Skip to content
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

Merged
merged 1 commit into from
Feb 21, 2020

Conversation

puerco
Copy link
Member

@puerco puerco commented Feb 16, 2020

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?:

Add --create-draft-pr --draft-org and --draft-repo flags to automate the creation of the release notes draft
Add --output-dir to output a copy of the release notes.

/cc @saschagrunert @JamesLaverack @evillgenius75

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Feb 16, 2020
@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/release-eng Issues or PRs related to the Release Engineering subproject sig/release Categorizes an issue or PR as relevant to SIG Release. labels Feb 16, 2020
Copy link
Member

@justaugustus justaugustus left a 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.


// createDraftPR pushes the release notes draft to the users fork
func createDraftPR(tag string, result *releaseNotesResult) error {
repoparts := strings.Split(releaseNotesOpts.sigReleaseFork, "/")
Copy link
Member

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.

Copy link
Member Author

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.

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
Copy link
Member

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?

Copy link
Member Author

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.

}

logrus.Infof("Pushing release notes draft to %s", releaseNotesOpts.sigReleaseFork)
err = ioutil.WriteFile(targetdir+"/release-notes-draft.md", []byte(result.markdown), 0644)
Copy link
Member

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.

Copy link
Member Author

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) {
Copy link
Member

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.

Copy link
Member Author

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.

@puerco
Copy link
Member Author

puerco commented Feb 17, 2020

Thanks @justaugustus for such detailed guidance, changes are comming right up.

@puerco
Copy link
Member Author

puerco commented Feb 18, 2020

~~ 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.

@puerco puerco closed this Feb 18, 2020
@puerco puerco reopened this Feb 19, 2020
@puerco puerco closed this Feb 19, 2020
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 19, 2020
@puerco puerco reopened this Feb 19, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 19, 2020
if err != nil {
return errors.Wrap(err, "Failed to create release notes draft PR")
}
}
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@saschagrunert saschagrunert left a 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 👍

branchname := "release-notes-draft-" + tag

// checkout kubernetes/sig-release
sigReleaseRepo, err := git.CloneOrOpenGitHubRepo("", "kubernetes", "sig-release", true)
Copy link
Member

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

Copy link
Member Author

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?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 20, 2020
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 20, 2020
@puerco
Copy link
Member Author

puerco commented Feb 20, 2020

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).

Copy link
Member

@saschagrunert saschagrunert left a 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

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 21, 2020
Copy link
Member

@saschagrunert saschagrunert left a 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 💚

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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. area/release-eng Issues or PRs related to the Release Engineering subproject cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/release Categorizes an issue or PR as relevant to SIG Release. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants