12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- import os
16
-
15
+ from typing import Any
16
+
17
+ from adk_triaging_agent .settings import BOT_LABEL
18
+ from adk_triaging_agent .settings import GITHUB_BASE_URL
19
+ from adk_triaging_agent .settings import IS_INTERACTIVE
20
+ from adk_triaging_agent .settings import OWNER
21
+ from adk_triaging_agent .settings import REPO
22
+ from adk_triaging_agent .utils import error_response
23
+ from adk_triaging_agent .utils import get_request
24
+ from adk_triaging_agent .utils import post_request
17
25
from google .adk import Agent
18
26
import requests
19
27
20
- GITHUB_TOKEN = os .getenv ("GITHUB_TOKEN" )
21
- if not GITHUB_TOKEN :
22
- raise ValueError ("GITHUB_TOKEN environment variable not set" )
23
-
24
- OWNER = os .getenv ("OWNER" , "google" )
25
- REPO = os .getenv ("REPO" , "adk-python" )
26
- BOT_LABEL = os .getenv ("BOT_LABEL" , "bot_triaged" )
27
-
28
- BASE_URL = "https://api.github.com"
29
-
30
- headers = {
31
- "Authorization" : f"token { GITHUB_TOKEN } " ,
32
- "Accept" : "application/vnd.github.v3+json" ,
33
- }
34
-
35
28
ALLOWED_LABELS = [
36
29
"documentation" ,
37
30
"services" ,
45
38
"web" ,
46
39
]
47
40
48
-
49
- def is_interactive ():
50
- return os .environ .get ("INTERACTIVE" , "1" ).lower () in ["true" , "1" ]
41
+ APPROVAL_INSTRUCTION = (
42
+ "Do not ask for user approval for labeling! If you can't find appropriate"
43
+ " labels for the issue, do not label it."
44
+ )
45
+ if IS_INTERACTIVE :
46
+ APPROVAL_INSTRUCTION = "Only label them when the user approves the labeling!"
51
47
52
48
53
- def list_issues (issue_count : int ):
54
- """
55
- Generator to list all issues for the repository by handling pagination.
49
+ def list_unlabeled_issues (issue_count : int ) -> dict [str , Any ]:
50
+ """List most recent `issue_count` numer of unlabeled issues in the repo.
56
51
57
52
Args:
58
53
issue_count: number of issues to return
59
54
55
+ Returns:
56
+ The status of this request, with a list of issues when successful.
60
57
"""
58
+ url = f"{ GITHUB_BASE_URL } /search/issues"
61
59
query = f"repo:{ OWNER } /{ REPO } is:open is:issue no:label"
62
-
63
- unlabelled_issues = []
64
- url = f"{ BASE_URL } /search/issues"
65
-
66
60
params = {
67
61
"q" : query ,
68
62
"sort" : "created" ,
69
63
"order" : "desc" ,
70
64
"per_page" : issue_count ,
71
65
"page" : 1 ,
72
66
}
73
- response = requests .get (url , headers = headers , params = params , timeout = 60 )
74
- response .raise_for_status ()
75
- json_response = response .json ()
76
- issues = json_response .get ("items" , None )
77
- if not issues :
78
- return []
67
+
68
+ try :
69
+ response = get_request (url , params )
70
+ except requests .exceptions .RequestException as e :
71
+ return error_response (f"Error: { e } " )
72
+ issues = response .get ("items" , None )
73
+
74
+ unlabeled_issues = []
79
75
for issue in issues :
80
- if not issue .get ("labels" , None ) or len ( issue [ "labels" ]) == 0 :
81
- unlabelled_issues .append (issue )
82
- return unlabelled_issues
76
+ if not issue .get ("labels" , None ):
77
+ unlabeled_issues .append (issue )
78
+ return { "status" : "success" , "issues" : unlabeled_issues }
83
79
84
80
85
- def add_label_to_issue (issue_number : str , label : str ):
86
- """
87
- Add the specified label to the given issue number.
81
+ def add_label_to_issue (issue_number : int , label : str ) -> dict [str , Any ]:
82
+ """Add the specified label to the given issue number.
88
83
89
84
Args:
90
- issue_number: issue number of the Github issue, in string foramt .
85
+ issue_number: issue number of the Github issue.
91
86
label: label to assign
87
+
88
+ Returns:
89
+ The the status of this request, with the applied label when successful.
92
90
"""
93
91
print (f"Attempting to add label '{ label } ' to issue #{ issue_number } " )
94
92
if label not in ALLOWED_LABELS :
95
- error_message = (
93
+ return error_response (
96
94
f"Error: Label '{ label } ' is not an allowed label. Will not apply."
97
95
)
98
- print (error_message )
99
- return {"status" : "error" , "message" : error_message , "applied_label" : None }
100
96
101
- url = f"{ BASE_URL } /repos/{ OWNER } /{ REPO } /issues/{ issue_number } /labels"
97
+ url = f"{ GITHUB_BASE_URL } /repos/{ OWNER } /{ REPO } /issues/{ issue_number } /labels"
102
98
payload = [label , BOT_LABEL ]
103
- response = requests .post (url , headers = headers , json = payload , timeout = 60 )
104
- response .raise_for_status ()
105
- return response .json ()
106
99
100
+ try :
101
+ response = post_request (url , payload )
102
+ except requests .exceptions .RequestException as e :
103
+ return error_response (f"Error: { e } " )
104
+ return {
105
+ "status" : "success" ,
106
+ "message" : response ,
107
+ "applied_label" : label ,
108
+ }
107
109
108
- approval_instruction = (
109
- "Only label them when the user approves the labeling!"
110
- if is_interactive ()
111
- else (
112
- "Do not ask for user approval for labeling! If you can't find a"
113
- " appropriate labels for the issue, do not label it."
114
- )
115
- )
116
110
117
111
root_agent = Agent (
118
- model = "gemini-2.5-pro-preview-05-06 " ,
112
+ model = "gemini-2.5-pro" ,
119
113
name = "adk_triaging_assistant" ,
120
114
description = "Triage ADK issues." ,
121
115
instruction = f"""
122
- You are a Github adk-python repo triaging bot . You will help get issues, and recommend a label.
123
- IMPORTANT: { approval_instruction }
116
+ You are a triaging bot for the Github { REPO } repo with the owner { OWNER } . You will help get issues, and recommend a label.
117
+ IMPORTANT: { APPROVAL_INSTRUCTION }
124
118
Here are the rules for labeling:
125
119
- If the user is asking about documentation-related questions, label it with "documentation".
126
120
- If it's about session, memory services, label it with "services"
@@ -138,8 +132,5 @@ def add_label_to_issue(issue_number: str, label: str):
138
132
- the issue summary in a few sentence
139
133
- your label recommendation and justification
140
134
""" ,
141
- tools = [
142
- list_issues ,
143
- add_label_to_issue ,
144
- ],
135
+ tools = [list_unlabeled_issues , add_label_to_issue ],
145
136
)
0 commit comments