Skip to content

ci: add PR size labeling workflow#2042

Merged
Pouyanpi merged 2 commits into
developfrom
pouyanpi/ci/pr-size-label
Jun 17, 2026
Merged

ci: add PR size labeling workflow#2042
Pouyanpi merged 2 commits into
developfrom
pouyanpi/ci/pr-size-label

Conversation

@Pouyanpi

@Pouyanpi Pouyanpi commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Description

Apply a "size: XS/S/M/L/XL" label to pull requests based on a weighted diff score (code + 50% docs + 50% tests), excluding poetry.lock and recorded test data so generated fixtures do not dominate the size.

Runs on pull_request_target with no checkout of PR head code; the job reads the PR file list and calls the labels API only.

Related Issue(s)

Verification

AI Assistance

  • No AI tools were used.
  • AI tools were used; a human reviewed and can explain every change (tool: ___).

Checklist

  • I've read the CONTRIBUTING guidelines.
  • This PR links to a triaged issue assigned to me.
  • My PR title follows the project commit convention.
  • I've updated the documentation if applicable.
  • I've added tests if applicable.
  • I've noted any verification beyond CI and any checks I couldn't run.
  • I did not update generated changelog files manually.
  • I addressed all CodeRabbit, Greptile, and other review comments, or replied with why no change is needed.
  • @mentions of the person or team responsible for reviewing proposed changes.

Summary by CodeRabbit

  • Chores
    • Added automated pull request size classification to streamline the code review process.

Apply a "size: XS/S/M/L/XL" label to pull requests based on a weighted
diff score (code + 50% docs + 50% tests), excluding poetry.lock and
recorded test data so generated fixtures do not dominate the size.

Runs on pull_request_target with no checkout of PR head code; the job
reads the PR file list and calls the labels API only.

Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
@Pouyanpi Pouyanpi self-assigned this Jun 17, 2026
@Pouyanpi Pouyanpi added status: needs triage New issues that have not yet been reviewed or categorized. status: triaged Triaged by a maintainer; eligible for automated review (CodeRabbit/Greptile). and removed status: needs triage New issues that have not yet been reviewed or categorized. labels Jun 17, 2026
@greptile-apps

greptile-apps Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a GitHub Actions workflow that automatically applies a size: XS/S/M/L/XL label to pull requests based on a weighted line-diff score (full weight for code, 50% for docs and tests), excluding generated/fixture files.

  • Runs under pull_request_target with a pinned SHA for actions/github-script, least-privilege permissions (pull-requests: write only), and a concurrency guard to prevent duplicate runs on rapid pushes.
  • Classifies files into code/docs/tests buckets, computes a weighted score, removes any stale size: labels (with a 404-safe try/catch), and adds the new label only when it isn't already present.

Confidence Score: 5/5

Safe to merge — the workflow is a self-contained CI labeler with no effect on tests, builds, or the main codebase.

The only changed file is the new labeling workflow. It never checks out or runs PR-head code, uses a pinned action SHA, scopes permissions to pull-requests: write, and correctly guards the removeLabel call against 404s.

No files require special attention.

Important Files Changed

Filename Overview
.github/workflows/pr-size-label.yml New workflow that labels PRs with XS/S/M/L/XL based on a weighted diff score; runs under pull_request_target with a pinned action SHA, scoped permissions, and a 404-guarded removeLabel call.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[pull_request_target\nopened / synchronize / reopened] --> B[Fetch PR file list\ngithub.paginate listFiles]
    B --> C{isExcluded?\npoetry.lock, cassettes,\nrecordings, fixtures}
    C -- yes --> D[skip file]
    C -- no --> E{isDocs?\ndocs/ or .md}
    E -- yes --> F[docs += additions + deletions]
    E -- no --> G{isTests?\ntests/}
    G -- yes --> H[tests += additions + deletions]
    G -- no --> I[code += additions + deletions]
    F & H & I --> J[score = code + floor of docs/2 + floor of tests/2]
    J --> K{score thresholds}
    K -- lt 10 --> L[size: XS]
    K -- lt 50 --> M[size: S]
    K -- lt 250 --> N[size: M]
    K -- lt 1000 --> O[size: L]
    K -- 1000+ --> P[size: XL]
    L & M & N & O & P --> Q[Remove stale size: labels\nwith 404 guard]
    Q --> R{label already\npresent?}
    R -- no --> S[addLabels]
    R -- yes --> T[no-op]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[pull_request_target\nopened / synchronize / reopened] --> B[Fetch PR file list\ngithub.paginate listFiles]
    B --> C{isExcluded?\npoetry.lock, cassettes,\nrecordings, fixtures}
    C -- yes --> D[skip file]
    C -- no --> E{isDocs?\ndocs/ or .md}
    E -- yes --> F[docs += additions + deletions]
    E -- no --> G{isTests?\ntests/}
    G -- yes --> H[tests += additions + deletions]
    G -- no --> I[code += additions + deletions]
    F & H & I --> J[score = code + floor of docs/2 + floor of tests/2]
    J --> K{score thresholds}
    K -- lt 10 --> L[size: XS]
    K -- lt 50 --> M[size: S]
    K -- lt 250 --> N[size: M]
    K -- lt 1000 --> O[size: L]
    K -- 1000+ --> P[size: XL]
    L & M & N & O & P --> Q[Remove stale size: labels\nwith 404 guard]
    Q --> R{label already\npresent?}
    R -- no --> S[addLabels]
    R -- yes --> T[no-op]
