From 3b5a864a2be0cc16737a6867ea0899d36a54574e Mon Sep 17 00:00:00 2001 From: Anmol Singh Date: Sun, 26 Feb 2023 01:52:51 +0530 Subject: [PATCH] fix: added ability to use github action token when commenting on PR --- .github/workflows/review_pr.yml | 1 + sources/main.py | 4 ++-- sources/manager_download.py | 2 +- sources/manager_environment.py | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/review_pr.yml b/.github/workflows/review_pr.yml index dd5c50f..ceb79ef 100644 --- a/.github/workflows/review_pr.yml +++ b/.github/workflows/review_pr.yml @@ -32,6 +32,7 @@ jobs: env: INPUT_GH_TOKEN: ${{ secrets.INPUT_GITHUB_TOKEN }} INPUT_WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} + CURRENT_GITHUB_ACTION_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.number }} INPUT_SHOW_TIMEZONE: true INPUT_SHOW_PROJECTS: True diff --git a/sources/main.py b/sources/main.py index 8d980b9..ba687af 100644 --- a/sources/main.py +++ b/sources/main.py @@ -191,9 +191,9 @@ async def main(): DBM.g("Readme updated!") else: DBM.i("Commenting PR...") - pr_data = await DM.get_remote_graphql("get_pr_id", pr_number=EM.PR_NUMBER) + pr_data = await DM.get_remote_graphql("get_pr_id", pr_number=EM.PR_NUMBER, use_github_action=True) pr_id = pr_data["data"]["repository"]["pullRequest"]["id"] - await DM.get_remote_graphql("add_pr_comment", pr_id=pr_id, comment=stats) + await DM.get_remote_graphql("add_pr_comment", pr_id=pr_id, comment=stats, use_github_action=True) DBM.g("PR commented!") DBM.g("Debug run, readme not updated. check the latest comment for the generated stats.") await DM.close_remote_resources() diff --git a/sources/manager_download.py b/sources/manager_download.py index 81bff81..27c7ce7 100644 --- a/sources/manager_download.py +++ b/sources/manager_download.py @@ -250,7 +250,7 @@ class DownloadManager: :param kwargs: Parameters for substitution of variables in dynamic query. :return: Response JSON dictionary. """ - headers = {"Authorization": f"Bearer {EM.GH_TOKEN}"} + headers = {"Authorization": f"Bearer {EM.GH_TOKEN if not kwargs.get('use_github_action', False) else EM.CURRENT_GITHUB_ACTION_TOKEN}"} res = await DownloadManager._client.post("https://api.github.com/graphql", json={"query": Template(GITHUB_API_QUERIES[query]).substitute(kwargs)}, headers=headers) if res.status_code == 200: return res.json() diff --git a/sources/manager_environment.py b/sources/manager_environment.py index e018075..ee1da4d 100644 --- a/sources/manager_environment.py +++ b/sources/manager_environment.py @@ -47,3 +47,4 @@ class EnvironmentManager: DEBUG_LOGGING = getenv("INPUT_DEBUG_LOGGING", "0").lower() in _TRUTHY DEBUG_RUN = getenv("DEBUG_RUN", "False").lower() in _TRUTHY PR_NUMBER = getenv("PR_NUMBER", "") + CURRENT_GITHUB_ACTION_TOKEN = getenv("CURRENT_GITHUB_ACTION_TOKEN", "")