Skip to content

Conversation

@kpj2006
Copy link
Contributor

@kpj2006 kpj2006 commented Dec 25, 2025

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

  • Chores
    • PRs now automatically receive size labels (XS, S, M, L, XL).
    • Size label assignment moved earlier in the workflow.
    • Contributor-based labeling now runs after size labeling.
    • Minor workflow cleanup and improved logging for label application.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 25, 2025

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Workflow: PR labeling
/.github/workflows/sync-pr-labels.yml
Added a new Step 3 that computes PR size (additions+deletions), maps to `size/XS

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • add sync-pr-labels #6: Modifies the same .github/workflows/sync-pr-labels.yml workflow with overlapping labeling changes (size labeling and step reorder).

Suggested reviewers

  • Zahnentferner

Poem

🐰 I counted additions, subtractions too,
From tiny hops (XS) to hops that grew,
I cleared old hats and placed a new one,
Labels in order, the job is done—hop, run! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'add one more label' is vague and does not clearly convey the main change. The PR actually adds automatic PR size labeling based on line changes, but the title does not reflect this. Use a more descriptive title that reflects the main change, such as 'Add automatic PR size labeling based on line changes' or 'Implement PR size classification from diff statistics'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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}`);
+          }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9afc996 and f28fd3b.

📒 Files selected for processing (1)
  • .github/workflows/sync-pr-labels.yml

…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
Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between f28fd3b and 14b9783.

📒 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: read to issues: write is 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.

@Zahnentferner Zahnentferner merged commit 14c8905 into AOSSIE-Org:main Dec 26, 2025
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants