-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
126 lines (93 loc) · 2.8 KB
/
agent.py
File metadata and controls
126 lines (93 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""
agent.py
Entry point for the GitHub Triage Agent.
This agent reads issues and performs triage actions such as:
- fetching issue details
- searching issues
- listing labels
- posting comments
"""
from tools import (
get_issue,
search_issues,
list_labels,
list_contributors,
post_comment,
list_open_issues
)
from memory import is_triaged, mark_triaged, log_action
from datetime import datetime, timezone
from llm import suggest_label
import os
def triage_issue(issue_number: int):
"""
Main triage workflow for a single issue.
"""
print(f"Fetching issue #{issue_number}...\n")
if is_triaged(issue_number):
print(f"Issue #{issue_number} has already been triaged. Skipping.")
return
issue = get_issue(issue_number)
age = datetime.now(timezone.utc) - issue["created_at"]
if age.days > 0:
print(f"Issue #{issue_number} is old. Skipping comment.")
mark_triaged(issue_number)
return
print("Issue Details")
print("---------------------")
print("Number:", issue["number"])
print("Title:", issue["title"])
print("Author:", issue["author"])
print("State:", issue["state"])
print("Labels:", issue["labels"])
print()
# Example logic
if issue["state"] == "open":
print("Issue is open — performing triage...\n")
labels = list_labels()
print("Available Labels:")
print(labels)
print()
contributors = list_contributors()
print("Repo Contributors:")
print(contributors)
print()
label = suggest_label(issue)
# Example automated comment
comment_body = (
"👋 Thanks for opening this issue!\n\n"
f"Suggested label: **{label}**\n\n"
"Our team will review it shortly. Sharpiru Sharpallaina"
)
result = post_comment(issue_number, comment_body)
print(result)
mark_triaged(issue_number)
log_action(issue_number, "comment_posted")
else:
print("Issue is already closed.")
def search_workflow(query: str):
"""
Example workflow for searching issues.
"""
print(f"Searching issues for: {query}\n")
results = search_issues(query)
for issue in results:
print(
f"#{issue['number']} - "
f"{issue['title']} "
f"({issue['state']})"
)
if __name__ == "__main__":
"""
Entry point when script is run directly.
"""
print("GitHub Triage Agent Started\n")
issue_number = os.getenv("ISSUE_NUMBER")
if issue_number:
triage_issue(int(issue_number))
else:
# fallback: triage all open issues
for issue in list_open_issues():
triage_issue(issue["number"])
# Optional:
# search_workflow("bug")