Unverified Commit 84d6678f authored by Wolfgang Walther's avatar Wolfgang Walther
Browse files

ci/github-script/merge: support OR conditions

This supports AND on the first and OR on the second level, which is
needed for some follow up work like backports, approval based merges or
trusted maintainers.
parent 6848f938
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -44,7 +44,9 @@ To ensure security and a focused utility, the bot adheres to specific limitation

- The PR targets `master`, `staging`, or `staging-next`.
- The PR only touches packages located under `pkgs/by-name/*`.
- The PR is authored by [@r-ryantm](https://nix-community.github.io/nixpkgs-update/r-ryantm/) or a [committer][@NixOS/nixpkgs-committers].
- The PR is either:
  - authored by a [committer][@NixOS/nixpkgs-committers], or
  - created by [@r-ryantm](https://nix-community.github.io/nixpkgs-update/r-ryantm/).
- The user attempting to merge is a member of [@NixOS/nixpkgs-maintainers].
- The user attempting to merge is a maintainer of all packages touched by the PR.

+17 −6
Original line number Diff line number Diff line
@@ -28,9 +28,10 @@ function runChecklist({
      'staging-next',
    ].includes(pull_request.base.ref),
    'PR touches only packages in `pkgs/by-name/`.': allByName,
    'PR authored by r-ryantm or committer.':
      pull_request.user.login === 'r-ryantm' ||
      committers.has(pull_request.user.id),
    'PR is at least one of:': {
      'Authored by a committer.': committers.has(pull_request.user.id),
      'Created by r-ryantm.': pull_request.user.login === 'r-ryantm',
    },
  }

  if (user) {
@@ -48,7 +49,9 @@ function runChecklist({
    checklist['PR has maintainers eligible to merge.'] = eligible.size > 0
  }

  const result = Object.values(checklist).every(Boolean)
  const result = Object.values(checklist).every((v) =>
    typeof v === 'boolean' ? v : Object.values(v).some(Boolean),
  )

  log('checklist', JSON.stringify(checklist))
  log('eligible', JSON.stringify(Array.from(eligible)))
@@ -255,8 +258,16 @@ async function handleMerge({
      `@${comment.user.login} wants to merge this PR.`,
      '',
      'Requirements to merge this PR with `@NixOS/nixpkgs-merge-bot merge`:',
      ...Object.entries(checklist).map(
        ([msg, res]) => `- :${res ? 'white_check_mark' : 'x'}: ${msg}`,
      ...Object.entries(checklist).flatMap(([msg, res]) =>
        typeof res === 'boolean'
          ? `- :${res ? 'white_check_mark' : 'x'}: ${msg}`
          : [
              `- :${Object.values(res).some(Boolean) ? 'white_check_mark' : 'x'}: ${msg}`,
              ...Object.entries(res).map(
                ([msg, res]) =>
                  `  - ${res ? ':white_check_mark:' : ':white_large_square:'} ${msg}`,
              ),
            ],
      ),
      '',
    ]