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

Release charts push #468

Merged
merged 13 commits into from
Aug 26, 2024
Merged

Conversation

nicholasSUSE
Copy link
Contributor

@nicholasSUSE nicholasSUSE commented Aug 9, 2024

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:

  • inspecting the commits that will be pushed.
  • inspecting the files that will be pushed.

Result example:

Without debug mode, this is an example PR created: rancher/charts#4333

The debug mode is too verbose to print here.

@nicholasSUSE nicholasSUSE marked this pull request as ready for review August 9, 2024 20:54
@nicholasSUSE nicholasSUSE force-pushed the release-charts-push branch 4 times, most recently from 08ba503 to bafa827 Compare August 10, 2024 15:28
cmd/release/cmd/push.go Outdated Show resolved Hide resolved
repository/repository.go Outdated Show resolved Hide resolved
release/charts/charts.go Outdated Show resolved Hide resolved
repository/repository.go Outdated Show resolved Hide resolved

"github.com/google/go-github/v39/github"
"github.com/spf13/cobra"

Copy link
Member

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.

releaseBranch string // given release branch

ctx context.Context // background context
t string // token
Copy link
Member

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?

var (
releaseBranch string // given release branch

ctx context.Context // background context
Copy link
Member

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.


ctx context.Context // background context
t string // token
ghc *github.Client // github client
Copy link
Member

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

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.

"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"

Copy link
Member

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.

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

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.

}

// getCommits returns the commits beginning at the given hash
func getCommits(r *git.Repository, h plumbing.Hash) ([]*object.Commit, error) {
Copy link
Member

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

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.

err = nil // Reset error if it was forced by the limit
}

return commits, err
Copy link
Member

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.

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

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.

)

// body is the default PR body for the charts release PR
const body string = `
Copy link
Member

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

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

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.


// create a new PR
pr := &github.NewPullRequest{
Title: github.String(fmt.Sprintf("[%s] batch release", b)),
Copy link
Member

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.

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

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.

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

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.


var (
releaseBranch string
found bool
Copy link
Member

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.

return err
}

fmt.Printf("Pull request created: %s\n", prURL)
Copy link
Member

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.

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

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.


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

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.

@nicholasSUSE nicholasSUSE merged commit 6ccddb4 into rancher:master Aug 26, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants