lysandre HF staff commited on
Commit
3823d44
1 Parent(s): 102b8de

Protect from bad token

Browse files
Files changed (2) hide show
  1. app.py +7 -2
  2. graphql_calls.py +9 -1
app.py CHANGED
@@ -16,13 +16,18 @@ def get_release_notes(
16
  repo: str,
17
  tag: str,
18
  branch: str,
19
- contributor_treshold: int,
20
  ignore_dependabot: bool,
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 = {}
28
 
@@ -52,7 +57,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 and k != '<NOT FOUND>'
56
  }
57
 
58
  if len(significant_contributors):
 
16
  repo: str,
17
  tag: str,
18
  branch: str,
19
+ contributor_treshhold: int,
20
  ignore_dependabot: bool,
21
  ignore_direct: bool,
22
  ):
23
  date = get_tag_commit_date(token, repo, tag)
24
+
25
+ if date is None:
26
+ return "The token was invalid or didn't have the necessary scopes."
27
+
28
  commits = get_commits(token, repo, branch, date)
29
 
30
+
31
  result = ""
32
  contributors = {}
33
 
 
57
  result += f"* {commit.message} by @{commit.user.name} (direct commit on {branch})\n"
58
 
59
  significant_contributors = {
60
+ k: v for k, v in contributors.items() if (v.additions + v.deletions) > contributor_treshhold and k != '<NOT FOUND>'
61
  }
62
 
63
  if len(significant_contributors):
graphql_calls.py CHANGED
@@ -43,7 +43,15 @@ def get_tag_commit_date(token, repository, tag):
43
  }}
44
  }}
45
  """
46
- return call_with_query(query, token)['data']['repository']['object']['committedDate']
 
 
 
 
 
 
 
 
47
 
48
 
49
  def get_commits(token, repository, branch, since):
 
43
  }}
44
  }}
45
  """
46
+
47
+ response = call_with_query(query, token)
48
+
49
+ try:
50
+ committed_date = response['data']['repository']['object']['committedDate']
51
+ except KeyError:
52
+ committed_date = None
53
+
54
+ return committed_date
55
 
56
 
57
  def get_commits(token, repository, branch, since):