From 49cfe2c9e2a874c3c9061eefbed599e1537ca839 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 8 Nov 2024 23:10:19 -0600 Subject: [PATCH 01/11] feat: set target url --- conda_forge_webservices/linting.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/conda_forge_webservices/linting.py b/conda_forge_webservices/linting.py index 343712ce8..f018ed097 100644 --- a/conda_forge_webservices/linting.py +++ b/conda_forge_webservices/linting.py @@ -59,7 +59,16 @@ def lint_via_github_actions(full_name: str, pr_num: int) -> bool: ) if running: - _set_pr_status(repo_owner, repo_name, sha, "pending") + run = None + for _run in workflow.get_runs(branch=ref, event="workflow_dispatch"): + if uid in run.name: + run = _run + break + 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 From 33adc645582318e0172727e4a928c60343876514 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 8 Nov 2024 23:20:03 -0600 Subject: [PATCH 02/11] feat: make a function and test it --- conda_forge_webservices/linting.py | 15 ++++++++++----- tests/test_live_linter.py | 13 +++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/conda_forge_webservices/linting.py b/conda_forge_webservices/linting.py index f018ed097..48dad0435 100644 --- a/conda_forge_webservices/linting.py +++ b/conda_forge_webservices/linting.py @@ -29,6 +29,15 @@ class LintInfo(TypedDict): sha: str +def _get_workflow_run_from_uid(workflow, uid, ref): + run = None + for _run in workflow.get_runs(branch=ref, event="workflow_dispatch"): + if uid in run.name: + run = _run + break + return run + + def lint_via_github_actions(full_name: str, pr_num: int) -> bool: gh = get_gh_client() repo = gh.get_repo(full_name) @@ -59,11 +68,7 @@ def lint_via_github_actions(full_name: str, pr_num: int) -> bool: ) if running: - run = None - for _run in workflow.get_runs(branch=ref, event="workflow_dispatch"): - if uid in run.name: - run = _run - break + run = _get_workflow_run_from_uid(workflow, uid, ref) if run: target_url = run.html_url else: diff --git a/tests/test_live_linter.py b/tests/test_live_linter.py index c5215cf4f..3310fbcab 100644 --- a/tests/test_live_linter.py +++ b/tests/test_live_linter.py @@ -5,6 +5,7 @@ import github import conda_forge_webservices +from conda_forge_webservices.linting import _set_pr_status, _get_workflow_run_from_uid TEST_CASES = [ ( @@ -104,6 +105,18 @@ def test_linter_pr(pytestconfig): "uid": uid, }, ) + run = _get_workflow_run_from_uid(workflow, uid, branch) + if run: + target_url = run.html_url + else: + target_url = None + _set_pr_status( + "conda-forge", + "conda-forge-webservices", + pr.head.sha, + "pending", + target_url=target_url, + ) print("\nsleeping for four minutes to let the linter work...", flush=True) tot = 0 From c4c95d0ed2b5e8542ba1eb12f0bd779d85a6d2e0 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 8 Nov 2024 23:25:03 -0600 Subject: [PATCH 03/11] fix: bug in getting run and missing a newline --- .../github_actions_integration/linting.py | 2 +- conda_forge_webservices/linting.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/conda_forge_webservices/github_actions_integration/linting.py b/conda_forge_webservices/github_actions_integration/linting.py index f47997829..d6451f481 100644 --- a/conda_forge_webservices/github_actions_integration/linting.py +++ b/conda_forge_webservices/github_actions_integration/linting.py @@ -158,7 +158,7 @@ def build_and_make_lint_comment(gh, repo, pr_id, lints, hints): """, ) - mixed = good + dedent_with_escaped_continue( + mixed = good + "\n" + dedent_with_escaped_continue( """ I do have some suggestions for making it better though... diff --git a/conda_forge_webservices/linting.py b/conda_forge_webservices/linting.py index 48dad0435..5d5394c1a 100644 --- a/conda_forge_webservices/linting.py +++ b/conda_forge_webservices/linting.py @@ -30,12 +30,17 @@ class LintInfo(TypedDict): def _get_workflow_run_from_uid(workflow, uid, ref): - run = None - for _run in workflow.get_runs(branch=ref, event="workflow_dispatch"): + num_try = 0 + max_try = 20 + for run in workflow.get_runs(branch=ref, event="workflow_dispatch"): if uid in run.name: - run = _run + return run + + num_try += 1 + if num_try > max_try: break - return run + + return None def lint_via_github_actions(full_name: str, pr_num: int) -> bool: From d332715dabbb267a1d83172691e37f22484d6221 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 8 Nov 2024 23:30:42 -0600 Subject: [PATCH 04/11] fix: wrong pr status function --- .../github_actions_integration/linting.py | 10 +++++++--- tests/test_live_linter.py | 11 +++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/conda_forge_webservices/github_actions_integration/linting.py b/conda_forge_webservices/github_actions_integration/linting.py index d6451f481..8dacfae53 100644 --- a/conda_forge_webservices/github_actions_integration/linting.py +++ b/conda_forge_webservices/github_actions_integration/linting.py @@ -158,13 +158,17 @@ def build_and_make_lint_comment(gh, repo, pr_id, lints, hints): """, ) - mixed = good + "\n" + dedent_with_escaped_continue( - """ + 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""" diff --git a/tests/test_live_linter.py b/tests/test_live_linter.py index 3310fbcab..45a42d105 100644 --- a/tests/test_live_linter.py +++ b/tests/test_live_linter.py @@ -5,7 +5,8 @@ import github import conda_forge_webservices -from conda_forge_webservices.linting import _set_pr_status, _get_workflow_run_from_uid +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 = [ ( @@ -110,13 +111,7 @@ def test_linter_pr(pytestconfig): target_url = run.html_url else: target_url = None - _set_pr_status( - "conda-forge", - "conda-forge-webservices", - pr.head.sha, - "pending", - target_url=target_url, - ) + 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 From 0d720496df794030c1f0bd3fb8880cf5c5483d52 Mon Sep 17 00:00:00 2001 From: beckermr Date: Fri, 8 Nov 2024 23:47:01 -0600 Subject: [PATCH 05/11] debug: print the url --- tests/test_live_linter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_live_linter.py b/tests/test_live_linter.py index 45a42d105..ab93f5d99 100644 --- a/tests/test_live_linter.py +++ b/tests/test_live_linter.py @@ -111,6 +111,7 @@ def test_linter_pr(pytestconfig): target_url = run.html_url else: target_url = None + print(f"target_url: {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) From 3bc9192da399f67c2440309745257fc47e975fcc Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 9 Nov 2024 00:00:33 -0600 Subject: [PATCH 06/11] debug: what is happening --- tests/test_live_linter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_live_linter.py b/tests/test_live_linter.py index ab93f5d99..b885e5476 100644 --- a/tests/test_live_linter.py +++ b/tests/test_live_linter.py @@ -96,7 +96,7 @@ 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", @@ -106,6 +106,7 @@ def test_linter_pr(pytestconfig): "uid": 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 From d363721f5bf2b671fce46fd4b23a72bcffdf9d59 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 9 Nov 2024 00:06:11 -0600 Subject: [PATCH 07/11] fix: buggy test --- tests/test_live_linter.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_live_linter.py b/tests/test_live_linter.py index b885e5476..4513a22ce 100644 --- a/tests/test_live_linter.py +++ b/tests/test_live_linter.py @@ -103,7 +103,7 @@ def test_linter_pr(pytestconfig): "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}!" @@ -112,7 +112,8 @@ def test_linter_pr(pytestconfig): target_url = run.html_url else: target_url = None - print(f"target_url: {target_url}", flush=True) + 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) From 67342fd65174094954be92639cec2f6b40cd22c3 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 9 Nov 2024 00:12:28 -0600 Subject: [PATCH 08/11] fix: wait for run to start --- tests/test_live_linter.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_live_linter.py b/tests/test_live_linter.py index 4513a22ce..888e0760d 100644 --- a/tests/test_live_linter.py +++ b/tests/test_live_linter.py @@ -107,7 +107,11 @@ def test_linter_pr(pytestconfig): }, ) assert workflow_ran, f"Workflow did not run for PR {pr_number}!" - run = _get_workflow_run_from_uid(workflow, uid, branch) + for _ in range(10): + time.sleep(1) + run = _get_workflow_run_from_uid(workflow, uid, branch) + if run: + break if run: target_url = run.html_url else: From ccdd23571728da8c37ce93e005b1e07f6a519867 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 9 Nov 2024 00:22:11 -0600 Subject: [PATCH 09/11] fix: wait for api --- conda_forge_webservices/linting.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conda_forge_webservices/linting.py b/conda_forge_webservices/linting.py index 5d5394c1a..7ac0ae522 100644 --- a/conda_forge_webservices/linting.py +++ b/conda_forge_webservices/linting.py @@ -73,7 +73,9 @@ def lint_via_github_actions(full_name: str, pr_num: int) -> bool: ) if running: - run = _get_workflow_run_from_uid(workflow, uid, ref) + for _ in range(10): + time.sleep(1) + run = _get_workflow_run_from_uid(workflow, uid, ref) if run: target_url = run.html_url else: From 6ca87ffed483489c4ef8773d378d9bc7517d52b6 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Sat, 9 Nov 2024 00:29:49 -0600 Subject: [PATCH 10/11] Update conda_forge_webservices/github_actions_integration/linting.py --- .../github_actions_integration/linting.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conda_forge_webservices/github_actions_integration/linting.py b/conda_forge_webservices/github_actions_integration/linting.py index 8dacfae53..f25418935 100644 --- a/conda_forge_webservices/github_actions_integration/linting.py +++ b/conda_forge_webservices/github_actions_integration/linting.py @@ -163,10 +163,10 @@ def build_and_make_lint_comment(gh, repo, pr_id, lints, hints): + "\n" + dedent_with_escaped_continue( """ - I do have some suggestions for making it better though... + I do have some suggestions for making it better though... - {} - """ + {} + """ ).format("\n".join(messages)) ) From a8175b7234cc00ef36cdf4bb96ec0b8bb1907245 Mon Sep 17 00:00:00 2001 From: beckermr Date: Sat, 9 Nov 2024 00:32:58 -0600 Subject: [PATCH 11/11] fix: do not repeat myself --- conda_forge_webservices/linting.py | 13 ++++++++++--- tests/test_live_linter.py | 6 +----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/conda_forge_webservices/linting.py b/conda_forge_webservices/linting.py index 7ac0ae522..2b0df2246 100644 --- a/conda_forge_webservices/linting.py +++ b/conda_forge_webservices/linting.py @@ -30,6 +30,15 @@ class LintInfo(TypedDict): 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"): @@ -73,9 +82,7 @@ def lint_via_github_actions(full_name: str, pr_num: int) -> bool: ) if running: - for _ in range(10): - time.sleep(1) - run = _get_workflow_run_from_uid(workflow, uid, ref) + run = _get_workflow_run_from_uid(workflow, uid, ref) if run: target_url = run.html_url else: diff --git a/tests/test_live_linter.py b/tests/test_live_linter.py index 888e0760d..4513a22ce 100644 --- a/tests/test_live_linter.py +++ b/tests/test_live_linter.py @@ -107,11 +107,7 @@ def test_linter_pr(pytestconfig): }, ) assert workflow_ran, f"Workflow did not run for PR {pr_number}!" - for _ in range(10): - time.sleep(1) - run = _get_workflow_run_from_uid(workflow, uid, branch) - if run: - break + run = _get_workflow_run_from_uid(workflow, uid, branch) if run: target_url = run.html_url else: