Skip to content

Add nil guard to publisher.Commit and set GitUser in GithubOptions.GitClientFactory - #801

Open
StarMiner99 wants to merge 2 commits into
kubernetes-sigs:mainfrom
StarMiner99:main
Open

Add nil guard to publisher.Commit and set GitUser in GithubOptions.GitClientFactory#801
StarMiner99 wants to merge 2 commits into
kubernetes-sigs:mainfrom
StarMiner99:main

Conversation

@StarMiner99

Copy link
Copy Markdown

as described in #800 here is a proposed modification that would close #800.

What does this pr do?

  • Adds a nil guard to pkg/git/v2/publisher.go publisher.Commit: p.info previously was directly called, if GitUser was not set p.info would be nil and a nil pointer dereference panic occured. I inserted a nil guard.
  • in pkg/flagutil/github.go: now also sets the GitUser when using the GitClientFactory, username is the same as opts.Username and the email is left empty.

@netlify

netlify Bot commented Jul 15, 2026

Copy link
Copy Markdown

Deploy Preview for k8s-prow ready!

Name Link
🔨 Latest commit b8eface
🔍 Latest deploy log https://app.netlify.com/projects/k8s-prow/deploys/6a577a6156addf0008c66d73
😎 Deploy Preview https://deploy-preview-801--k8s-prow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: StarMiner99
Once this PR has been reviewed and has the lgtm label, please assign cjwagner for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@kubernetes-prow
kubernetes-prow Bot requested review from Prucek and cjwagner July 15, 2026 12:17
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 15, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @StarMiner99!

It looks like this is your first PR to kubernetes-sigs/prow 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/prow has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 15, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @StarMiner99. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@kubernetes-prow kubernetes-prow Bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 15, 2026
@kubernetes-prow kubernetes-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 26, 2026
@ylink-lfs

Copy link
Copy Markdown
Contributor

Several improvement ideas:

  • Expect to add tests in pkg/git/v2/publisher_test.go for the new behavior.
  • Current the returned error doesn't explain the remedy for developers.
  • Authentication and commit identity are separated, but the current changes inherit the authentication identity for commit.
  • The field validation logic should follow prow's convention, not git's minimal requirement. See
    func validateOptions(o *Options) error {
    if !o.SkipPullRequest && o.Gerrit == nil {
    mode := o.resolvedPRSourceMode()
    switch mode {
    case "branch":
    if o.GitHubOptions == nil || o.GitHubOptions.AppID == "" {
    return fmt.Errorf("--pr-source-mode=branch requires --github-app-id and --github-app-private-key-path")
    }
    if err := o.GitHubOptions.Validate(false); err != nil {
    return fmt.Errorf("invalid GitHub options: %w", err)
    }
    case "fork":
    if o.GitHubToken == "" {
    return fmt.Errorf("gitHubToken is mandatory when skipPullRequest is false or unspecified")
    }
    if o.RemoteName == "" {
    return fmt.Errorf("remoteName is mandatory when skipPullRequest is false or unspecified")
    }
    default:
    return fmt.Errorf("invalid pr-source-mode %q, expected one of: fork, branch", mode)
    }
    if (o.GitEmail == "") != (o.GitName == "") {
    return fmt.Errorf("gitName and gitEmail must be specified together")
    }

@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. and removed ok-to-test Indicates a non-member PR verified by an org member that is safe to test. labels Jul 26, 2026
Comment thread pkg/git/v2/publisher.go
func (p *publisher) Commit(title, body string) error {
p.logger.Infof("Committing changes with title %q", title)
if p.info == nil {
return fmt.Errorf("error committing %q: GitUser is not set", title)

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.

Current the returned error doesn't explain the remedy for developers.

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

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

publisher.Commit panics (nil pointer) when GitUser is unset, and GitHubOptions.GitClientFactory can't set it

2 participants