Skip to content

ci: review request maintainers #1053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

awwpotato
Copy link
Collaborator

very janky and probably doesn't work

Comment on lines 32 to 66
- id: get-maintainers
# yamllint disable rule:line-length
run: |
existing_reviewers=$(curl -s "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers")
to_ping=""

for file in $(jq -r '.[]' <<<"${{ steps.changed-files.outputs.files }}"); do
for gh_id in ${jq -r '.[$file][]' result/gh_ids.json}; do
if [ $gh_id == "${{ github.event.pull_request.user.login }}" || $gh_id == $(echo "$existing_reviewers" | jq -r ".users[].login") ]; then
continue
fi
to_ping+="$gh_id,"
done
done

echo "::set-output name=to-ping::$to_ping"
# yamllint enable rule:line-length
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reduce needless maintainer pings, certain scenarios should be conservatively filtered out. For example, when a PR touches many modules, their module maintainers should not be pinged because the PR might be a simple refactor. The safest criteria is when a PR touches only a single module.

Consider taking inspiration from the heuristics I implemented in #749.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, put a maximum limit on the number of maintainers, so that we still allow cases where all the modules of a particular maintainer were changed.

@danth
Copy link
Owner

danth commented Mar 26, 2025

When this is complete we can also remove the "Maintainer CC" section from the pull request template

@awwpotato
Copy link
Collaborator Author

anyone know why this error is happening?

 error:
       … in the condition of the assert statement
         at /nix/store/g4ppspdl4fy7hnp4jgjl4ll03v7i08w3-source/pkgs/build-support/trivial-builders/default.nix:136:5:
          135|     # TODO: To fully deprecate, replace the assertion with `lib.isString` and remove the warning
          136|     assert lib.assertMsg (lib.strings.isConvertibleWithToString text) ''
             |     ^
          137|       pkgs.writeText ${lib.strings.escapeNixString name}: The second argument should be a string, but it's a ${builtins.typeOf text} instead.'';

       … in the left operand of the OR (||) operator
         at /nix/store/g4ppspdl4fy7hnp4jgjl4ll03v7i08w3-source/lib/asserts.nix:39:31:
           38|   # TODO(Profpatsch): add tests that check stderr
           39|   assertMsg = pred: msg: pred || builtins.throw msg;
             |                               ^
           40|

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: attribute 'name' missing

runs-on: ubuntu-24.04
if: github.repository_owner == 'danth'
steps:
- uses: actions/[email protected]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related: #1074

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe that's an issue when it's pull_request, only with pull_request_target. I should probably change it to pull_request_target tho.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that pull_request_target gets some extra permissions on the token, which can be risky. See the warning here.

@awwpotato awwpotato force-pushed the ping-maintainers branch 2 times, most recently from 53a468b to 94ebde1 Compare April 11, 2025 18:58
Copy link
Collaborator

@trueNAHO trueNAHO Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid string injections, we should use environment variables:

env:
  GH_REPO: ${{ github.repository }}
  PR_AUTHOR: ${{ github.event.pull_request.user.login }}
  PR_NUMBER: ${{ github.event.pull_request.number }}

The Bash code could be polished to something like the following partially (not on GitHub) tested:

MAX_MAINTAINERS=5

existing_reviewers="$(
  curl \
    --silent \
    "https://api.github.com/repos/$GH_REPO/pulls/$PR_NUMBER/requested_reviewers" |
    jq --raw-output [.users[].login]
)"

to_ping=()

jq --raw-output '.[]' <<<"$CHANGED_FILES" | while read -r file; do
  jq --arg file "$file" --raw-output '.[$file][]' result/gh_ids.json |
    while read -r gh_id;
  do
    # Do not request the original author or already requested reviewers.
    if [[ "$gh_id" == "$PR_AUTHOR" || "$existing_reviewers" =~ $gh_id ]]; then
        continue
    fi

    to_ping+=("$gh_id")
  done
done

if ((${#to_ping[@]} > 0 && ${#to_ping[@]} <= MAX_MAINTAINERS)); then
  printf '%s\n' "::set-output name=to-ping::$(printf '%s,' "${to_ping[@]}")"
fi

The current "$existing_reviewers" =~ $gh_id check is fragile and should be replaced with a jq command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants