-
Notifications
You must be signed in to change notification settings - Fork 505
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
Implement clone, commit and push of release notes draft to user's fork #1102
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@puerco -- I've made some suggestions.
Please also squash down these commits.
Each commit should be logically organized with a commit message you'd be okay with showing up in our git history.
cmd/krel/cmd/release_notes.go
Outdated
|
||
// createDraftPR pushes the release notes draft to the users fork | ||
func createDraftPR(tag string, result *releaseNotesResult) error { | ||
repoparts := strings.Split(releaseNotesOpts.sigReleaseFork, "/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we should probably add the validatePROptions()
check here instead.
repoparts
becomes unnecessary if the flags get split as suggested above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose to call validatePROptions()
before generating the notes. i wanted to avoid running the release notes gatherer (which is very expensive timewise) if the PR was going to fail anyway.
cmd/krel/cmd/release_notes.go
Outdated
targetdir := srrepo.Dir() + fmt.Sprintf("/releases/release-%d.%d", s.Major, s.Minor) | ||
logrus.Debugf("Release notes markdown will be written to %s", targetdir) | ||
|
||
// Ugly hack to match repo.Checkout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the ugly hack necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Commit() function arguments takes a revision and arguments (Checkout(rev string, args ...string)) . I need to pass -b to git but if i send it in the arguments it appends it at the end and it breaks.
cmd/krel/cmd/release_notes.go
Outdated
} | ||
|
||
logrus.Infof("Pushing release notes draft to %s", releaseNotesOpts.sigReleaseFork) | ||
err = ioutil.WriteFile(targetdir+"/release-notes-draft.md", []byte(result.markdown), 0644) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
targetdir
can probably become the releaseNotesOpts.outputDir
suggested above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, do you mean overriding the default location in the repo with --output-dir if defined ?
pkg/git/git.go
Outdated
@@ -658,6 +658,17 @@ func (r *Repo) Add(filename string) error { | |||
return nil | |||
} | |||
|
|||
// CommitAll Commit all changes using git command | |||
func (r *Repo) CommitAll(msg string) ([]string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason Commit()
doesn't suit our needs here?
If it's the Author
field, you can push those values into consts instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I resolved this to Add()ing only the release notes files. The reason I was adding a new function was because the Commit functions does not take arguments besides the message.
Thanks @justaugustus for such detailed guidance, changes are comming right up. |
~~ Due to rebase issues I'm scraping this PR in favour of PR #1110 which includes all your suggestions. I'm still addressing the comments here. ~~ Scratch that. Gentleman extraordinaire @JamesLaverack helped me get this in order. |
if err != nil { | ||
return errors.Wrap(err, "Failed to create release notes draft PR") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If releaseNotesOpts.createDraftPR
is false, because --create-draft-pr
was not given, should we log out to say we're skipping it and why? Might help users understand why it's not working if they missed that flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if do not specify an output option for the release notes we could print out the help screen. There are and will be more options in addition to --create-draft-pr in the subcommand. For example just writing the release notes to files or generating the json version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some comments from my side 👍
cmd/krel/cmd/release_notes.go
Outdated
branchname := "release-notes-draft-" + tag | ||
|
||
// checkout kubernetes/sig-release | ||
sigReleaseRepo, err := git.CloneOrOpenGitHubRepo("", "kubernetes", "sig-release", true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should take the repo path from the options. And use git.DefaultGithubOrg
for the org. For the repo we could define a new variable in the git package, like DefaultGithubReleaseRepo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I;ve added a new option to determine the path: sigrelease-fork-path
it defaults to os.TempDir(), "k8s-sigrelease". Maybe we can come up with a better name for the flag?
Thanks for your comments @saschagrunert I love the attention you give to these kinds of details in your code. I think I've addressed all of your remarks I'll run a new test in a bit (i've run out of my API quota for the next hour). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM, let's iterate on this
/lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
Thanks for the hard work @puerco 💚
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: puerco, saschagrunert 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 |
What type of PR is this?
/kind feature
What this PR does / why we need it:
This is the first (partial) implementation of the release notes PR automation we have been discussing mainly in #1061 . Specifically, this PR adds a new option (--create-draft-pr) to the krel release-notes subcommand that, when enabled, will generate the release notes draft to a user's fork of k/sig-release. The user's fork must be determined using the --draft-org and --draft-repo flags
I also added a new option (-o|--output-dir) to output the release notes in markdown and json to a directory, mainly for testing purposes.
Which issue(s) this PR fixes:
Relates to #1061
Special notes for your reviewer:
This PR stops short of talking to GitHub and creating the PR. I wanted to touch base first and see if this is going in the right direction.
I added two new functions to pkg/go.git, one to add a remote (Repo.AddRemote(name, owner, repo string)) and another to push to a specific branch (Repo.PushToRemote())
Does this PR introduce a user-facing change?:
/cc @saschagrunert @JamesLaverack @evillgenius75