amaechler commented on code in PR #20693:
URL: https://github.com/apache/druid/pull/20693#discussion_r4361318964
##########
.github/workflows/labeler.yml:
##########
@@ -23,15 +23,40 @@
name: "Pull Request Labeler"
on:
-- pull_request_target
+ workflow_run:
+ workflows: ["Pull Request Labeler Signal"]
+ types: [completed]
+
+permissions: {}
jobs:
triage:
+ if: github.event.workflow_run.event == 'pull_request'
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- - uses: actions/labeler@v7
+ - name: Find the pull request
+ id: pr
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
+ run: |
+ [[ "$HEAD_SHA" =~ ^[0-9a-f]{40}$ ]] || { echo "::error::bad head sha";
exit 1; }
+ PR_NUMBER=$(gh pr list -R "$GITHUB_REPOSITORY" --state open --search
"$HEAD_SHA" \
+ --json number,headRefOid \
+ --jq "first(.[] | select(.headRefOid == \"$HEAD_SHA\") | .number)")
+ echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
+ - if: steps.pr.outputs.number != ''
+ uses: actions/labeler@v7
with:
- repo-token: "${{ secrets.GITHUB_TOKEN }}"
\ No newline at end of file
+ repo-token: "${{ secrets.GITHUB_TOKEN }}"
+ pr-number: ${{ steps.pr.outputs.number }}
+ # actions/labeler reads head-branch from the pull_request event payload,
which workflow_run lacks
+ - name: Label backport branches
+ if: steps.pr.outputs.number != '' &&
startsWith(github.event.workflow_run.head_branch, 'backport')
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ PR_NUMBER: ${{ steps.pr.outputs.number }}
+ run: gh api "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels" -f
"labels[]=Backport"
Review Comment:
`pull-requests: write` is enough for this call. GitHub's [fine-grained
permissions
reference](https://docs.github.com/en/rest/authentication/permissions-required-for-fine-grained-personal-access-tokens)
lists `POST /repos/{owner}/{repo}/issues/{issue_number}/labels` under both
"Issues" and "Pull requests" write, and `actions/labeler` uses the same
endpoint with the same scopes. I also ran this job in a scratch repository with
only `contents: read` and `pull-requests: write`, and the step added `Backport`
to two test PRs. `issues: write` would only be needed to create a label that
doesn't exist yet, and `Backport` already exists here.
##########
.github/workflows/pr-merged.yml:
##########
@@ -44,4 +48,10 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
- .github/scripts/auto-add-milestone.sh "${{
github.event.pull_request.number }}" "${{ github.repository }}"
+ PR_NUMBER=$(gh api
"repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" \
+ --jq "first(.[] | select(.merged_at != null and .base.ref ==
\"master\" and .merge_commit_sha == \"$GITHUB_SHA\") | .number)")
Review Comment:
In this repository each push to `master` carries one PR: merge commits are
disabled and there is no merge queue. All 1,262 commits on `master` this year
came from single PR merges, mostly squash merges. A rebase merge of a
multi-commit PR is still one PR, and its `merge_commit_sha` is the pushed head.
So `first()` doesn't drop anything today. I added a comment above the lookup
saying to loop over `github.event.commits` if a merge queue is enabled.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]