LysandreJik commited on
Commit
5c5d1c5
1 Parent(s): a089850

Ready for production

Browse files
Files changed (2) hide show
  1. app.py +43 -3
  2. graphql_calls.py +6 -2
app.py CHANGED
@@ -21,7 +21,7 @@ def get_release_notes(
21
  ignore_direct: bool,
22
  ):
23
  date = get_tag_commit_date(token, repo, tag)
24
- commits = get_commits(token, repo, date)
25
 
26
  result = ""
27
  contributors = {}
@@ -52,7 +52,7 @@ def get_release_notes(
52
  result += f"* {commit.message} by @{commit.user.name} (direct commit on {branch})\n"
53
 
54
  significant_contributors = {
55
- k: v for k, v in contributors.items() if (v.additions + v.deletions) > contributor_treshold
56
  }
57
 
58
  if len(significant_contributors):
@@ -69,6 +69,38 @@ def get_release_notes(
69
 
70
  return result
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  demo = gr.Interface(
74
  fn=get_release_notes,
@@ -93,8 +125,16 @@ demo = gr.Interface(
93
  gr.inputs.Checkbox(label="Ignore direct commits"),
94
  ],
95
  outputs="text",
 
 
 
 
 
 
 
 
96
  )
97
 
98
 
99
  if __name__ == "__main__":
100
- demo.launch()
 
21
  ignore_direct: bool,
22
  ):
23
  date = get_tag_commit_date(token, repo, tag)
24
+ commits = get_commits(token, repo, branch, date)
25
 
26
  result = ""
27
  contributors = {}
 
52
  result += f"* {commit.message} by @{commit.user.name} (direct commit on {branch})\n"
53
 
54
  significant_contributors = {
55
+ k: v for k, v in contributors.items() if (v.additions + v.deletions) > contributor_treshold and k != '<NOT FOUND>'
56
  }
57
 
58
  if len(significant_contributors):
 
69
 
70
  return result
71
 
72
+ article = """
73
+ ## How to use the interface?
74
+
75
+ ⚠️ Most errors are due to:
76
+ - A wrong `tag` -> the tag must exist on the repository!
77
+ - A wrong `branch` -> The branch must exist on the repository!
78
+ - A wrong `token` -> Obtaining a token is detailed below.
79
+
80
+ ### token
81
+
82
+ This is a personal access token generated by GitHub. You can obtain one with the following guide:
83
+ https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token.
84
+
85
+ ### Repository
86
+
87
+ The repository for which to create the release notes. Should be in the format '<organization>/<repository>'.
88
+
89
+ ### Tag
90
+
91
+ The tag from which all commits were made. The app will fetch the date at which this tag was created, and will
92
+ return all commits of the branch defined below that have a timestamp following that date.
93
+
94
+ ### Branch
95
+
96
+ The branch on which all commits lie. Usually `master` or `main`.
97
+
98
+ ### Threshold
99
+
100
+ This threshold allows highlighting specific community contributors according to the size of their contributions.
101
+ It currently adds all their additions/deletions across all PRs included in this release. It is then compared
102
+ to the defined threshold: if above, that user will get a special note mentioning what they have worked on!
103
+ """
104
 
105
  demo = gr.Interface(
106
  fn=get_release_notes,
 
125
  gr.inputs.Checkbox(label="Ignore direct commits"),
126
  ],
127
  outputs="text",
128
+ examples=[
129
+ ['ghp_XXX', 'huggingface/datasets', '2.1.0', 'master', 60, True, True],
130
+ ['ghp_XXX', 'huggingface/accelerate', 'v0.7.1', 'main', 500, True, True],
131
+ ['ghp_XXX', 'huggingface/transformers', 'v4.18.0', 'main', 500, True, True],
132
+ ['ghp_XXX', 'gradio-app/gradio', 'v2.9.0', 'main', 500, True, True],
133
+ ],
134
+ title='Automatic release notes 🤗',
135
+ article=article
136
  )
137
 
138
 
139
  if __name__ == "__main__":
140
+ demo.launch(show_error=True)
graphql_calls.py CHANGED
@@ -46,7 +46,7 @@ def get_tag_commit_date(token, repository, tag):
46
  return call_with_query(query, token)['data']['repository']['object']['committedDate']
47
 
48
 
49
- def get_commits(token, repository, since):
50
  owner, name = repository.split('/')
51
 
52
  def get_page_result(next_page=''):
@@ -54,7 +54,7 @@ def get_commits(token, repository, since):
54
  query GetCommits {{
55
  repository(owner: "{owner}", name: "{name}"){{
56
  nameWithOwner
57
- object(expression: "main") {{
58
  ... on Commit {{
59
  oid
60
  history(first: 100, since: "{since}"{next_page}) {{
@@ -84,6 +84,10 @@ def get_commits(token, repository, since):
84
  }}
85
  """
86
  result = call_with_query(query, token)
 
 
 
 
87
  nodes = result['data']['repository']['object']['history']['nodes']
88
  cursor = result['data']['repository']['object']['history']['pageInfo']['endCursor']
89
  return nodes, cursor
 
46
  return call_with_query(query, token)['data']['repository']['object']['committedDate']
47
 
48
 
49
+ def get_commits(token, repository, branch, since):
50
  owner, name = repository.split('/')
51
 
52
  def get_page_result(next_page=''):
 
54
  query GetCommits {{
55
  repository(owner: "{owner}", name: "{name}"){{
56
  nameWithOwner
57
+ object(expression: "{branch}") {{
58
  ... on Commit {{
59
  oid
60
  history(first: 100, since: "{since}"{next_page}) {{
 
84
  }}
85
  """
86
  result = call_with_query(query, token)
87
+
88
+ if result['data']['repository']['object'] is None:
89
+ raise ValueError("Either the tag or the branch were incorrect.")
90
+
91
  nodes = result['data']['repository']['object']['history']['nodes']
92
  cursor = result['data']['repository']['object']['history']['pageInfo']['endCursor']
93
  return nodes, cursor