Create github_api_utils.py
Browse files- github_api_utils.py +81 -0
github_api_utils.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GitHub API functions
|
| 2 |
+
def get_github_stars_forks(owner, repo):
|
| 3 |
+
url = f"https://api.github.com/repos/{owner}/{repo}"
|
| 4 |
+
response = requests.get(url, headers={'Accept': 'application/vnd.github.v3+json'})
|
| 5 |
+
if response.status_code == 200:
|
| 6 |
+
data = response.json()
|
| 7 |
+
return data.get('stargazers_count', 0), data.get('forks_count', 0)
|
| 8 |
+
else:
|
| 9 |
+
print(f"Error fetching stars and forks: {response.status_code}")
|
| 10 |
+
return 0, 0
|
| 11 |
+
|
| 12 |
+
def get_github_issues(owner, repo):
|
| 13 |
+
url = f"https://api.github.com/repos/{owner}/{repo}/issues"
|
| 14 |
+
response = requests.get(url, headers={'Accept': 'application/vnd.github.v3+json'})
|
| 15 |
+
if response.status_code == 200:
|
| 16 |
+
issues = response.json()
|
| 17 |
+
return len(issues)
|
| 18 |
+
else:
|
| 19 |
+
print(f"Error fetching issues: {response.status_code}")
|
| 20 |
+
return 0
|
| 21 |
+
|
| 22 |
+
def get_github_pull_requests(owner, repo):
|
| 23 |
+
url = f"https://api.github.com/repos/{owner}/{repo}/pulls"
|
| 24 |
+
response = requests.get(url, headers={'Accept': 'application/vnd.github.v3+json'})
|
| 25 |
+
if response.status_code == 200:
|
| 26 |
+
pulls = response.json()
|
| 27 |
+
return len(pulls)
|
| 28 |
+
else:
|
| 29 |
+
print(f"Error fetching pull requests: {response.status_code}")
|
| 30 |
+
return 0
|
| 31 |
+
|
| 32 |
+
def get_github_license(owner, repo):
|
| 33 |
+
url = f"https://api.github.com/repos/{owner}/{repo}/license"
|
| 34 |
+
response = requests.get(url, headers={'Accept': 'application/vnd.github.v3+json'})
|
| 35 |
+
if response.status_code == 200:
|
| 36 |
+
data = response.json()
|
| 37 |
+
return data['license']['name'] if data.get('license') else 'No license found'
|
| 38 |
+
else:
|
| 39 |
+
print(f"Error fetching license: {response.status_code}")
|
| 40 |
+
return 'No license found'
|
| 41 |
+
|
| 42 |
+
def get_last_commit(owner, repo):
|
| 43 |
+
url = f"https://api.github.com/repos/{owner}/{repo}/commits"
|
| 44 |
+
response = requests.get(url, headers={'Accept': 'application/vnd.github.v3+json'})
|
| 45 |
+
if response.status_code == 200:
|
| 46 |
+
commits = response.json()
|
| 47 |
+
return commits[0]['commit']['committer']['date'] if commits else 'No commits found'
|
| 48 |
+
else:
|
| 49 |
+
print(f"Error fetching commits: {response.status_code}")
|
| 50 |
+
return 'No commits found'
|
| 51 |
+
|
| 52 |
+
def get_github_workflow_status(owner, repo):
|
| 53 |
+
url = f"https://api.github.com/repos/{owner}/{repo}/actions/runs"
|
| 54 |
+
response = requests.get(url, headers={'Accept': 'application/vnd.github.v3+json'})
|
| 55 |
+
if response.status_code == 200:
|
| 56 |
+
runs = response.json()
|
| 57 |
+
return runs['workflow_runs'][0]['status'] if runs.get('workflow_runs') else "No workflows found"
|
| 58 |
+
else:
|
| 59 |
+
print(f"Error fetching workflow status: {response.status_code}")
|
| 60 |
+
return 'No workflows found'
|
| 61 |
+
|
| 62 |
+
# Main function to display OSINT data
|
| 63 |
+
def fetch_osint_data(owner, repo):
|
| 64 |
+
stars, forks = get_github_stars_forks(owner, repo)
|
| 65 |
+
open_issues = get_github_issues(owner, repo)
|
| 66 |
+
open_pulls = get_github_pull_requests(owner, repo)
|
| 67 |
+
license_type = get_github_license(owner, repo)
|
| 68 |
+
last_commit = get_last_commit(owner, repo)
|
| 69 |
+
workflow_status = get_github_workflow_status(owner, repo)
|
| 70 |
+
|
| 71 |
+
# Print the collected data
|
| 72 |
+
print(f"GitHub Repository: {owner}/{repo}")
|
| 73 |
+
print(f"Stars: {stars}, Forks: {forks}")
|
| 74 |
+
print(f"Open Issues: {open_issues}, Open Pull Requests: {open_pulls}")
|
| 75 |
+
print(f"License: {license_type}")
|
| 76 |
+
print(f"Last Commit: {last_commit}")
|
| 77 |
+
print(f"Workflow Status: {workflow_status}")
|
| 78 |
+
|
| 79 |
+
# Example usage
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
fetch_osint_data("Chemically-Motivated-Solutions", "OSINT_Tool") # Replace with your desired repo
|