Loading

Reviews (2): Last reviewed commit: "ci: guard size-label removal against 404..." | Re-trigger Greptile

Comment thread .github/workflows/pr-size-label.yml
Comment thread .github/workflows/pr-size-label.yml Outdated
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new GitHub Actions workflow (.github/workflows/pr-size-label.yml) is added. It triggers on pull_request_target events, fetches the PR's changed file list via the GitHub API, excludes lock files and test fixtures, categorizes files into code/docs/tests, computes a weighted score, and applies a size: XS/S/M/L/XL label while removing any outdated size labels.

Changes

PR Size Label Workflow

Layer / File(s) Summary
Workflow trigger, permissions, and concurrency
.github/workflows/pr-size-label.yml
Defines pull_request_target trigger on opened, synchronize, and reopened events with empty workflow-level permissions and per-PR concurrency group that cancels in-progress runs.
Size label computation and application
.github/workflows/pr-size-label.yml
Fetches PR file list via GitHub API, excludes poetry.lock and cassette/recording/fixture paths, categorizes remaining files as docs (docs/* and markdown), tests, or code, computes score = code + floor(docs/2) + floor(tests/2), maps to a size band, removes mismatched existing size: labels, and adds the computed label if absent.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'ci: add PR size labeling workflow' clearly and concisely summarizes the main change—introducing a new GitHub Actions workflow for automatic PR size labeling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Test Results For Major Changes ✅ Passed This PR adds a GitHub Actions workflow file for PR labeling automation. Changes are operational/CI-focused with no modifications to application code, numerics, convergence, or performance, making t...

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pouyanpi/ci/pr-size-label

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/pr-size-label.yml:
- Around line 72-80: The removeLabel API call can fail with a 404 error if
another workflow or actor has already removed the label, which causes the entire
workflow to fail. Wrap the github.rest.issues.removeLabel call in a try-catch
block to handle this benign race condition. In the catch block, check if the
error is a 404 status code (which indicates the label was already removed), and
if so, silently ignore it by continuing to the next iteration. For any other
errors, you may choose to log or handle them differently, but the 404 should be
treated as a non-fatal condition that allows the labeling workflow to succeed.
- Around line 26-27: The workflow permissions block currently only includes
`pull-requests: write`, but the workflow uses `github.rest.issues.removeLabel()`
and `github.rest.issues.addLabels()` which require the `issues: write`
permission scope. Add `issues: write` to the permissions section in the workflow
file alongside the existing `pull-requests: write` permission to ensure these
label operations have the necessary access permissions and will not fail with a
403 error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 402786ba-daa2-4415-982a-bf8a3a9afe66

📥 Commits

Reviewing files that changed from the base of the PR and between 6cb7030 and 5644346.

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

Comment thread .github/workflows/pr-size-label.yml
Comment thread .github/workflows/pr-size-label.yml
@Pouyanpi Pouyanpi merged commit 75836f3 into develop Jun 17, 2026
3 checks passed
@Pouyanpi Pouyanpi deleted the pouyanpi/ci/pr-size-label branch June 17, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: triaged Triaged by a maintainer; eligible for automated review (CodeRabbit/Greptile).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant