From a2d8a258ca4638c3385fe0224c74cc39787c59fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 1 Dec 2024 12:38:49 +0100 Subject: [PATCH 1/4] no longer wait for ofborg Now that eval happens on github we no longer should block mergebot prs on ofborg. --- nixpkgs_merge_bot/commands/merge.py | 84 +++++++------------ tests/data/get_statuses_for_commit.json | 102 ------------------------ tests/test_webhook.py | 3 - 3 files changed, 31 insertions(+), 158 deletions(-) delete mode 100644 tests/data/get_statuses_for_commit.json diff --git a/nixpkgs_merge_bot/commands/merge.py b/nixpkgs_merge_bot/commands/merge.py index ecf4e6f..2d1ec8b 100644 --- a/nixpkgs_merge_bot/commands/merge.py +++ b/nixpkgs_merge_bot/commands/merge.py @@ -26,64 +26,42 @@ def process_pull_request_status( ) -> CheckRunResult: check_run_result = CheckRunResult(True, False, False, []) - # As ofBorg takes a while to add a check_suite to the pull request we have to check the statues first if this is still pending - - statuses = client.get_statuses_for_commit( + log.debug(f"{pull_request.number}: Getting check suites for commit") + check_runs_for_commit = client.get_check_runs_for_commit( pull_request.repo_owner, pull_request.repo_name, pull_request.head_sha - ).json() - if statuses["state"] != "success": - check_run_result.success = False - log.info(f"{pull_request.number}: Status {statuses['state']} is not success") - if statuses["state"] == "pending": - check_run_result.success = False - check_run_result.pending = True - message = "Some status is still pending" - log.info(f"{pull_request.number}: {message}") - check_run_result.messages.append(message) - if check_run_result.success: + ) + for check_run in check_runs_for_commit.json()["check_runs"]: log.debug( - f"{pull_request.number} All the statues where fine we now move to check the check_suites" + f"{pull_request.number}: {check_run['name']} conclusion: {check_run['conclusion']} and status: {check_run['status']}" ) - log.debug(f"{pull_request.number}: Getting check suites for commit") - check_runs_for_commit = client.get_check_runs_for_commit( - pull_request.repo_owner, pull_request.repo_name, pull_request.head_sha - ) - for check_run in check_runs_for_commit.json()["check_runs"]: - log.debug( - f"{pull_request.number}: {check_run['name']} conclusion: {check_run['conclusion']} and status: {check_run['status']}" - ) - # Ignoring darwin checks for ofborg as these get stucked quite often - if "darwin" in check_run["name"] and ( - check_run["status"] == "queued" or check_run["status"] == "neutral" + # Ignoring darwin checks for ofborg as these get stucked quite often + if "darwin" in check_run["name"] and ( + check_run["status"] == "queued" or check_run["status"] == "neutral" + ): + log.debug(f"{pull_request.number}: Ignoring darwin check") + continue + + if check_run["status"] != "completed": + message = f"Check run {check_run['name']} is not completed, we will wait for it to finish and if it succeeds we will merge this." + check_run_result.messages.append(message) + log.info(f"{pull_request.number}: {message}") + check_run_result.success = False + if check_run["status"] == "in_progress" or check_run["status"] == "queued": + log.debug(f"{pull_request.number}: Check run is in progress or queued") + check_run_result.pending = True + else: + # if the state is not success or skipped we will decline the merge. The state can be + # Can be one of: success, failure, neutral, cancelled, timed_out, action_required, stale, null, skipped, startup_failure + if not ( + check_run["conclusion"] == "success" + or check_run["conclusion"] == "skipped" + or check_run["conclusion"] == "neutral" ): - log.debug(f"{pull_request.number}: Ignoring darwin check") - continue - if check_run["status"] != "completed": - message = f"Check run {check_run['name']} is not completed, we will wait for it to finish and if it succeeds we will merge this." - check_run_result.messages.append(message) - log.info(f"{pull_request.number}: {message}") check_run_result.success = False - if ( - check_run["status"] == "in_progress" - or check_run["status"] == "queued" - ): - log.debug( - f"{pull_request.number}: Check run is in progress or queued" - ) - check_run_result.pending = True - else: - # if the state is not success or skipped we will decline the merge. The state can be - # Can be one of: success, failure, neutral, cancelled, timed_out, action_required, stale, null, skipped, startup_failure - if not ( - check_run["conclusion"] == "success" - or check_run["conclusion"] == "skipped" - or check_run["conclusion"] == "neutral" - ): - check_run_result.success = False - check_run_result.failed = True - message = f"Check suite {check_run['app']['name']} is {check_run['conclusion']}" - check_run_result.messages.append(message) - log.info(f"{pull_request.number}: message") + check_run_result.failed = True + message = f"Check suite {check_run['app']['name']} is {check_run['conclusion']}" + check_run_result.messages.append(message) + log.info(f"{pull_request.number}: message") return check_run_result diff --git a/tests/data/get_statuses_for_commit.json b/tests/data/get_statuses_for_commit.json deleted file mode 100644 index 4f15a35..0000000 --- a/tests/data/get_statuses_for_commit.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "state": "success", - "statuses": [ - { - "url": "https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e", - "avatar_url": "https://github.com/images/error/hubot_happy.gif", - "id": 1, - "node_id": "MDY6U3RhdHVzMQ==", - "state": "success", - "description": "Build has completed successfully", - "target_url": "https://ci.example.com/1000/output", - "context": "continuous-integration/jenkins", - "created_at": "2012-07-20T01:19:13Z", - "updated_at": "2012-07-20T01:19:13Z" - }, - { - "url": "https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e", - "avatar_url": "https://github.com/images/error/other_user_happy.gif", - "id": 2, - "node_id": "MDY6U3RhdHVzMg==", - "state": "success", - "description": "Testing has completed successfully", - "target_url": "https://ci.example.com/2000/output", - "context": "security/brakeman", - "created_at": "2012-08-20T01:19:13Z", - "updated_at": "2012-08-20T01:19:13Z" - } - ], - "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e", - "total_count": 2, - "repository": { - "id": 1296269, - "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", - "name": "Hello-World", - "full_name": "octocat/Hello-World", - "owner": { - "login": "octocat", - "id": 1, - "node_id": "MDQ6VXNlcjE=", - "avatar_url": "https://github.com/images/error/octocat_happy.gif", - "gravatar_id": "", - "url": "https://api.github.com/users/octocat", - "html_url": "https://github.com/octocat", - "followers_url": "https://api.github.com/users/octocat/followers", - "following_url": "https://api.github.com/users/octocat/following{/other_user}", - "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", - "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", - "organizations_url": "https://api.github.com/users/octocat/orgs", - "repos_url": "https://api.github.com/users/octocat/repos", - "events_url": "https://api.github.com/users/octocat/events{/privacy}", - "received_events_url": "https://api.github.com/users/octocat/received_events", - "type": "User", - "site_admin": false - }, - "private": false, - "html_url": "https://github.com/octocat/Hello-World", - "description": "This your first repo!", - "fork": false, - "url": "https://api.github.com/repos/octocat/Hello-World", - "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", - "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", - "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", - "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", - "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", - "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", - "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", - "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", - "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", - "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", - "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", - "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", - "events_url": "https://api.github.com/repos/octocat/Hello-World/events", - "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", - "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", - "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", - "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", - "git_url": "git:github.com/octocat/Hello-World.git", - "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", - "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", - "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", - "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", - "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", - "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", - "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", - "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", - "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", - "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", - "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", - "ssh_url": "git@github.com:octocat/Hello-World.git", - "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", - "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", - "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", - "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", - "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", - "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", - "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", - "hooks_url": "http://api.github.com/repos/octocat/Hello-World/hooks" - }, - "commit_url": "https://api.github.com/repos/octocat/Hello-World/6dcb09b5b57875f334f61aebed695e2e4193db5e", - "url": "https://api.github.com/repos/octocat/Hello-World/6dcb09b5b57875f334f61aebed695e2e4193db5e/status" -} diff --git a/tests/test_webhook.py b/tests/test_webhook.py index ba9e863..80cfa04 100644 --- a/tests/test_webhook.py +++ b/tests/test_webhook.py @@ -91,9 +91,6 @@ def default_mocks(mocker: MockerFixture) -> dict[str, Any]: "nixpkgs_merge_bot.github.GitHubClient.GithubClient.get_check_runs_for_commit": FakeHttpResponse( TEST_DATA / "get_check_run_for_commit.json" ), - "nixpkgs_merge_bot.github.GitHubClient.GithubClient.get_statuses_for_commit": FakeHttpResponse( - TEST_DATA / "get_statuses_for_commit.json" - ), "nixpkgs_merge_bot.github.GitHubClient.GithubClient.create_issue_comment": FakeHttpResponse( TEST_DATA / "issue_comment.merge.json" ), # unused From 9801901f17f1369d43664185ac68a9a45f053918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 1 Dec 2024 12:40:54 +0100 Subject: [PATCH 2/4] update flakes --- flake.lock | 55 +++++++++++++++++++----------------------------------- 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/flake.lock b/flake.lock index 72705cd..24551df 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1729712798, - "narHash": "sha256-a+Aakkb+amHw4biOZ0iMo8xYl37uUL48YEXIC5PYJ/8=", + "lastModified": 1732988076, + "narHash": "sha256-2uMaVAZn7fiyTUGhKgleuLYe5+EAAYB/diKxrM7g3as=", "owner": "nix-community", "repo": "disko", - "rev": "09a776702b004fdf9c41a024e1299d575ee18a7d", + "rev": "2814a5224a47ca19e858e027f7e8bff74a8ea9f1", "type": "github" }, "original": { @@ -27,11 +27,11 @@ ] }, "locked": { - "lastModified": 1727826117, - "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", + "lastModified": 1730504689, + "narHash": "sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS+b4tfNFCwE=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", + "rev": "506278e768c2a08bec68eb62932193e341f55c90", "type": "github" }, "original": { @@ -42,11 +42,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1729674553, - "narHash": "sha256-avsQc594jov0sLa64mhuEbBTZY+cUuNTnLudrt/0JQo=", + "lastModified": 1733038015, + "narHash": "sha256-kIKqS3093Xz5vuvSLk0x1hqo2pFaGwMjnwr3qrTBkzk=", "owner": "Nixos", "repo": "nixpkgs", - "rev": "c0915172d935f94d92abd5e0d048903446e22c42", + "rev": "767b0e3398fb899d0c88a9f7aecf30dd1cad3166", "type": "github" }, "original": { @@ -56,22 +56,6 @@ "type": "github" } }, - "nixpkgs-stable": { - "locked": { - "lastModified": 1729357638, - "narHash": "sha256-66RHecx+zohbZwJVEPF7uuwHeqf8rykZTMCTqIrOew4=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "bb8c2cf7ea0dd2e18a52746b2c3a5b0c73b93c22", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "release-24.05", - "repo": "nixpkgs", - "type": "github" - } - }, "root": { "inputs": { "disko": "disko", @@ -86,15 +70,14 @@ "inputs": { "nixpkgs": [ "nixpkgs" - ], - "nixpkgs-stable": "nixpkgs-stable" + ] }, "locked": { - "lastModified": 1729695320, - "narHash": "sha256-Fm4cGAlaDwekQvYX0e6t0VjT6YJs3fRXtkyuE4/NzzU=", + "lastModified": 1732575825, + "narHash": "sha256-xtt95+c7OUMoqZf4OvA/7AemiH3aVuWHQbErYQoPwFk=", "owner": "Mic92", "repo": "sops-nix", - "rev": "d089e742fb79259b9c4dd9f18e9de1dd4fa3c1ec", + "rev": "3433ea14fbd9e6671d0ff0dd45ed15ee4c156ffa", "type": "github" }, "original": { @@ -110,11 +93,11 @@ ] }, "locked": { - "lastModified": 1729731316, - "narHash": "sha256-InsUCPq86xyvJ9U+pVijYNBCep/dYACyJblG6fgkkWA=", + "lastModified": 1732791727, + "narHash": "sha256-E3ki8879tKii42pjibenRpJSDVW0mJFfSWHbci5Ck0s=", "owner": "numtide", "repo": "srvos", - "rev": "0e447b6d3f16d6a305ca99ac89686d51042f516a", + "rev": "ce61f7168038e4077ed6e27a4aa9f2c3c3500099", "type": "github" }, "original": { @@ -130,11 +113,11 @@ ] }, "locked": { - "lastModified": 1729613947, - "narHash": "sha256-XGOvuIPW1XRfPgHtGYXd5MAmJzZtOuwlfKDgxX5KT3s=", + "lastModified": 1732894027, + "narHash": "sha256-2qbdorpq0TXHBWbVXaTqKoikN4bqAtAplTwGuII+oAc=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "aac86347fb5063960eccb19493e0cadcdb4205ca", + "rev": "6209c381904cab55796c5d7350e89681d3b2a8ef", "type": "github" }, "original": { From 0524593e01ec9362f128a3e471f3dae1c932cee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 1 Dec 2024 14:29:29 +0100 Subject: [PATCH 3/4] fix mypy formatting --- flake.lock | 7 ++++--- flake.nix | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index 24551df..32e0899 100644 --- a/flake.lock +++ b/flake.lock @@ -113,15 +113,16 @@ ] }, "locked": { - "lastModified": 1732894027, - "narHash": "sha256-2qbdorpq0TXHBWbVXaTqKoikN4bqAtAplTwGuII+oAc=", + "lastModified": 1733059446, + "narHash": "sha256-BPYYjUHzIfSmlbNleJwn7bs4qFMUtlFVajm9TcxKX5U=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "6209c381904cab55796c5d7350e89681d3b2a8ef", + "rev": "4a26912cb1f818df294a750cbedbf3cf1e983765", "type": "github" }, "original": { "owner": "numtide", + "ref": "mypy", "repo": "treefmt-nix", "type": "github" } diff --git a/flake.nix b/flake.nix index b8ee5d3..8ca3bdd 100644 --- a/flake.nix +++ b/flake.nix @@ -7,7 +7,8 @@ flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; # used for development - treefmt-nix.url = "github:numtide/treefmt-nix"; + # https://github.com/numtide/treefmt-nix/pull/269 + treefmt-nix.url = "github:numtide/treefmt-nix/mypy"; treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; sops-nix.url = "github:Mic92/sops-nix"; From b2e8cf0cd1b916a4d27e914855143ddaf37f7825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 1 Dec 2024 14:29:42 +0100 Subject: [PATCH 4/4] treefmt: remove unused args and silent some warnings --- nix/treefmt/flake-module.nix | 41 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/nix/treefmt/flake-module.nix b/nix/treefmt/flake-module.nix index ba4fa16..16b4723 100644 --- a/nix/treefmt/flake-module.nix +++ b/nix/treefmt/flake-module.nix @@ -3,27 +3,26 @@ imports = [ inputs.treefmt-nix.flakeModule ]; - perSystem = - { pkgs, ... }: - { - treefmt = { - projectRootFile = ".git/config"; - programs.nixfmt.enable = true; - programs.shellcheck.enable = true; - programs.deno.enable = true; - settings.formatter.deno.excludes = [ - "tests/data/*.json" - "secrets.yaml" - ]; - settings.formatter.shellcheck.options = [ - "-s" - "bash" - ]; + perSystem = { + treefmt = { + projectRootFile = ".git/config"; + programs.nixfmt.enable = true; + programs.shellcheck.enable = true; + programs.deno.enable = true; - programs.mypy.enable = true; - programs.mypy.directories."." = { }; - programs.ruff.check = true; - programs.ruff.format = true; - }; + settings.global.excludes = [ + "tests/data/*.json" + "secrets.yaml" + ]; + settings.formatter.shellcheck.options = [ + "-s" + "bash" + ]; + + programs.mypy.enable = true; + programs.mypy.directories."." = { }; + programs.ruff.check = true; + programs.ruff.format = true; }; + }; }