-
Notifications
You must be signed in to change notification settings - Fork 3
add one more label #8
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
Conversation
📝 WalkthroughWalkthroughAdds a PR size-labeling step to the GitHub Actions workflow that computes total changes (additions + deletions), clears existing size/* labels, applies a new size/{XS,S,M,L,XL} label, and reorders steps so size labeling runs before contributor-based labeling; checkout/fetch-depth was removed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant PR as Pull Request (GitHub)
participant Runner as Actions Runner
participant API as GitHub REST API / Labels
Note over PR,Runner: PR opened/updated triggers workflow
PR->>Runner: workflow_dispatch / pull_request event
Runner->>API: fetch PR data (additions,deletions,labels)
alt compute size
Runner->>Runner: compute total = additions + deletions
Runner->>Runner: map total -> size label (XS/S/M/L/XL)
end
Runner->>API: remove existing `size/*` labels
Runner->>API: add new `size/{...}` label
Runner->>API: continue other labeling steps (issue/file/contributor)
API-->>Runner: 200 OK
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
.github/workflows/sync-pr-labels.yml (1)
192-256: LGTM! PR size labeling implementation is solid.The logic correctly calculates total changes, maps them to size labels, clears stale labels, and applies the new label. The thresholds (XS ≤10, S ≤50, M ≤200, L ≤500, XL >500) are reasonable for most repositories.
Optional: Add error handling for robustness
While the current implementation is functional, wrapping the API calls in a try-catch block would provide better resilience and logging:
script: | const prNumber = context.payload.pull_request.number; + try { // Get PR details to calculate size const pr = await github.rest.pulls.get({ owner: context.repo.owner, repo: context.repo.repo, pull_number: prNumber }); const additions = pr.data.additions; const deletions = pr.data.deletions; const totalChanges = additions + deletions; console.log(`PR has ${additions} additions and ${deletions} deletions (${totalChanges} total changes)`); // Determine size label based on total changes let sizeLabel = ''; if (totalChanges <= 10) { sizeLabel = 'size/XS'; } else if (totalChanges <= 50) { sizeLabel = 'size/S'; } else if (totalChanges <= 200) { sizeLabel = 'size/M'; } else if (totalChanges <= 500) { sizeLabel = 'size/L'; } else { sizeLabel = 'size/XL'; } console.log(`Applying size label: ${sizeLabel}`); // Remove any existing size labels first const currentLabels = await github.rest.issues.listLabelsOnIssue({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber }); const sizeLabelsToRemove = currentLabels.data .map(label => label.name) .filter(name => name.startsWith('size/')); for (const label of sizeLabelsToRemove) { await github.rest.issues.removeLabel({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, name: label }); } // Apply the new size label await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, labels: [sizeLabel] }); + } catch (error) { + console.log(`Error applying PR size label: ${error.message}`); + }
…kflow doesn't need to checkout any code since it only uses GitHub API calls for labeling Permissions corrected - Changed issues: read → issues: write since labeling operations require write access to the issues API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
.github/workflows/sync-pr-labels.yml (1)
187-251: Well-implemented PR size labeling with good cleanup logic.The implementation correctly:
- Calculates total changes from additions and deletions
- Maps to appropriate size labels with reasonable thresholds
- Removes existing size/* labels before applying the new one to prevent duplicates
Consider adding error handling similar to other steps in the workflow for consistency:
🔎 Suggested enhancement with error handling
# STEP 3: PR size labels - name: Apply PR size label uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const prNumber = context.payload.pull_request.number; + try { // Get PR details to calculate size const pr = await github.rest.pulls.get({ owner: context.repo.owner, repo: context.repo.repo, pull_number: prNumber }); const additions = pr.data.additions; const deletions = pr.data.deletions; const totalChanges = additions + deletions; console.log(`PR has ${additions} additions and ${deletions} deletions (${totalChanges} total changes)`); // Determine size label based on total changes let sizeLabel = ''; if (totalChanges <= 10) { sizeLabel = 'size/XS'; } else if (totalChanges <= 50) { sizeLabel = 'size/S'; } else if (totalChanges <= 200) { sizeLabel = 'size/M'; } else if (totalChanges <= 500) { sizeLabel = 'size/L'; } else { sizeLabel = 'size/XL'; } console.log(`Applying size label: ${sizeLabel}`); // Remove any existing size labels first const currentLabels = await github.rest.issues.listLabelsOnIssue({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber }); const sizeLabelsToRemove = currentLabels.data .map(label => label.name) .filter(name => name.startsWith('size/')); for (const label of sizeLabelsToRemove) { await github.rest.issues.removeLabel({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, name: label }); } // Apply the new size label await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, labels: [sizeLabel] }); + } catch (error) { + console.log(`Error applying size label: ${error.message}`); + }
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/sync-pr-labels.yml
🔇 Additional comments (2)
.github/workflows/sync-pr-labels.yml (2)
12-12: LGTM! Permission change is necessary.The permission change from
issues: readtoissues: writeis required for the workflow to perform label add/remove operations throughout the workflow steps.
252-252: LGTM! Step numbering updated correctly.The comment correctly reflects the new step order after inserting the PR size label step.
By estimating size based on the number of lines.
Also, I will first remove all existing size labels, because the size of a PR should depend on the PR’s line changes, not on the manually
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.