Skip to content

feat(github): support user-defined PR labels#867

Open
kadams54 wants to merge 1 commit into
ColeMurray:mainfrom
CompanyCam:kadams54/feat-user-defined-pr-labels
Open

feat(github): support user-defined PR labels#867
kadams54 wants to merge 1 commit into
ColeMurray:mainfrom
CompanyCam:kadams54/feat-user-defined-pr-labels

Conversation

@kadams54

@kadams54 kadams54 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Add a setting in the GitHub integration screen that lets the admin specify a label that should be applied to all Open Inspect-generated PRs. The use case here is tracking Open Inspect-generated PRs separately from the rest of the PRs (whether human or agent created).

Setting the label in Settings > Integrations > GitHub Bot:

image

Resulting PR:

image

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a global PR Label default for GitHub integrations.
    • Agent-created PRs can now include the configured label.
  • Bug Fixes

    • PR label input is trimmed before saving; empty values are treated as unset.
    • Label creation is best-effort—PR creation continues even if label lookup/creation fails or resolved settings can’t be retrieved.
  • Validation

    • Added validation for the optional PR Label configuration to ensure it is a string.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f45636e1-44da-428b-9d05-42a4c34a2fbd

📥 Commits

Reviewing files that changed from the base of the PR and between 6709ba0 and 9f5fdb4.

📒 Files selected for processing (7)
  • packages/control-plane/src/db/integration-settings.ts
  • packages/control-plane/src/routes/integration-settings.ts
  • packages/control-plane/src/session/durable-object.ts
  • packages/control-plane/src/session/pull-request-service.ts
  • packages/control-plane/src/source-control/providers/github-provider.ts
  • packages/shared/src/types/integrations.ts
  • packages/web/src/components/settings/integrations/github-integration-settings.tsx
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/control-plane/src/routes/integration-settings.ts
  • packages/shared/src/types/integrations.ts
  • packages/control-plane/src/db/integration-settings.ts
  • packages/control-plane/src/session/durable-object.ts
  • packages/control-plane/src/session/pull-request-service.ts
  • packages/web/src/components/settings/integrations/github-integration-settings.tsx
  • packages/control-plane/src/source-control/providers/github-provider.ts

📝 Walkthrough

Walkthrough

Adds an optional prLabel field to GitHub integration settings. It is validated and normalized in the DB layer, exposed in resolved config, read during PR creation, passed to the GitHub provider, and surfaced in the web settings UI.

Changes

PR Label for GitHub Integration

Layer / File(s) Summary
Shared type and DB validation
packages/shared/src/types/integrations.ts, packages/control-plane/src/db/integration-settings.ts
GitHubBotSettings gains optional prLabel; validation trims and normalizes it.
Resolved config API and PR service contract
packages/control-plane/src/routes/integration-settings.ts, packages/control-plane/src/session/pull-request-service.ts
Resolved config endpoint exposes prLabel; PullRequestServiceDeps adds optional prLabel; PR creation conditionally passes labels to the provider.
SessionDO prLabel lookup and wiring
packages/control-plane/src/session/durable-object.ts
createPullRequest performs a best-effort D1 lookup of resolved GitHub settings to extract prLabel, then passes it into SessionPullRequestService.
GitHub provider ensureLabels
packages/control-plane/src/source-control/providers/github-provider.ts
Before attaching labels to a PR, a new ensureLabels helper best-effort POSTs each label to the GitHub labels endpoint, ignoring 422 and logging other failures without throwing.
PR Label settings UI
packages/web/src/components/settings/integrations/github-integration-settings.tsx
GlobalSettingsSection adds prLabel state, initializes/resets/saves it, and renders a new PR Label input field.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • ColeMurray

Poem

🐇 A label for every PR, neat and new,
From settings to GitHub, it travels through.
I trim it, I save it, I hop along bright,
And ensure it exists before taking flight. 🏷️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding user-defined PR labels for GitHub-created pull requests.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@kadams54 kadams54 closed this Jun 30, 2026
@kadams54

Copy link
Copy Markdown
Contributor Author

Premature add here. We'll shake this out at CompanyCam and then I'll resubmit it for upstream inclusion.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/control-plane/src/db/integration-settings.ts (1)

283-289: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Consider validating prLabel length.

