lysandre HF staff commited on
Commit
2e4b438
1 Parent(s): 3823d44

SSO protection

Browse files
Files changed (2) hide show
  1. app.py +5 -7
  2. graphql_calls.py +13 -3
app.py CHANGED
@@ -20,13 +20,11 @@ def get_release_notes(
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 = {}
 
20
  ignore_dependabot: bool,
21
  ignore_direct: bool,
22
  ):
23
+ try:
24
+ date = get_tag_commit_date(token, repo, tag)
25
+ commits = get_commits(token, repo, branch, date)
26
+ except ValueError as e:
27
+ return str(e)
 
 
28
 
29
  result = ""
30
  contributors = {}
graphql_calls.py CHANGED
@@ -47,9 +47,16 @@ def get_tag_commit_date(token, repository, tag):
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
 
@@ -93,6 +100,9 @@ def get_commits(token, repository, branch, since):
93
  """
94
  result = call_with_query(query, token)
95
 
 
 
 
96
  if result['data']['repository']['object'] is None:
97
  raise ValueError("Either the tag or the branch were incorrect.")
98
 
 
47
  response = call_with_query(query, token)
48
 
49
  try:
50
+ repository = response['data']['repository']['object']
51
+
52
+ if repository is None:
53
+ if 'errors' in response:
54
+ raise ValueError(response['errors'][0]['message'])
55
+ raise ValueError('Invalid tag. Does this tag exist?')
56
+
57
+ committed_date = repository['committedDate']
58
+ except (KeyError, TypeError):
59
+ raise ValueError('Invalid token. Does your token have the valid permissions?')
60
 
61
  return committed_date
62
 
 
100
  """
101
  result = call_with_query(query, token)
102
 
103
+ if 'data' not in result:
104
+ raise ValueError(result['errors'][0]['message'])
105
+
106
  if result['data']['repository']['object'] is None:
107
  raise ValueError("Either the tag or the branch were incorrect.")
108