Skip to content

Commit

Permalink
Merge pull request #128 from NixOS/remove-ofborg
Browse files Browse the repository at this point in the history
no longer wait for ofborg
  • Loading branch information
Lassulus authored Dec 1, 2024
2 parents c0cdb51 + b2e8cf0 commit 03d3e42
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 216 deletions.
56 changes: 20 additions & 36 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
41 changes: 20 additions & 21 deletions nix/treefmt/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
}
84 changes: 31 additions & 53 deletions nixpkgs_merge_bot/commands/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
102 changes: 0 additions & 102 deletions tests/data/get_statuses_for_commit.json

This file was deleted.

3 changes: 0 additions & 3 deletions tests/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 03d3e42

Please sign in to comment.