Unlike issueSessionInstructions (capped at 10000), prLabel has no upper bound. GitHub rejects label names longer than 50 characters, and because ensureLabels/addLabels are best-effort, an over-length value would silently never be applied. Adding a length check here surfaces the problem at save time instead of failing quietly during PR creation.

♻️ Proposed validation
     if (settings.prLabel !== undefined && typeof settings.prLabel !== "string") {
       throw new IntegrationSettingsValidationError("prLabel must be a string");
     }

     if (settings.prLabel !== undefined) {
-      settings = { ...settings, prLabel: settings.prLabel.trim() || undefined };
+      const trimmed = settings.prLabel.trim();
+      if (trimmed.length > 50) {
+        throw new IntegrationSettingsValidationError("prLabel must be 50 characters or fewer");
+      }
+      settings = { ...settings, prLabel: trimmed || undefined };
     }
🤖 Prompt for 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.

In `@packages/control-plane/src/db/integration-settings.ts` around lines 283 -
289, Add an upper-bound validation for prLabel in the integration settings
validation flow so oversized labels are rejected at save time. Update the logic
in integration-settings validation where prLabel is checked and trimmed to also
enforce GitHub’s 50-character limit, throwing IntegrationSettingsValidationError
with a clear message when exceeded. Keep the existing prLabel string/type and
trim handling in place, and apply the new check alongside
issueSessionInstructions-style validation in the same validation path.
🤖 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
`@packages/web/src/components/settings/integrations/github-integration-settings.tsx`:
- Around line 480-496: The PR Label field in github-integration-settings.tsx is
missing an accessible programmatic association between the visible label and the
Input. Add a stable id to the Input component in this PR Label section and set
the matching htmlFor on the corresponding label so clicks and screen readers
target the field correctly; use the existing PR Label block and Input element to
locate the change.
- Line 218: The `prLabel` value is trimmed before saving, but
`GithubIntegrationSettings` keeps the original untrimmed value in local state,
so the UI can drift from what was actually persisted. After the save completes
in this component, normalize `prLabel` in state to the same trimmed value (or
clear it when trimming results in empty) so the input reflects the saved backend
value. Update the state flow around the `prLabel` save path in
`github-integration-settings.tsx` and ensure the `initialized` guard does not
block this post-save normalization.

---

Nitpick comments:
In `@packages/control-plane/src/db/integration-settings.ts`:
- Around line 283-289: Add an upper-bound validation for prLabel in the
integration settings validation flow so oversized labels are rejected at save
time. Update the logic in integration-settings validation where prLabel is
checked and trimmed to also enforce GitHub’s 50-character limit, throwing
IntegrationSettingsValidationError with a clear message when exceeded. Keep the
existing prLabel string/type and trim handling in place, and apply the new check
alongside issueSessionInstructions-style validation in the same validation path.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: c3306a87-6794-410e-ad8f-38d182ce1ce7

📥 Commits

Reviewing files that changed from the base of the PR and between dc678ed and c3a1180.

📒 Files selected for processing (7)
  • packages/control-plane/src/db/integration-settings.ts
  • packages/control-plane/src/routes/integration-settings.ts
  • packages/control-plane/src/session/durable-object.ts
  • packages/control-plane/src/session/pull-request-service.ts
  • packages/control-plane/src/source-control/providers/github-provider.ts
  • packages/shared/src/types/integrations.ts
  • packages/web/src/components/settings/integrations/github-integration-settings.tsx

Comment thread packages/web/src/components/settings/integrations/github-integration-settings.tsx Outdated
@kadams54 kadams54 deleted the kadams54/feat-user-defined-pr-labels branch June 30, 2026 19:02
@kadams54 kadams54 restored the kadams54/feat-user-defined-pr-labels branch June 30, 2026 19:38
@kadams54

Copy link
Copy Markdown
Contributor Author

OK, confirmed this feature works in our fork. I'll flesh out the body of the PR with more information.

@kadams54 kadams54 reopened this Jun 30, 2026
@kadams54 kadams54 force-pushed the kadams54/feat-user-defined-pr-labels branch from c3a1180 to 6709ba0 Compare June 30, 2026 19:38
@kadams54 kadams54 force-pushed the kadams54/feat-user-defined-pr-labels branch from 6709ba0 to 9f5fdb4 Compare June 30, 2026 19:51
@jehiah

jehiah commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

This setting might make sense in a new 'Source Code Management' setting category (pending in #762) where it applies equally to GitHub and GitLab.

#762 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants