Skip to content

Commit 47c2f5e

Browse files
committed
Automate PR creation for updates to the Release Notes draft
1 parent 7639dde commit 47c2f5e

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

cmd/krel/cmd/release_notes.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,39 @@ func createDraftPR(tag string, result *releaseNotesResult) (err error) {
447447
return errors.Wrapf(err, "pushing %v to remote", userForkName)
448448
}
449449

450-
// TODO: Call github API and create PR against k/sig-release
450+
// Create a PR against k/sig-release using the github API
451+
gh := github.New()
452+
453+
// TODO: Maybe read and parse the PR template from sig-release?
454+
prBody := fmt.Sprintln(
455+
"**What type of PR is this?**",
456+
"/kind documentation",
457+
"**What this PR does / why we need it**:",
458+
fmt.Sprintf("This PR updates the release notes draft to k/k %s", tag),
459+
"**Which issue(s) this PR fixes**:",
460+
"**Special notes for your reviewer**:",
461+
"This is an automated PR generated from `krel The Kubernetes Release Toolbox`",
462+
)
463+
464+
// Create the pull request
465+
logrus.Debugf(
466+
"PR params: org: %s, repo: %s, headBranch: %s baseBranch: %s",
467+
defaultKubernetesSigReleaseOrg, defaultKubernetesSigReleaseRepo, "master",
468+
fmt.Sprintf("%s:%s", releaseNotesOpts.draftOrg, branchname),
469+
)
470+
pr, err := gh.CreatePullRequest(
471+
defaultKubernetesSigReleaseOrg, defaultKubernetesSigReleaseRepo, "master",
472+
fmt.Sprintf("%s:%s", releaseNotesOpts.draftOrg, branchname),
473+
fmt.Sprintf("Update release notes draft to version %s", tag), prBody,
474+
)
475+
476+
if err != nil {
477+
logrus.Warnf("An error has occurred while creating the pull request for %s", tag)
478+
logrus.Warn("While the PR failed, the release notes draft was generated and submitted to your fork")
479+
return errors.Wrap(err, "creating the pull request")
480+
}
481+
482+
logrus.Infof("Successfully created PR #%d", pr.GetNumber())
451483
return nil
452484
}
453485

@@ -629,7 +661,7 @@ func createWebsitePR(tag, jsonStr string) (err error) {
629661
)
630662

631663
if err != nil {
632-
logrus.Warnf("An error ocurred while creating the pull request for %s", tag)
664+
logrus.Warnf("An error has occurred while creating the pull request for %s", tag)
633665
logrus.Warn("While the PR failed, the release notes where generated and submitted to your fork")
634666
return errors.Wrap(err, "creating the pull request")
635667
}

0 commit comments

Comments
 (0)