-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommits_reader.py
More file actions
36 lines (26 loc) · 1.14 KB
/
commits_reader.py
File metadata and controls
36 lines (26 loc) · 1.14 KB
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
import urllib.request, json
def get_branches_from_repository(owner, repository_name):
with urllib.request.urlopen(f"https://api.github.com/repos/{owner}/{repository_name}/branches") as url:
data = json.loads(url.read().decode())
names = []
for branch in data:
names.append(branch["name"])
return names
def get_commits_from_branch(owner, repository_name, branch_name):
with urllib.request.urlopen(f"https://api.github.com/repos/{owner}/{repository_name}/commits?sha={branch_name}") as url:
data = json.loads(url.read().decode())
commits = []
for commit in data:
commits.append([
commit["commit"]["author"]["name"],
commit["commit"]["author"]["email"],
commit["commit"]["author"]["date"],
commit["commit"]["message"]
])
return commits
if __name__ == "__main__":
repo_owner = input("Repository owner: ")
repo_name = input("Repository name: ")
for branch in get_branches_from_repository(repo_owner, repo_name):
print(f"Branch {branch}:")
print(*get_commits_from_branch(repo_owner, repo_name, branch), sep='\n')