Skip to content

Commit

Permalink
Add User-Agent header
Browse files Browse the repository at this point in the history
Fixes #248
  • Loading branch information
alstr committed Nov 22, 2024
1 parent 6cf1955 commit 7b4aab7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions GitHubClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ def __init__(self):
self.issue_headers = {
'Content-Type': 'application/json',
'Authorization': f'token {self.token}',
'X-GitHub-Api-Version': '2022-11-28'
'X-GitHub-Api-Version': '2022-11-28',
'User-Agent': 'TODOToIssue/5.1.5'
}
self.graphql_headers = {
'Authorization': f'Bearer {os.getenv("INPUT_PROJECTS_SECRET", "")}',
'Accept': 'application/vnd.github.v4+json'
'Accept': 'application/vnd.github.v4+json',
'User-Agent': 'TODOToIssue/5.1.5'
}
auto_p = os.getenv('INPUT_AUTO_P', 'true') == 'true'
self.line_break = '\n\n' if auto_p else '\n'
Expand Down Expand Up @@ -79,7 +81,8 @@ def get_last_diff(self):
diff_headers = {
'Accept': 'application/vnd.github.v3.diff',
'Authorization': f'token {self.token}',
'X-GitHub-Api-Version': '2022-11-28'
'X-GitHub-Api-Version': '2022-11-28',
'User-Agent': 'TODOToIssue/5.1.5'
}
diff_request = requests.get(url=diff_url, headers=diff_headers)
if diff_request.status_code == 200:
Expand Down
8 changes: 6 additions & 2 deletions TodoParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from urllib.parse import urlparse
import itertools

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

class TodoParser(object):
"""Parser for extracting information from a given diff file."""
FILE_HUNK_PATTERN = r'(?<=diff)(.*?)(?=diff\s--git\s)'
Expand Down Expand Up @@ -54,7 +58,7 @@ def __init__(self, options=dict()):
if os.getenv('INPUT_NO_STANDARD', 'false') != 'true':
# Load the languages data for ascertaining file types.
languages_url = 'https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml'
languages_request = requests.get(url=languages_url)
languages_request = requests.get(url=languages_url, headers=headers)
if languages_request.status_code == 200:
languages_data = languages_request.text
yaml = YAML(typ='safe')
Expand All @@ -64,7 +68,7 @@ def __init__(self, options=dict()):

# Load the comment syntax data for identifying comments.
syntax_url = 'https://raw.githubusercontent.com/alstr/todo-to-issue-action/master/syntax.json'
syntax_request = requests.get(url=syntax_url)
syntax_request = requests.get(url=syntax_url, headers=headers)
if syntax_request.status_code == 200:
self.syntax_dict = syntax_request.json()
else:
Expand Down

0 comments on commit 7b4aab7

Please sign in to comment.