added urls to results for get open prs, get open issues. added --json option
This commit is contained in:
parent
faa5591c21
commit
aac7c02167
1 changed files with 29 additions and 18 deletions
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
from github import Github, Auth, GithubException
|
from github import Github, Auth, GithubException
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
|
@ -34,7 +35,7 @@ class GithubSearcher():
|
||||||
logging.error(f"Error searching users: {e}")
|
logging.error(f"Error searching users: {e}")
|
||||||
self.result = None
|
self.result = None
|
||||||
|
|
||||||
def search_in_name(self):
|
def search_in_repo_name(self):
|
||||||
try:
|
try:
|
||||||
self.result = self.g.search_repositories('in:name ' + self.query)
|
self.result = self.g.search_repositories('in:name ' + self.query)
|
||||||
except GithubException as e:
|
except GithubException as e:
|
||||||
|
@ -57,10 +58,7 @@ class GithubSearcher():
|
||||||
|
|
||||||
def get_repo_contents(self, repo):
|
def get_repo_contents(self, repo):
|
||||||
try:
|
try:
|
||||||
contents = repo.get_contents("")
|
return repo.get_contents("")
|
||||||
for content_file in contents:
|
|
||||||
print(content_file)
|
|
||||||
return contents
|
|
||||||
except GithubException as e:
|
except GithubException as e:
|
||||||
logging.error(f"Error getting repository contents: {e}")
|
logging.error(f"Error getting repository contents: {e}")
|
||||||
return None
|
return None
|
||||||
|
@ -71,10 +69,11 @@ class GithubSearcher():
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Search GitHub repositories and users for PoC exploits and CVEs.")
|
parser = argparse.ArgumentParser(description="Search GitHub repositories and users for PoC exploits and CVEs.")
|
||||||
parser.add_argument("--query", type=str, required=True, help="The search query.")
|
parser.add_argument("--query", type=str, required=True, help="The search query.")
|
||||||
parser.add_argument("--search_type", type=str, required=True, choices=["repo", "users", "name"], help="The type of search to perform: 'repo', 'users', or 'name'.")
|
parser.add_argument("--search_type", type=str, required=True, choices=["repo", "users", "in-repo-name"], help="The type of search to perform: 'repo', 'users', or 'in-repo-name'.")
|
||||||
parser.add_argument("--get_file_contents", action="store_true", help="Get the contents of repo results.")
|
parser.add_argument("--get_file_contents", action="store_true", help="Get the contents of repo results.")
|
||||||
parser.add_argument("--get_open_issues", action="store_true", help="Get the open issues of repo results.")
|
parser.add_argument("--get_open_issues", action="store_true", help="Get the open issues of repo results.")
|
||||||
parser.add_argument("--get_open_pull_requests", action="store_true", help="Get the open pull requests of repo results.")
|
parser.add_argument("--get_open_pull_requests", action="store_true", help="Get the open pull requests of repo results.")
|
||||||
|
parser.add_argument("--json", action="store_true", help="Output results in JSON format.")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -84,33 +83,45 @@ def main():
|
||||||
searcher.search_repo()
|
searcher.search_repo()
|
||||||
elif args.search_type == "users":
|
elif args.search_type == "users":
|
||||||
searcher.search_users()
|
searcher.search_users()
|
||||||
elif args.search_type == "name":
|
elif args.search_type == "in-repo-name":
|
||||||
searcher.search_in_name()
|
searcher.search_in_repo_name()
|
||||||
|
|
||||||
result = searcher.get_result()
|
result = searcher.get_result()
|
||||||
if result is None:
|
if result is None:
|
||||||
print("No results found.")
|
print("No results found.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
output = []
|
||||||
for item in result:
|
for item in result:
|
||||||
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:
|
||||||
print(repo.html_url)
|
repo_info = {"repo_url": repo.html_url, "repo_name": repo.name, "repo_description": repo.description}
|
||||||
|
output.append(repo_info)
|
||||||
else:
|
else:
|
||||||
print(item.html_url)
|
repo_info = {"repo_url": item.html_url, "repo_name": item.name, "repo_description": item.description}
|
||||||
|
|
||||||
if args.get_open_issues:
|
if args.get_open_issues:
|
||||||
searcher.get_repo_open_issues(item)
|
open_issues = searcher.get_repo_open_issues(item)
|
||||||
print("\n")
|
if open_issues:
|
||||||
|
repo_info["open_issues"] = [{"title": issue.title, "url": issue.html_url} for issue in open_issues]
|
||||||
if args.get_open_pull_requests:
|
if args.get_open_pull_requests:
|
||||||
searcher.get_repo_open_pull_requests(item)
|
open_prs = searcher.get_repo_open_pull_requests(item)
|
||||||
print("\n")
|
if open_prs:
|
||||||
|
repo_info["open_pull_requests"] = [{"title": pr.title, "url": pr.html_url} for pr in open_prs]
|
||||||
if args.get_file_contents:
|
if args.get_file_contents:
|
||||||
searcher.get_repo_contents(item)
|
contents = searcher.get_repo_contents(item)
|
||||||
print("\n")
|
if contents:
|
||||||
|
repo_info["contents"] = [content_file.name for content_file in contents]
|
||||||
|
|
||||||
|
output.append(repo_info)
|
||||||
|
|
||||||
|
if args.json:
|
||||||
|
print(json.dumps(output, indent=4))
|
||||||
|
else:
|
||||||
|
for item in output:
|
||||||
|
print(item)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Add table
Reference in a new issue