[GitHub Actions] Use actions/labeler (#233)
- Leverage existing labeler action for labels based on files changed. - Change the previous workflow to run on 30 minute intervals to assign author organization membership label, to work on forked pull requests. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
committato da
GitHub
parent
7105a89a51
commit
8956b47747
@@ -0,0 +1,63 @@
|
||||
# Label PRs by Author Org Membership
|
||||
# -------------
|
||||
# This workflow is designed to automatically label pull requests based on the author's membership in the ROCm organization.
|
||||
name: "Label PRs by Author Org Membership"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: "*/30 * * * *" # every 30 minutes
|
||||
|
||||
jobs:
|
||||
label-prs:
|
||||
if: github.repository == 'ROCm/rocm-systems'
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
env:
|
||||
ORG_TO_CHECK: ROCm
|
||||
ORG_LABEL: "organization: ROCm"
|
||||
EXTERNAL_LABEL: "external contribution"
|
||||
steps:
|
||||
- name: Generate GitHub App token
|
||||
id: generate-token
|
||||
uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
|
||||
with:
|
||||
app-id: ${{ secrets.APP_ID }}
|
||||
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
||||
owner: ${{ github.repository_owner }}
|
||||
|
||||
- name: Get open PR numbers
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
||||
run: |
|
||||
gh pr list --state open --json number,labels \
|
||||
--jq '[.[] | select(
|
||||
([.labels[].name] | index(env.ORG_LABEL) | not) and
|
||||
([.labels[].name] | index(env.EXTERNAL_LABEL) | not)
|
||||
) | .number] | .[]' \
|
||||
> pr_numbers.txt
|
||||
|
||||
- name: Label PRs based on author membership
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
||||
run: |
|
||||
while read pr; do
|
||||
echo "Checking PR #$pr"
|
||||
|
||||
labels=$(gh pr view "$pr" --json labels --jq '.labels[].name')
|
||||
|
||||
if echo "$labels" | grep -qFx "${{ env.ORG_LABEL }}" || echo "$labels" | grep -qFx "${{ env.EXTERNAL_LABEL }}"; then
|
||||
echo "PR #$pr already labeled, skipping."
|
||||
continue
|
||||
fi
|
||||
|
||||
author=$(gh pr view "$pr" --json author --jq '.author.login')
|
||||
|
||||
if gh api orgs/${{ env.ORG_TO_CHECK }}/members/$author --silent; then
|
||||
gh pr edit "$pr" --add-label "${{ env.ORG_LABEL }}"
|
||||
else
|
||||
gh pr edit "$pr" --add-label "${{ env.EXTERNAL_LABEL }}"
|
||||
fi
|
||||
done < pr_numbers.txt
|
||||
Fai riferimento in un nuovo problema
Block a user