Skip to content

Commit

Permalink
Merge pull request #768 from conda-forge/linter-link-to-run
Browse files Browse the repository at this point in the history
feat: set target url
  • Loading branch information
beckermr authored Nov 9, 2024
2 parents 49bb5b0 + 306f4b7 commit cd43445
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
16 changes: 10 additions & 6 deletions conda_forge_webservices/github_actions_integration/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,17 @@ def build_and_make_lint_comment(gh, repo, pr_id, lints, hints):
""",
)

mixed = good + dedent_with_escaped_continue(
"""
I do have some suggestions for making it better though...
mixed = (
good
+ "\n"
+ dedent_with_escaped_continue(
"""
I do have some suggestions for making it better though...
{}
"""
).format("\n".join(messages))
{}
"""
).format("\n".join(messages))
)

bad = dedent_with_escaped_continue(
f"""
Expand Down
30 changes: 29 additions & 1 deletion conda_forge_webservices/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ class LintInfo(TypedDict):
sha: str


def _get_workflow_run_from_uid(workflow, uid, ref):
for _ in range(10):
time.sleep(1)
run = _inner_get_workflow_run_from_uid(workflow, uid, ref)
if run:
return run
return None


def _inner_get_workflow_run_from_uid(workflow, uid, ref):
num_try = 0
max_try = 20
for run in workflow.get_runs(branch=ref, event="workflow_dispatch"):
if uid in run.name:
return run

num_try += 1
if num_try > max_try:
break

return None


def lint_via_github_actions(full_name: str, pr_num: int) -> bool:
gh = get_gh_client()
repo = gh.get_repo(full_name)
Expand Down Expand Up @@ -59,7 +82,12 @@ def lint_via_github_actions(full_name: str, pr_num: int) -> bool:
)

if running:
_set_pr_status(repo_owner, repo_name, sha, "pending")
run = _get_workflow_run_from_uid(workflow, uid, ref)
if run:
target_url = run.html_url
else:
target_url = None
_set_pr_status(repo_owner, repo_name, sha, "pending", target_url=target_url)

return running

Expand Down
15 changes: 13 additions & 2 deletions tests/test_live_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import github

import conda_forge_webservices
from conda_forge_webservices.linting import _get_workflow_run_from_uid
from conda_forge_webservices.github_actions_integration.linting import set_pr_status

TEST_CASES = [
(
Expand Down Expand Up @@ -94,16 +96,25 @@ def test_linter_pr(pytestconfig):
uid = uuid.uuid4().hex
pr = repo.get_pull(pr_number)
workflow = repo.get_workflow("webservices-workflow-dispatch.yml")
workflow.create_dispatch(
workflow_ran = workflow.create_dispatch(
ref=branch,
inputs={
"task": "lint",
"repo": "conda-forge-webservices",
"pr_number": str(pr_number),
"container_tag": conda_forge_webservices.__version__.replace("+", "."),
"uid": uid,
"uuid": uid,
},
)
assert workflow_ran, f"Workflow did not run for PR {pr_number}!"
run = _get_workflow_run_from_uid(workflow, uid, branch)
if run:
target_url = run.html_url
else:
target_url = None
assert target_url is not None
print(f"target_url for PR {pr_number}: {target_url}", flush=True)
set_pr_status(repo, pr.head.sha, "pending", target_url=target_url)

print("\nsleeping for four minutes to let the linter work...", flush=True)
tot = 0
Expand Down

0 comments on commit cd43445

Please sign in to comment.