LysandreJik commited on
Commit
d80253f
1 Parent(s): 630f2f8

First version

Browse files
Files changed (2) hide show
  1. app.py +37 -0
  2. graphql_calls.py +90 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from graphql_calls import get_tag_commit_date, get_commits
3
+
4
+
5
+ def get_all_commits(token, repo, tag, branch):
6
+ date = get_tag_commit_date(token, repo, tag)
7
+ commits = get_commits(token, repo, date)
8
+
9
+ result = ''
10
+
11
+ for commit in commits:
12
+ if '(#' in commit.message:
13
+ split = commit.message.split('(#')
14
+ message = split[0]
15
+ number = split[1].strip(')')
16
+
17
+ result += f"* {message} by @{commit.user} in #{number}\n"
18
+ else:
19
+ result += f"* {commit.message} by @{commit.user} (direct commit on {branch})\n"
20
+
21
+ return result
22
+
23
+
24
+ demo = gr.Interface(
25
+ fn=get_all_commits,
26
+ inputs=[
27
+ gr.inputs.Textbox(lines=1, placeholder="Your GitHub token"),
28
+ gr.inputs.Textbox(lines=1, placeholder="Repository", default='huggingface/transformers'),
29
+ gr.inputs.Textbox(lines=1, placeholder="The tag from which to get commit"),
30
+ gr.inputs.Textbox(lines=1, placeholder="The linear branch on which the new version tag will be added", default='main'),
31
+ ],
32
+ outputs='text',
33
+ )
34
+
35
+
36
+ if __name__ == "__main__":
37
+ demo.launch()
graphql_calls.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+
3
+ import requests
4
+
5
+
6
+ @dataclass
7
+ class Commit:
8
+ message: str
9
+ user: str
10
+
11
+
12
+ def call_with_query(query, token):
13
+ url = 'https://api.github.com/graphql'
14
+ r = requests.post(url, json={'query': query}, headers={'Authorization': f'Bearer {token}'})
15
+ return r.json()
16
+
17
+
18
+ def get_tag_commit_date(token, repository, tag):
19
+ owner, name = repository.split('/')
20
+ query = f"""
21
+ query GetTagCommit {{
22
+ repository(owner: "{owner}", name: "{name}"){{
23
+ object(expression: "{tag}") {{
24
+ ... on Commit {{
25
+ oid
26
+ message
27
+ committedDate
28
+ author {{
29
+ user {{
30
+ login
31
+ }}
32
+ }}
33
+ }}
34
+ }}
35
+ }}
36
+ }}
37
+ """
38
+ return call_with_query(query, token)['data']['repository']['object']['committedDate']
39
+
40
+
41
+ def get_commits(token, repository, since):
42
+ owner, name = repository.split('/')
43
+
44
+ def get_page_result(next_page=''):
45
+ query = f"""
46
+ query GetCommits {{
47
+ repository(owner: "{owner}", name: "{name}"){{
48
+ nameWithOwner
49
+ object(expression: "main") {{
50
+ ... on Commit {{
51
+ oid
52
+ history(first: 100, since: "{since}"{next_page}) {{
53
+ nodes {{
54
+ message
55
+ author {{
56
+ user {{
57
+ login
58
+ }}
59
+ }}
60
+ }}
61
+ pageInfo {{
62
+ endCursor
63
+ hasNextPage
64
+ }}
65
+ }}
66
+ }}
67
+ }}
68
+ }}
69
+ }}
70
+ """
71
+ result = call_with_query(query, token)
72
+ nodes = result['data']['repository']['object']['history']['nodes']
73
+ cursor = result['data']['repository']['object']['history']['pageInfo']['endCursor']
74
+ return nodes, cursor
75
+
76
+ nodes, cursor = get_page_result()
77
+
78
+ while cursor is not None:
79
+ _nodes, cursor = get_page_result(f' after:"{cursor}"')
80
+ nodes.extend(_nodes)
81
+
82
+
83
+ commits = []
84
+ for node in nodes:
85
+ if node['author']['user'] is None:
86
+ commits.append(Commit(message=node['message'].split('\n')[0], user='<NOT FOUND>'))
87
+ else:
88
+ commits.append(Commit(message=node['message'].split('\n')[0], user=node['author']['user']['login']))
89
+
90
+ return commits