added try/except and some better error handling
This commit is contained in:
parent
5ce0908fb1
commit
378c54dbc7
1 changed files with 36 additions and 13 deletions
|
@ -1,6 +1,10 @@
|
|||
import os
|
||||
import argparse
|
||||
from github import Github, Auth
|
||||
import logging
|
||||
from github import Github, Auth, GithubException
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
def auth():
|
||||
access_token = os.getenv("GITHUB_ACCESS_TOKEN")
|
||||
|
@ -17,31 +21,50 @@ class GithubSearcher():
|
|||
self.result = None
|
||||
|
||||
def search_repo(self):
|
||||
self.result = self.g.search_repositories(self.query)
|
||||
try:
|
||||
self.result = self.g.search_repositories(self.query)
|
||||
except GithubException as e:
|
||||
logging.error(f"Error searching repositories: {e}")
|
||||
self.result = None
|
||||
|
||||
def search_users(self):
|
||||
self.result = self.g.search_users(self.query)
|
||||
try:
|
||||
self.result = self.g.search_users(self.query)
|
||||
except GithubException as e:
|
||||
logging.error(f"Error searching users: {e}")
|
||||
self.result = None
|
||||
|
||||
def search_in_name(self):
|
||||
self.result = self.g.search_repositories('in:name ' + self.query)
|
||||
try:
|
||||
self.result = self.g.search_repositories('in:name ' + self.query)
|
||||
except GithubException as e:
|
||||
logging.error(f"Error searching in name: {e}")
|
||||
self.result = None
|
||||
|
||||
def get_repo_open_issues(self, repo):
|
||||
return repo.get_issues(state='open')
|
||||
try:
|
||||
return repo.get_issues(state='open')
|
||||
except GithubException as e:
|
||||
logging.error(f"Error getting open issues: {e}")
|
||||
return None
|
||||
|
||||
def get_repo_contents(self, repo):
|
||||
contents = repo.get_contents()
|
||||
for content_file in contents:
|
||||
print(content_file)
|
||||
|
||||
return contents
|
||||
try:
|
||||
contents = repo.get_contents("")
|
||||
for content_file in contents:
|
||||
print(content_file)
|
||||
return contents
|
||||
except GithubException as e:
|
||||
logging.error(f"Error getting repository contents: {e}")
|
||||
return None
|
||||
|
||||
def get_result(self):
|
||||
return self.result
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Search GitHub repositories and users.")
|
||||
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 = 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("--search_type", type=str, required=True, 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()
|
||||
|
|
Loading…
Add table
Reference in a new issue