fix: added ability to use github action token when commenting on PR

This commit is contained in:
Anmol Singh
2023-02-26 01:52:51 +05:30
parent 8bd25d079c
commit 3b5a864a2b
4 changed files with 5 additions and 3 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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()

View File

@@ -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", "")