-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
43 lines (36 loc) · 1.61 KB
/
tools.py
File metadata and controls
43 lines (36 loc) · 1.61 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
import os
from github import Github
from dotenv import load_dotenv
load_dotenv() # load the .env file, connect to my repo and read github token
g = Github(os.getenv("GITHUB_TOKEN")) # my Github Client
repo = g.get_repo(os.getenv("TARGET_REPO") or "") # repo is the repo the agent will work on
def get_issue(issue_number: int) -> dict:
# this fetches a single issue by a number and returns the important fields
issue = repo.get_issue(issue_number)
return {
"number": issue.number,
"title": issue.title,
"body": issue.body,
"labels": [l.name for l in issue.labels],
"author": issue.user.login,
"state": issue.state,
"created_at": issue.created_at
}
def search_issues(query: str) -> list:
# searches all issues in the repo by a keyword or phrase
issues = g.search_issues(f"repo:{os.getenv('TARGET_REPO')} {query}")
return [{"number": i.number, "title": i.title, "state": i.state} for i in list(issues)[:5]]
def list_labels() -> list:
# returns all the labels that exist in your repo
return [label.name for label in repo.get_labels()]
def list_contributors() -> list:
# Returns the GitHub usernames of everyone who has contributed to the repo.
return [c.login for c in repo.get_contributors()]
def post_comment(issue_number: int, body: str) -> str:
# Posts a comment on a given issue.
issue = repo.get_issue(issue_number)
issue.create_comment(body)
return "Comment posted successfully"
def list_open_issues() -> list:
issues = repo.get_issues(state="open")
return [{"number": i.number, "title": i.title} for i in issues]