Skip to content

✨ alpha(update): add --open-gh-issue flag #5009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

vitorfloriano
Copy link
Contributor

@vitorfloriano vitorfloriano commented Aug 13, 2025

Summary

This PR introduces the --open-gh-issue flag, which enhances the kubebuilder alpha update command with automated GitHub integration and intelligent conflict warning system, making it ready for automated update workflows using GitHub Actions while informing users when manual intervention is needed.

Use Case

When used with GitHub Actions, --open-gh-issue will:

  1. Perform an update using a 3-way merge.
  2. Create a branch to commit the result.
  3. Create an issue to notify about the update, with a link to create a PR.

Issue Template

There's a new scaffold available for update!

Check out what's new in Kubebuilder v4.7.1 Release Notes.

What to do?

To make your life easier, Kubebuilder has updated your project scaffold from v4.6.0 to v4.7.1 on the kubebuilder-alpha-update-from-v4.6.0-to-v4.7.1 branch.

You can create a Pull Request with the changes using the link below:

https://github.com/vitorfloriano/test-operator/pull/new/kubebuilder-alpha-update-from-v4.6.0-to-v4.7.1

ATTENTION: This update was performed by automation. Always review and test your code before merging the changes.

HINT: You can learn more ways to automate updates in the alpha update documentation.

WARNING: Conflict markers were committed to make this automation possible. You should resolve the conflicts before anything.

Idempotency

--open-gh-issue validates if a branch for the same update already exists before pushing anything, which avoids overwritting existing work that may have been started on the update branch.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 13, 2025
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 13, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @vitorfloriano. 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.

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.

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Aug 13, 2025
@camilamacedo86
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot 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 Aug 13, 2025
@vitorfloriano vitorfloriano changed the title ✨ alpha(update): add --open-pr and --open-issue flags ✨ alpha(update): add --open-gh-pr and --open-gh-issue flags Aug 13, 2025
@vitorfloriano vitorfloriano force-pushed the alpha-update-open-pr-issue branch 2 times, most recently from 8c465c1 to cd1c376 Compare August 14, 2025 04:32
@vitorfloriano vitorfloriano changed the title ✨ alpha(update): add --open-gh-pr and --open-gh-issue flags ✨ alpha(update): add --open-gh-issue flag Aug 14, 2025
@vitorfloriano vitorfloriano force-pushed the alpha-update-open-pr-issue branch from cd1c376 to 1d52e1c Compare August 14, 2025 11:48
@vitorfloriano vitorfloriano force-pushed the alpha-update-open-pr-issue branch from 1d52e1c to 0d280e3 Compare August 14, 2025 11:54

// GitHub integration
if opts.OpenIssue {
// Configure git identity for GitHub integration commits
Copy link
Member

Choose a reason for hiding this comment

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

Currently, we just push the branch if we’re in createIssue.
We need to add a check here:

  • Check: Do we already have a branch in the repo with outBranchName pushed?
  • If yes: Stop the process and show a warning.

The process should end before creating the issue or updating the branch, since we found an existing branch. This is to preserve the existing code and avoid overwriting work. We also won’t open another issue, as it’s likely the task has already been completed.

⚠️ Branch {outBranchName} already exists in the repository.
Skipping issue creation and branch update to preserve existing work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

createIssue calls pushBranchToRemote, which then calls checkRemoteBranchExists to check that.

If the branch already exists, it logs:

"Remote branch already exists, skipping push to avoid overwriting existing work"

Then we skip issue creation and log:

"Branch was not pushed (already exists), skipping issue creation"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@camilamacedo86 I did another test just for sanity: https://github.com/vitorfloriano/test-operator/actions/runs/16966361349/job/48091252772#step:5:161

INFO Remote branch already exists, skipping push to avoid overwriting existing work branch=kubebuilder-alpha-update-from-v4.6.0-to-v4.7.1
INFO Branch was not pushed (already exists), skipping issue creation branch=kubebuilder-alpha-update-from-v4.6.0-to-v4.7.1

The branch was not pushed and did not overwrite the existent one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But looking at the code again, we could reorder the checks so this message would be shown regardless of whether the issue already existed or the branch already existed. 🤔

Copy link
Member

Choose a reason for hiding this comment

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

INFO Branch was not pushed (already exists), skipping issue creation branch=kubebuilder-alpha-update-from-v4.6.0-to-v4.7.1

The second one can be only from skipping

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@camilamacedo86 , I improved the logic and logging to behave as follows:

Case 1: Both branch & issue exist (most common re-run)

Scenario: User runs the command again after everything was already created

INFO Remote branch already exists. Branch was not pushed to avoid overwriting existing work
INFO Issue for update already exists. Nothing to do here. from=v4.5.0 to=v4.6.0

Case 2: Branch exists, no issue (issue was deleted/never created)

Scenario: Branch was created before but issue creation failed or was manually deleted

INFO Remote branch already exists. Branch was not pushed to avoid overwriting existing work
INFO Creating issue for existing branch branch=kubebuilder-alpha-update-from-v4.5.0-to-v4.6.0

(issue creation proceeds normally)

Case 3: Branch doesn't exist, issue exists (branch was deleted/failed to push)

Scenario: Issue exists but branch was manually deleted or push failed previously
(pushBranchToRemote logs from successful push operation)
INFO Branch was created but issue already exists for this update branch=kubebuilder-alpha-update-from-v4.5.0-to-v4.6.0

WDYT?

- Add --open-gh-issue flag for automated Issue creation on GitHub
- Include conflict warning in Issue body
- Add comprehensive test coverage and documentation
@vitorfloriano vitorfloriano force-pushed the alpha-update-open-pr-issue branch from 0d280e3 to 7a31b3c Compare August 14, 2025 12:55
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm
/approved

Let's move forward, to facilitate the progress and we can refine in follow-up if we need. !
Great work 🎉

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 14, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, vitorfloriano

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

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 14, 2025
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 15, 2025
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/hold

I think in a way to simplify it.
I will try to do it today

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 15, 2025
@vitorfloriano
Copy link
Contributor Author

Closed in favor of #5018.

@vitorfloriano vitorfloriano deleted the alpha-update-open-pr-issue branch August 19, 2025 14:28
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants