Skip to content

Commit

Permalink
Add diff fallback URL
Browse files Browse the repository at this point in the history
  • Loading branch information
alstr committed Dec 12, 2024
1 parent b64689f commit 84220a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions GitHubClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def __init__(self):
'Content-Type': 'application/json',
'Authorization': f'token {self.token}',
'X-GitHub-Api-Version': '2022-11-28',
'User-Agent': 'TODOToIssue/5.1.5'
'User-Agent': 'TODOToIssue/5.1.9'
}
self.graphql_headers = {
'Authorization': f'Bearer {os.getenv("INPUT_PROJECTS_SECRET", "")}',
'Accept': 'application/vnd.github.v4+json',
'User-Agent': 'TODOToIssue/5.1.5'
'User-Agent': 'TODOToIssue/5.1.9'
}
auto_p = os.getenv('INPUT_AUTO_P', 'true') == 'true'
self.line_break = '\n\n' if auto_p else '\n'
Expand Down Expand Up @@ -88,7 +88,7 @@ def get_last_diff(self):
'Accept': 'application/vnd.github.v3.diff',
'Authorization': f'token {self.token}',
'X-GitHub-Api-Version': '2022-11-28',
'User-Agent': 'TODOToIssue/5.1.5'
'User-Agent': 'TODOToIssue/5.1.9'
}
diff_request = requests.get(url=diff_url, headers=diff_headers)
if diff_request.status_code == 200:
Expand All @@ -100,6 +100,16 @@ def get_last_diff(self):
if 'application/json' in diff_request.headers['content-type']:
error_response.append(f"Server response: {json.loads(diff_request.text)['message']}")
error_response.append('Operation will abort')

if '/compare/' in diff_url:
# The before SHA may no longer be valid due to a force push, fall back to /commits/ endpoint.
diff_url = f'{self.repos_url}{self.repo}/commits/{self.sha}'
print(f'Falling back to {diff_url}')
diff_request = requests.get(url=diff_url, headers=diff_headers)
if diff_request.status_code == 200:
return diff_request.text
error_response.append('Fallback URL also failed')

raise Exception('\n'.join(error_response))

# noinspection PyMethodMayBeStatic
Expand Down
2 changes: 1 addition & 1 deletion TodoParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import itertools

headers = {
'User-Agent': 'TODOToIssue/5.1.5'
'User-Agent': 'TODOToIssue/5.1.9'
}

class TodoParser(object):
Expand Down

0 comments on commit 84220a4

Please sign in to comment.