mirror of
https://github.com/huggingface/diffusers.git
synced 2026-10-23 09:09:01 +03:00
Applies to both the fixes-issue label and the issue-link reminder. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
110 lines
4.0 KiB
YAML
110 lines
4.0 KiB
YAML
name: PR Labeler
|
|
|
|
on:
|
|
pull_request_target:
|
|
types: [opened, synchronize, reopened]
|
|
|
|
|
|
permissions: {}
|
|
|
|
jobs:
|
|
label:
|
|
permissions:
|
|
contents: read
|
|
issues: read
|
|
pull-requests: write
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
REPO: ${{ github.repository }}
|
|
steps:
|
|
# label
|
|
- uses: actions/labeler@bf12e9b00b37c5c0ca2b87b79b2daf7891dbda13 # v7.0.0
|
|
with:
|
|
sync-labels: true
|
|
|
|
# missing-tests
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
id: checkout
|
|
if: ${{ !cancelled() }}
|
|
with:
|
|
ref: ${{ github.event.pull_request.base.sha }}
|
|
- name: Check for missing tests
|
|
id: check
|
|
if: ${{ !cancelled() && steps.checkout.outcome == 'success' }}
|
|
run: |
|
|
gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/files" \
|
|
| python utils/check_test_missing.py
|
|
- name: Add or remove missing-tests label
|
|
if: always()
|
|
run: |
|
|
HAS_LABEL=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/labels" --jq 'any(.[]; .name == "missing-tests")')
|
|
if [ "${{ steps.check.outcome }}" = "failure" ]; then
|
|
if [ "$HAS_LABEL" != "true" ]; then
|
|
gh pr edit "$PR_NUMBER" --add-label "missing-tests"
|
|
fi
|
|
else
|
|
if [ "$HAS_LABEL" = "true" ]; then
|
|
gh pr edit "$PR_NUMBER" --remove-label "missing-tests" 2>/dev/null || true
|
|
fi
|
|
fi
|
|
|
|
# fixes-issue
|
|
- name: Check for linked closing issues
|
|
# An issue the PR author opened after the PR does not count as linked.
|
|
if: ${{ !cancelled() }}
|
|
run: |
|
|
OWNER="${REPO%/*}"
|
|
NAME="${REPO#*/}"
|
|
COUNT=$(gh api graphql \
|
|
-F owner="$OWNER" -F name="$NAME" -F number="$PR_NUMBER" \
|
|
-f query='
|
|
query($owner: String!, $name: String!, $number: Int!) {
|
|
repository(owner: $owner, name: $name) {
|
|
pullRequest(number: $number) {
|
|
createdAt
|
|
author { login }
|
|
closingIssuesReferences(first: 50) {
|
|
nodes { createdAt author { login } }
|
|
}
|
|
}
|
|
}
|
|
}' \
|
|
--jq '.data.repository.pullRequest as $pr
|
|
| [$pr.closingIssuesReferences.nodes[]
|
|
| select(.author.login != $pr.author.login or .createdAt < $pr.createdAt)]
|
|
| length')
|
|
HAS_LABEL=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/labels" --jq 'any(.[]; .name == "fixes-issue")')
|
|
if [ "${COUNT:-0}" -gt 0 ]; then
|
|
if [ "$HAS_LABEL" != "true" ]; then
|
|
gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "fixes-issue"
|
|
fi
|
|
else
|
|
if [ "$HAS_LABEL" = "true" ]; then
|
|
gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "fixes-issue" 2>/dev/null || true
|
|
fi
|
|
fi
|
|
|
|
# size-label
|
|
- name: Label PR by diff size
|
|
if: ${{ !cancelled() }}
|
|
run: |
|
|
DIFF_SIZE=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}" --jq '.additions + .deletions')
|
|
if [ "$DIFF_SIZE" -lt 50 ]; then
|
|
CANDIDATE_LABEL="size/S"
|
|
elif [ "$DIFF_SIZE" -lt 200 ]; then
|
|
CANDIDATE_LABEL="size/M"
|
|
else
|
|
CANDIDATE_LABEL="size/L"
|
|
fi
|
|
CURRENT_LABELS=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/labels" --jq '.[].name')
|
|
for label in size/S size/M size/L; do
|
|
if [ "$label" != "$CANDIDATE_LABEL" ] && echo "$CURRENT_LABELS" | grep -qx "$label"; then
|
|
gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$label" 2>/dev/null || true
|
|
fi
|
|
done
|
|
if ! echo "$CURRENT_LABELS" | grep -qx "$CANDIDATE_LABEL"; then
|
|
gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "$CANDIDATE_LABEL"
|
|
fi
|