Skip to content

Commit bc1df63

Browse files
committed
Associate annotations with current GitHub Actions run.
1 parent 0921051 commit bc1df63

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

flake8_github_action/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def action(
9797
token=token.value,
9898
)
9999

100-
check_run_id = check.create_check_run()
100+
# check_run_id = check.create_check_run()
101+
check_run_id = check.find_run_for_action()
101102

102103
flake8_app = Application()
103104
flake8_app.run(args)

flake8_github_action/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ def main(ctx: click.Context, token: str, repo: Union[str, URL, None] = None):
8080

8181

8282
if __name__ == "__main__":
83-
print("GITHUB_ACTION:", os.environ["GITHUB_ACTION"])
8483
print("GITHUB_RUN_ID:", os.environ["GITHUB_RUN_ID"])
8584
print("GITHUB_WORKFLOW:", os.environ["GITHUB_WORKFLOW"])
8685

flake8_github_action/checks.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#
2828

2929
# stdlib
30+
import os
3031
from datetime import datetime
3132

3233
# 3rd party
@@ -67,6 +68,18 @@ class Checks:
6768
#: The token used to authenticate with the GitHub api.
6869
token: Secret = attr.ib(converter=Secret)
6970

71+
def find_run_for_action(self) -> int:
72+
"""
73+
Returns the check run ID that corresponds to the current GitHub Actions run.
74+
"""
75+
76+
url = API_GITHUB_COM / "repos" / self.owner / self.repository_name / "commits" / self.head_sha / "check-runs"
77+
headers = {**common_headers, "Authorization": f"token {self.token.value}"}
78+
79+
for check_run in url.get(headers=headers).json()["check_runs"]:
80+
if check_run["name"] == os.environ.get("GITHUB_WORKFLOW"):
81+
return check_run["id"]
82+
7083
def create_check_run(self) -> int:
7184
"""
7285
Create a check and return its ID.

0 commit comments

Comments
 (0)