-
Notifications
You must be signed in to change notification settings - Fork 27
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
Release charts push #468
Release charts push #468
Conversation
08ba503
to
bafa827
Compare
bafa827
to
f7eb14d
Compare
d8e0d9a
to
1c5c6fb
Compare
1c5c6fb
to
113b2d1
Compare
e4fa45f
to
a3658ad
Compare
cmd/release/cmd/push.go
Outdated
|
||
"github.com/google/go-github/v39/github" | ||
"github.com/spf13/cobra" | ||
|
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.
Remove this line. Imports should only be in 2 groups; stdlib and third party.
cmd/release/cmd/push.go
Outdated
releaseBranch string // given release branch | ||
|
||
ctx context.Context // background context | ||
t string // token |
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.
Can we rename this variable token
?
cmd/release/cmd/push.go
Outdated
var ( | ||
releaseBranch string // given release branch | ||
|
||
ctx context.Context // background context |
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.
This doesn't need to be declared here. Can be used below.
cmd/release/cmd/push.go
Outdated
|
||
ctx context.Context // background context | ||
t string // token | ||
ghc *github.Client // github client |
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.
This also doesn't need a declaration. Can be used from the assignment below.
exec/exec.go
Outdated
// UserInput will ask for user input with a given title | ||
func UserInput(title string) bool { | ||
var input string | ||
var err 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.
Let's remove this declaration.
repository/repository.go
Outdated
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/go-git/go-git/v5" | ||
"github.com/go-git/go-git/v5/config" | ||
"github.com/go-git/go-git/v5/plumbing" | ||
"github.com/go-git/go-git/v5/plumbing/object" | ||
"github.com/go-git/go-git/v5/plumbing/transport/http" | ||
|
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.
Remove empty lines and reformat.
repository/repository.go
Outdated
@@ -470,3 +476,169 @@ To find more information on specific steps, please see documentation [here](http | |||
- [ ] QA: Final validation of above PR and tracked through the linked ticket | |||
- [ ] PJM: Close the milestone in GitHub. | |||
` | |||
|
|||
// GetUpstreamRemote will return the remote name for a given configured remote URL | |||
func GetUpstreamRemote(r *git.Repository, rURL 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.
Let's remove "Get" from this function and call it "UpstramRemote". "Get" is a smell in Go.
repository/repository.go
Outdated
} | ||
|
||
// getCommits returns the commits beginning at the given hash | ||
func getCommits(r *git.Repository, h plumbing.Hash) ([]*object.Commit, 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.
Same as previous "get" comment.
|
||
limit := 100 | ||
count := 0 | ||
err = iter.ForEach(func(c *object.Commit) 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.
This error should be checked for nil first and then check for a certain kind of error.
repository/repository.go
Outdated
err = nil // Reset error if it was forced by the limit | ||
} | ||
|
||
return commits, err |
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.
Let's return nil here for the error explicitly if there is not error.
release/charts/chart_management.go
Outdated
@@ -21,15 +21,20 @@ type asset struct { | |||
|
|||
// ChartArgs will return the list of available charts in the current branch | |||
func ChartArgs(ctx context.Context, c *config.ChartsRelease) ([]string, error) { | |||
assets := filepath.Join(c.Workspace, "assets") | |||
var ( | |||
assets string |
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.
None of these appear to be needed to be pre declared.
release/charts/charts.go
Outdated
) | ||
|
||
// body is the default PR body for the charts release PR | ||
const body string = ` |
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.
Let's rename this chartsReleasePRBody
release/charts/charts.go
Outdated
// - b: release branch name. | ||
// - t: token from github. | ||
// - d: debug mode. | ||
func Push(ctx context.Context, c *config.ChartsRelease, u *config.User, ghc *github.Client, b, t string, d bool) (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.
Please name the argument variables with names that indicate what they're used for and then you can remove the description for them above.
release/charts/charts.go
Outdated
|
||
// create a new PR | ||
pr := &github.NewPullRequest{ | ||
Title: github.String(fmt.Sprintf("[%s] batch release", b)), |
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.
Please concatenate the strings rather than using the sprintf function.
release/charts/charts.go
Outdated
@@ -93,3 +190,47 @@ func runChartsBuild(chartsRepoPath string, args ...string) ([]byte, error) { | |||
|
|||
return output, nil | |||
} | |||
|
|||
// debugPullRequest will prompt the user to check the files and commits that will be pushed to the remote repository | |||
func debugPullRequest(r *git.Repository, remote, b 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.
Please rename the b variable to be descriptive of what it is. In Go, using a single character symbol is fine when the context of the variable is easily derived and the variable is used close to its initialization.
repository/repository.go
Outdated
@@ -470,3 +476,169 @@ To find more information on specific steps, please see documentation [here](http | |||
- [ ] QA: Final validation of above PR and tracked through the linked ticket | |||
- [ ] PJM: Close the milestone in GitHub. | |||
` | |||
|
|||
// GetUpstreamRemote will return the remote name for a given configured remote URL | |||
func GetUpstreamRemote(r *git.Repository, rURL 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.
Please rename rURL to remoteURL.
cmd/release/cmd/push.go
Outdated
|
||
var ( | ||
releaseBranch string | ||
found bool |
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.
This variable doesn't need to be declared or even used below. The function call be be directly in the if
statement.
cmd/release/cmd/push.go
Outdated
return err | ||
} | ||
|
||
fmt.Printf("Pull request created: %s\n", prURL) |
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.
Please concatenate this string rather than using the printf function.
a3da91e
to
16b2c2c
Compare
repository/repository.go
Outdated
// DiffLocalToRemote will get the commits from the local branch and from the target remote branch, | ||
// will return the commits that are present in the local branch but not in the remote branch. | ||
func DiffLocalToRemote(r *git.Repository, remote, releaseBranch string) error { | ||
var ( |
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.
It doesn't appear as though any of these variables need to be defined here.
repository/repository.go
Outdated
|
||
// findUniqueCommits returns the commits that are in the first reference but not in the second. | ||
func findUniqueCommits(r *git.Repository, localRef, remoteRef *plumbing.Reference) ([]*object.Commit, error) { | ||
var ( |
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.
These variables don't need to be defined.
16b2c2c
to
3668c03
Compare
Issue:
#447
Solution:
After: #464
This command (
release push charts <some_release_branch>
),will push the changes on the local branch,
and create a Pull Request against the given release branch.
Debug mode
Since it is a critical operation,
I implemented the debug mode which will guide the user on:
Result example:
Without debug mode, this is an example PR created: rancher/charts#4333
The debug mode is too verbose to print here.