Skip to content

Commit

Permalink
Add authen for pervious comment query
Browse files Browse the repository at this point in the history
  • Loading branch information
antiagainst committed Jun 8, 2021
1 parent f7b3b2a commit 2605b15
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions build_tools/android/post_benchmarks_as_pr_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,12 @@ def post_to_gist(filename: str, content: str, verbose: bool = False):
def get_previous_comment_on_pr(pr_number: str,
verbose: bool = False) -> Optional[int]:
"""Gets the previous comment's ID from GitHub."""
headers = {"Accept": "application/vnd.github.v3+json"}
# Increasing per_page limit requires user authentication.
api_token = get_required_env_var('GITHUB_TOKEN')
headers = {
"Accept": "application/vnd.github.v3+json",
"Authorization": f"token {api_token}",
}
payload = json.dumps({"per_page": 100})

api_endpoint = f"{GITHUB_IREE_API_PREFIX}/issues/{pr_number}/comments"
Expand All @@ -386,9 +391,12 @@ def get_previous_comment_on_pr(pr_number: str,
f"Failed to get PR comments from GitHub; error code: {response.status_code}"
)

response = response.json()
if verbose:
print(response)

# Find the last comment from GITHUB_USER and has the ABBR_PR_COMMENT_TITILE
# keyword.
response = response.json()
for comment in reversed(response):
if (comment["user"]["login"] == GITHUB_USER) and (ABBR_PR_COMMENT_TITLE
in comment["body"]):
Expand Down

0 comments on commit 2605b15

Please sign in to comment.