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

Add commitBranch variable to avoid duplicate prs #1248

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func BackportToRelease(ctx context.Context, r *Release, dryrun bool, cve, commit
}

// Create new branch
if err := gClient.Branch(r.EksGoReleaseVersion()); err != nil {
commitBranch := r.EksGoReleaseVersion()
if err := gClient.Branch(commitBranch); err != nil {
logger.Error(err, "git branch", "branch name", r.EksGoReleaseVersion(), "repo", forkUrl, "client", gClient)
return err
}
Expand Down Expand Up @@ -72,7 +73,7 @@ func BackportToRelease(ctx context.Context, r *Release, dryrun bool, cve, commit
// no longer update gospec with patch file since no patch was created
if !dryrun {
prFailureDescription := fmt.Sprintf(backportPRDescriptionFailureFmt, cve, r.EksGoReleaseVersion(), commit)
if err := createReleasePR(ctx, dryrun, r, ghUser, gClient, prSubject, prFailureDescription, commitMsg); err != nil {
if err := createReleasePR(ctx, dryrun, r, ghUser, gClient, prSubject, prFailureDescription, commitMsg, commitBranch); err != nil {
logger.Error(err, "Create Release PR")
return err
}
Expand All @@ -81,7 +82,7 @@ func BackportToRelease(ctx context.Context, r *Release, dryrun bool, cve, commit

if !dryrun {
prSuccessDescription := fmt.Sprintf(backportPRDescriptionSuccessFmt, cve, commit, r.EksGoReleaseVersion())
if err := createReleasePR(ctx, dryrun, r, ghUser, gClient, prSubject, prSuccessDescription, commitMsg); err != nil {
if err := createReleasePR(ctx, dryrun, r, ghUser, gClient, prSubject, prSuccessDescription, commitMsg, commitBranch); err != nil {
logger.Error(err, "Create Release PR")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func addTempFilesForNewMinorVersion(gClient git.Client, r *Release) error {
return nil
}

func createReleasePR(ctx context.Context, dryrun bool, r *Release, ghUser github.GitHubUser, gClient git.Client, prSubject, prDescription, commitMsg string) error {
func createReleasePR(ctx context.Context, dryrun bool, r *Release, ghUser github.GitHubUser, gClient git.Client, prSubject, prDescription, commitMsg, commitBranch string) error {
if dryrun {
logger.V(3).Info("running in dryrun mode no pr created")
return nil
Expand All @@ -334,7 +334,7 @@ func createReleasePR(ctx context.Context, dryrun bool, r *Release, ghUser github
prm := prManager.New(retrier, githubClient, prmOpts)

prOpts := &prManager.CreatePrOpts{
CommitBranch: r.EksGoReleaseVersion(),
CommitBranch: commitBranch,
BaseBranch: "main",
AuthorName: ghUser.User(),
AuthorEmail: ghUser.Email(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func NewMinorRelease(ctx context.Context, r *Release, dryrun bool, email, user s
}

// Create new branch
if err := gClient.Branch(r.EksGoReleaseVersion()); err != nil {
commitBranch := r.EksGoReleaseVersion()
if err := gClient.Branch(commitBranch); err != nil {
logger.Error(err, "git branch", "branch name", r.EksGoReleaseVersion(), "repo", forkUrl, "client", gClient)
return err
}
Expand Down Expand Up @@ -67,7 +68,7 @@ func NewMinorRelease(ctx context.Context, r *Release, dryrun bool, email, user s
prSubject := fmt.Sprintf(newMinorVersionPRSubjectFmt, r.GoSemver())
prDescription := fmt.Sprintf(newMinorVersionPRDescriptionFmt, r.EksGoReleaseVersion())
commitMsg := fmt.Sprintf(newMinorVersionCommitMsgFmt, r.GoSemver())
if err := createReleasePR(ctx, dryrun, r, ghUser, gClient, prSubject, prDescription, commitMsg); err != nil {
if err := createReleasePR(ctx, dryrun, r, ghUser, gClient, prSubject, prDescription, commitMsg, commitBranch); err != nil {
logger.Error(err, "Create Release PR")
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func ReleaseArtifacts(ctx context.Context, r *Release, dryrun bool, email, user
}

// Create new branch
if err := gClient.Branch(fmt.Sprintf("release-%s", r.GoMinorVersion())); err != nil {
commitBranch := fmt.Sprintf("release-%s", r.GoMinorVersion())
if err := gClient.Branch(commitBranch); err != nil {
logger.Error(err, "git branch", "branch name", r.GoMinorVersion(), "repo", forkUrl, "client", gClient)
return err
}
Expand All @@ -58,7 +59,7 @@ func ReleaseArtifacts(ctx context.Context, r *Release, dryrun bool, email, user
prSubject := fmt.Sprintf(releasePRSubjectFmt, r.EksGoReleaseVersion())
prDescription := fmt.Sprintf(releasePRDescriptionFmt, r.EksGoReleaseVersion())
commitMsg := fmt.Sprintf(releasePRCommitFmt, r.EksGoReleaseVersion())
if err := createReleasePR(ctx, dryrun, r, ghUser, gClient, prSubject, prDescription, commitMsg); err != nil {
if err := createReleasePR(ctx, dryrun, r, ghUser, gClient, prSubject, prDescription, commitMsg, commitBranch); err != nil {
logger.Error(err, "Create Release PR")
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func UpdateVersion(ctx context.Context, r *Release, dryrun bool, email, user str
}

// Create new branch
if err := gClient.Branch(r.EksGoReleaseVersion()); err != nil {
commitBranch := r.EksGoReleaseVersion()
if err := gClient.Branch(commitBranch); err != nil {
logger.Error(err, "git branch", "branch name", r.EksGoReleaseVersion(), "repo", forkUrl, "client", gClient)
return err
}
Expand All @@ -70,7 +71,7 @@ func UpdateVersion(ctx context.Context, r *Release, dryrun bool, email, user str
prSubject := fmt.Sprintf(updatePRSubjectFmt, r.GoSemver())
prDescription := fmt.Sprintf(updatePRDescriptionFmt, r.EksGoReleaseVersion())
commitMsg := fmt.Sprintf(updatePRCommitFmt, r.GoSemver())
if err := createReleasePR(ctx, dryrun, r, ghUser, gClient, prSubject, prDescription, commitMsg); err != nil {
if err := createReleasePR(ctx, dryrun, r, ghUser, gClient, prSubject, prDescription, commitMsg, commitBranch); err != nil {
logger.Error(err, "Create Release PR")
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,19 @@ func (p *PrCreator) CreatePr(ctx context.Context, opts *CreatePrOpts) (string, e
if opts.CommitMessage != "" {
ref, err := p.getRef(ctx, opts.CommitBranch, opts.BaseBranch)
if err != nil {
return "", fmt.Errorf("creating pull request: get/create the commit reference: %s\n", err)
return "", fmt.Errorf("creating pull request: get/create the commit reference: %s", err)
}
if ref == nil {
return "", fmt.Errorf("creating pull request: the reference is nil")
}

tree, err := p.getTree(ctx, ref, opts.SourceFileBody, opts.DestFileGitPath)
if err != nil {
return "", fmt.Errorf("creating the tree based on the provided files: %s\n", err)
return "", fmt.Errorf("creating the tree based on the provided files: %s", err)
}

if err := p.pushCommit(ctx, ref, tree, opts.AuthorName, opts.AuthorEmail, opts.CommitMessage); err != nil {
return "", fmt.Errorf("creating the commit: %s\n", err)
return "", fmt.Errorf("creating the commit: %s", err)
}
}

Expand Down
Loading