feat: added ability to generate stats on PR and sent to latest comment on PR

This commit is contained in:
Anmol Singh
2023-02-25 01:52:33 +05:30
parent c8ef0e49be
commit 94e4a6cbde
4 changed files with 86 additions and 2 deletions

View File

@@ -185,8 +185,17 @@ async def main():
init_localization_manager()
DBM.i("Managers initialized.")
if GHM.update_readme(await get_stats()):
DBM.g("Readme updated!")
stats = await get_stats()
if not EM.DEBUG_RUN:
if GHM.update_readme(stats):
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_id = pr_data["data"]["repository"]["pullRequest"]["id"]
await DM.get_remote_graphql("add_pr_comment", pr_id=pr_id, comment=stats)
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

@@ -121,6 +121,26 @@ GITHUB_API_QUERIES = {
}
}
""",
# Query to collect current PR ID
# NOTE: Only to be used for PR review not to be used with actual action
"get_pr_id": """
{
repository(owner: "anmol098", name: "waka-readme-stats") {
pullRequest(number: $pr_number) {
id
}
}
}
""",
"add_pr_comment": """
mutation {
addComment(input: {subjectId: "$pr_id", body: "$comment"}) {
subject {
id
}
}
}
"""
}

View File

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