Skip to content

Commit

Permalink
Merge pull request #2320 from palnabarun/krel/promote-images
Browse files Browse the repository at this point in the history
Minor improvements to krel promote-images
  • Loading branch information
k8s-ci-robot authored Nov 15, 2021
2 parents 9daadac + f032d32 commit d7b421d
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions cmd/krel/cmd/promote-images.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const (
k8sioRepo = "k8s.io"
k8sioDefaultBranch = "main"
promotionBranchSuffix = "-image-promotion"
defaultProject = release.Kubernetes
defaultReviewers = "@kubernetes/release-engineering"
)

// promoteCommand is the krel subcommand to promote conainer images
Expand Down Expand Up @@ -87,7 +89,7 @@ func (o *promoteOptions) Validate() error {
// Check that the GitHub token is set
token, isSet := os.LookupEnv(github.TokenEnvKey)
if !isSet || token == "" {
return errors.New("cannot promote images if GitHub token is not set")
return fmt.Errorf("cannot promote images if GitHub token env var %s is not set", github.TokenEnvKey)
}
return nil
}
Expand All @@ -98,7 +100,7 @@ func init() {
imagePromoteCommand.PersistentFlags().StringVar(
&promoteOpts.project,
"project",
release.Kubernetes,
defaultProject,
"the name of the project to promote images for",
)

Expand All @@ -120,7 +122,7 @@ func init() {
imagePromoteCommand.PersistentFlags().StringVar(
&promoteOpts.reviewers,
"reviewers",
"@kubernetes/release-engineering",
defaultReviewers,
"the list of GitHub users or teams to assign to the PR",
)

Expand Down Expand Up @@ -289,16 +291,12 @@ func runPromote(opts *promoteOptions) error {
return nil
}

prBody := fmt.Sprintf("Image promotion for %s %s\n", opts.project, strings.Join(opts.tags, " / "))
prBody += "This is an automated PR generated from `krel The Kubernetes Release Toolbox`\n\n"
prBody += fmt.Sprintf("/hold\ncc: %s\n", opts.reviewers)

// Create the Pull Request
if mustRun(opts, "Create pull request?") {
pr, err := gh.CreatePullRequest(
git.DefaultGithubOrg, k8sioRepo, k8sioDefaultBranch,
fmt.Sprintf("%s:%s", userForkOrg, branchname),
commitMessage, prBody,
commitMessage, generatePRBody(opts),
)
if err != nil {
return errors.Wrap(err, "creating the pull request in k/k8s.io")
Expand Down Expand Up @@ -331,3 +329,30 @@ func mustRun(opts *promoteOptions, question string) bool {
}
return false
}

// generatePRBody creates the body of the Image Promotion Pull Request
func generatePRBody(opts *promoteOptions) string {
args := fmt.Sprintf("--fork %s", opts.userFork)
if opts.interactiveMode {
args += " --interactive"
}

if opts.project != defaultProject {
args += " --project" + opts.project
}

if opts.reviewers != defaultReviewers {
args += " --reviewers" + opts.reviewers
}

for _, tag := range opts.tags {
args += " --tag " + tag
}

prBody := fmt.Sprintf("Image promotion for %s %s\n", opts.project, strings.Join(opts.tags, " / "))
prBody += "This is an automated PR generated from `krel The Kubernetes Release Toolbox`\n"
prBody += fmt.Sprintf("```\nkrel promote-images %s\n```\n\n", args)
prBody += fmt.Sprintf("/hold\ncc: %s\n", opts.reviewers)

return prBody
}

0 comments on commit d7b421d

Please sign in to comment.