|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -import random |
16 | 15 | import os |
17 | | -import requests |
| 16 | +import random |
18 | 17 | import time |
| 18 | + |
19 | 19 | from google.adk import Agent |
20 | 20 | from google.adk.tools.tool_context import ToolContext |
21 | 21 | from google.genai import types |
22 | | - |
| 22 | +import requests |
23 | 23 |
|
24 | 24 | # Read the PAT from the environment variable |
25 | 25 | GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") # Ensure you've set this in your shell |
26 | 26 | if not GITHUB_TOKEN: |
27 | | - raise ValueError("GITHUB_TOKEN environment variable not set") |
| 27 | + raise ValueError("GITHUB_TOKEN environment variable not set") |
28 | 28 |
|
29 | 29 | # Repository information |
30 | 30 | OWNER = "google" |
|
36 | 36 | # Headers including the Authorization header |
37 | 37 | headers = { |
38 | 38 | "Authorization": f"token {GITHUB_TOKEN}", |
39 | | - "Accept": "application/vnd.github.v3+json" |
| 39 | + "Accept": "application/vnd.github.v3+json", |
40 | 40 | } |
41 | 41 |
|
42 | 42 |
|
43 | | -def list_issues(per_page:int): |
44 | | - """ |
45 | | - Generator to list all issues for the repository by handling pagination. |
| 43 | +def list_issues(per_page: int): |
| 44 | + """ |
| 45 | + Generator to list all issues for the repository by handling pagination. |
| 46 | +
|
| 47 | + Args: |
| 48 | + per_page: number of pages to return per page. |
46 | 49 |
|
47 | | - Args: |
48 | | - per_page: number of pages to return per page. |
| 50 | + """ |
| 51 | + state = "open" |
| 52 | + # only process the 1st page for testing for now |
| 53 | + page = 1 |
| 54 | + results = [] |
| 55 | + url = ( # :contentReference[oaicite:16]{index=16} |
| 56 | + f"{BASE_URL}/repos/{OWNER}/{REPO}/issues" |
| 57 | + ) |
| 58 | + # Warning: let's only handle max 10 issues at a time to avoid bad results |
| 59 | + params = {"state": state, "per_page": per_page, "page": page} |
| 60 | + response = requests.get(url, headers=headers, params=params) |
| 61 | + response.raise_for_status() # :contentReference[oaicite:17]{index=17} |
| 62 | + issues = response.json() |
| 63 | + if not issues: |
| 64 | + return [] |
| 65 | + for issue in issues: |
| 66 | + # Skip pull requests (issues API returns PRs as well) |
| 67 | + if "pull_request" in issue: |
| 68 | + continue |
| 69 | + results.append(issue) |
| 70 | + return results |
49 | 71 |
|
50 | | - """ |
51 | | - state="open" |
52 | | - # only process the 1st page for testing for now |
53 | | - page = 1 |
54 | | - results = [] |
55 | | - url = f"{BASE_URL}/repos/{OWNER}/{REPO}/issues" # :contentReference[oaicite:16]{index=16} |
56 | | - # Warning: let's only handle max 10 issues at a time to avoid bad results |
57 | | - params = { |
58 | | - "state": state, |
59 | | - "per_page": per_page, |
60 | | - "page": page |
61 | | - } |
62 | | - response = requests.get(url, headers=headers, params=params) |
63 | | - response.raise_for_status() # :contentReference[oaicite:17]{index=17} |
64 | | - issues = response.json() |
65 | | - if not issues: |
66 | | - return [] |
67 | | - for issue in issues: |
68 | | - # Skip pull requests (issues API returns PRs as well) |
69 | | - if "pull_request" in issue: |
70 | | - continue |
71 | | - results.append(issue) |
72 | | - return results |
73 | 72 |
|
74 | | -def add_label_to_issue(issue_number:str, label:str): |
75 | | - """ |
76 | | - Add the specified label to the given issue number. |
| 73 | +def add_label_to_issue(issue_number: str, label: str): |
| 74 | + """ |
| 75 | + Add the specified label to the given issue number. |
| 76 | +
|
| 77 | + Args: |
| 78 | + issue_number: issue number of the Github issue, in string foramt. |
| 79 | + label: label to assign |
| 80 | + """ |
| 81 | + url = f"{BASE_URL}/repos/{OWNER}/{REPO}/issues/{issue_number}/labels" |
| 82 | + payload = [label] |
| 83 | + response = requests.post(url, headers=headers, json=payload) |
| 84 | + response.raise_for_status() |
| 85 | + return response.json() |
77 | 86 |
|
78 | | - Args: |
79 | | - issue_number: issue number of the Github issue, in string foramt. |
80 | | - label: label to assign |
81 | | - """ |
82 | | - url = f"{BASE_URL}/repos/{OWNER}/{REPO}/issues/{issue_number}/labels" |
83 | | - payload = [label] |
84 | | - response = requests.post(url, headers=headers, json=payload) |
85 | | - response.raise_for_status() |
86 | | - return response.json() |
87 | 87 |
|
88 | 88 | root_agent = Agent( |
89 | | - model='gemini-2.5-pro-preview-05-06', |
90 | | - name='adk_triaging_assistant', |
91 | | - description=( |
92 | | - 'Triage ADK issues.' |
93 | | - ), |
| 89 | + model="gemini-2.5-pro-preview-05-06", |
| 90 | + name="adk_triaging_assistant", |
| 91 | + description="Triage ADK issues.", |
94 | 92 | instruction=""" |
95 | 93 | You are a Github adk-python repo triaging bot. You will help get issues, and label them. |
96 | 94 | Here are the rules for labeling: |
|
0 commit comments