added --get_open_issues and --get_file_contents optional command-line args
This commit is contained in:
parent
12c9f3a054
commit
5ce0908fb1
1 changed files with 34 additions and 1 deletions
|
@ -4,6 +4,8 @@ from github import Github, Auth
|
||||||
|
|
||||||
def auth():
|
def auth():
|
||||||
access_token = os.getenv("GITHUB_ACCESS_TOKEN")
|
access_token = os.getenv("GITHUB_ACCESS_TOKEN")
|
||||||
|
if not access_token:
|
||||||
|
raise ValueError("GITHUB_ACCESS_TOKEN environment variable not set")
|
||||||
auth = Auth.Token(access_token)
|
auth = Auth.Token(access_token)
|
||||||
g = Github(auth=auth)
|
g = Github(auth=auth)
|
||||||
return g
|
return g
|
||||||
|
@ -23,6 +25,16 @@ class GithubSearcher():
|
||||||
def search_in_name(self):
|
def search_in_name(self):
|
||||||
self.result = self.g.search_repositories('in:name ' + self.query)
|
self.result = self.g.search_repositories('in:name ' + self.query)
|
||||||
|
|
||||||
|
def get_repo_open_issues(self, repo):
|
||||||
|
return repo.get_issues(state='open')
|
||||||
|
|
||||||
|
def get_repo_contents(self, repo):
|
||||||
|
contents = repo.get_contents()
|
||||||
|
for content_file in contents:
|
||||||
|
print(content_file)
|
||||||
|
|
||||||
|
return contents
|
||||||
|
|
||||||
def get_result(self):
|
def get_result(self):
|
||||||
return self.result
|
return self.result
|
||||||
|
|
||||||
|
@ -30,6 +42,8 @@ def main():
|
||||||
parser = argparse.ArgumentParser(description="Search GitHub repositories and users.")
|
parser = argparse.ArgumentParser(description="Search GitHub repositories and users.")
|
||||||
parser.add_argument("--query", type=str, help="The search query.")
|
parser.add_argument("--query", type=str, help="The search query.")
|
||||||
parser.add_argument("--search_type", type=str, choices=["repo", "users", "name"], help="The type of search to perform: 'repo', 'users', or 'name'.")
|
parser.add_argument("--search_type", type=str, choices=["repo", "users", "name"], help="The type of search to perform: 'repo', 'users', or 'name'.")
|
||||||
|
parser.add_argument("--get_file_contents", action="store_true", help="Get the contents of a repository.")
|
||||||
|
parser.add_argument("--get_open_issues", action="store_true", help="Get the open issues of a repository.")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
searcher = GithubSearcher(args.query)
|
searcher = GithubSearcher(args.query)
|
||||||
|
@ -42,8 +56,11 @@ def main():
|
||||||
searcher.search_in_name()
|
searcher.search_in_name()
|
||||||
|
|
||||||
result = searcher.get_result()
|
result = searcher.get_result()
|
||||||
|
if result is None:
|
||||||
|
print("No results found.")
|
||||||
|
return
|
||||||
|
|
||||||
for item in result:
|
for item in result:
|
||||||
# If users, print all user repo URLs
|
|
||||||
if args.search_type == "users":
|
if args.search_type == "users":
|
||||||
user_repos = item.get_repos()
|
user_repos = item.get_repos()
|
||||||
for repo in user_repos:
|
for repo in user_repos:
|
||||||
|
@ -51,5 +68,21 @@ def main():
|
||||||
else:
|
else:
|
||||||
print(item.html_url)
|
print(item.html_url)
|
||||||
|
|
||||||
|
if args.get_open_issues:
|
||||||
|
issues = searcher.get_repo_open_issues(item)
|
||||||
|
if issues:
|
||||||
|
print("Open issues:")
|
||||||
|
for issue in issues:
|
||||||
|
print(f"Issue: {issue.title}")
|
||||||
|
print("\n")
|
||||||
|
|
||||||
|
if args.get_file_contents:
|
||||||
|
contents = searcher.get_repo_contents(item)
|
||||||
|
if contents:
|
||||||
|
print("Contents:")
|
||||||
|
for content in contents:
|
||||||
|
print(f"File: {content.path}")
|
||||||
|
print("\n")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Add table
Reference in a new issue