This repository has been archived by the owner on Dec 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_get_branches.py
56 lines (41 loc) · 1.59 KB
/
2_get_branches.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
import json
from github import Github, UnknownObjectException
import tokens
def serialize_branch_workflow(obj):
out = []
for elem in obj:
out.append(str(elem.name))
return out
def main():
with open("source_links.json") as in_file:
source_links = json.loads(in_file.read())
# Create a GitHub instance using the access token
g = Github(tokens.GITHUB_TOKEN)
repo_not_found = []
for project in source_links["found"]:
username = project["github_username"]
repository_name = project["github_repo_name"]
# Get the repository
print(project["source"])
try:
repo = g.get_repo(f'{username}/{repository_name}')
repo_url = repo.html_url
print("Actual repository URL:", repo_url)
# Get a list of branches
branches = repo.get_branches()
project["branches"] = serialize_branch_workflow(branches)
project["source"] = repo_url
github_params = str(repo_url).replace("https://github.com/",
"").split("/")
project["github_username"] = github_params[0]
project["github_repo_name"] = github_params[1]
except UnknownObjectException:
print("Exception: repo unavailable!")
repo_not_found.append(project)
for i in repo_not_found:
source_links['found'].remove(i)
source_links['not_found'].append(i)
with open("branches.json", 'w') as out_f:
out_f.write(json.dumps(source_links))
if __name__ == "__main__":
main()