Skip to content

Add WithHead option to prcreator for App-auth PR creation#4974

Open
jmguzik wants to merge 1 commit intoopenshift:mainfrom
jmguzik:prcreation
Open

Add WithHead option to prcreator for App-auth PR creation#4974
jmguzik wants to merge 1 commit intoopenshift:mainfrom
jmguzik:prcreation

Conversation

@jmguzik
Copy link
Contributor

@jmguzik jmguzik commented Feb 27, 2026

Allow prcreator to skip git operations (fork, commit, push) and only create/update the PR when --head is provided. This enables a split workflow where fork+push is handled externally (e.g. via bash with PAT) and prcreator only does PR creation using GitHub App auth.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added head option to PR creation for using pre-existing branch references
    • Improved issue lookups with organization context awareness
    • Enhanced PR descriptions with CC mentions for assigned reviewers

Allow prcreator to skip git operations (fork, commit, push) and only
create/update the PR when --head is provided. This enables a split
workflow where fork+push is handled externally (e.g. via bash with PAT)
and prcreator only does PR creation using GitHub App auth.

Signed-off-by: Jakub Guzik <jguzik@redhat.com>
@openshift-ci-robot
Copy link
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Walkthrough

This pull request adds support for creating pull requests with a pre-pushed head reference via a new WithHead option, introduces an OrgAwareClient wrapper for automatic organization context, and refactors PR option handling to use variadic arguments instead of explicit parameters.

Changes

Cohort / File(s) Summary
Command-line Interface
cmd/prcreator/main.go
Adds head command-line flag and refactors PR option passing to use variadic PrOption arguments with WithHead option conditionally included when head is provided.
Organization-Aware Client
pkg/github/prcreation/orgaware.go
New file introducing OrgAwareClient type that wraps github.Client and embeds organization context, overriding FindIssues to automatically include org in requests via FindIssuesWithOrg.
PR Creation Logic
pkg/github/prcreation/prcreation.go
Introduces WithHead option and head field to PrOptions, adds internal upsertPR helper for pre-pushed head workflows, new formatAssigneeCC helper for formatting assignees as CC mentions in PR body, and updates label/assignee handling logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Structure And Quality ⚠️ Warning Pull request introduces new functionality without providing test files to verify their behavior. Add comprehensive test files for the new functionality including prcreation_test.go and orgaware_test.go with unit tests covering new features.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a WithHead option to prcreator that enables App-auth PR creation by allowing external git operations.
Stable And Deterministic Test Names ✅ Passed The pull request contains only production code files with no test code, making this test name stability check not applicable.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 27, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jmguzik

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 27, 2026
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/github/prcreation/prcreation.go`:
- Around line 124-126: Before calling upsertPR, add fast-fail validation of
inputs: if prArgs.head != "" validate the head value format (e.g., non-empty and
matches expected "user:branch" or "owner/branch" pattern) and return a clear
error if malformed; otherwise (when prArgs.head == "") ensure a token path is
provided (e.g., prArgs.tokenPath is non-empty) and return an error if missing.
Place these checks immediately before the existing conditional that calls
o.upsertPR(org, repo, branch, prTitle, prArgs) so invalid inputs are rejected
early.

ℹ️ Review info

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 27060f7 and d2b6d11.

📒 Files selected for processing (3)
  • cmd/prcreator/main.go
  • pkg/github/prcreation/orgaware.go
  • pkg/github/prcreation/prcreation.go

Comment on lines +124 to +126
if prArgs.head != "" {
return o.upsertPR(org, repo, branch, prTitle, prArgs)
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Validate execution mode inputs before branching.

This branch should fail fast for malformed --head and for non-head mode without a token path; otherwise failures happen later during API/git operations and are harder to diagnose.

Suggested fix
 	if prArgs.head != "" {
+		parts := strings.SplitN(prArgs.head, ":", 2)
+		if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
+			return fmt.Errorf("invalid --head value %q, expected <owner>:<branch>", prArgs.head)
+		}
 		return o.upsertPR(org, repo, branch, prTitle, prArgs)
 	}
+
+	if o.TokenPath == "" {
+		return fmt.Errorf("token path is required when --head is not set")
+	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if prArgs.head != "" {
return o.upsertPR(org, repo, branch, prTitle, prArgs)
}
if prArgs.head != "" {
parts := strings.SplitN(prArgs.head, ":", 2)
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
return fmt.Errorf("invalid --head value %q, expected <owner>:<branch>", prArgs.head)
}
return o.upsertPR(org, repo, branch, prTitle, prArgs)
}
if o.TokenPath == "" {
return fmt.Errorf("token path is required when --head is not set")
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/github/prcreation/prcreation.go` around lines 124 - 126, Before calling
upsertPR, add fast-fail validation of inputs: if prArgs.head != "" validate the
head value format (e.g., non-empty and matches expected "user:branch" or
"owner/branch" pattern) and return a clear error if malformed; otherwise (when
prArgs.head == "") ensure a token path is provided (e.g., prArgs.tokenPath is
non-empty) and return an error if missing. Place these checks immediately before
the existing conditional that calls o.upsertPR(org, repo, branch, prTitle,
prArgs) so invalid inputs are rejected early.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 27, 2026

@jmguzik: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/checkconfig d2b6d11 link true /test checkconfig
ci/prow/frontend-checks d2b6d11 link true /test frontend-checks
ci/prow/integration d2b6d11 link true /test integration
ci/prow/breaking-changes d2b6d11 link false /test breaking-changes

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants