func createReleasePR()

in tools/eksDistroBuildToolingOpsTools/pkg/eksGoRelease/githubRelease.go [324:377]


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
	}
	retrier := retrier.New(time.Second*380, retrier.WithBackoffFactor(1.5), retrier.WithMaxRetries(15, time.Second*30))

	githubClient, err := github.NewClient(ctx, ghUser.Token())
	if err != nil {
		return fmt.Errorf("setting up Github client: %v", err)
	}

	// Commit files
	// set up PR Creator handler
	prmOpts := &prManager.Opts{
		SourceOwner: ghUser.User(),
		SourceRepo:  constants.EksdBuildToolingRepoName,
		PrRepo:      constants.EksdBuildToolingRepoName,
		PrRepoOwner: constants.AwsOrgName,
	}
	prm := prManager.New(retrier, githubClient, prmOpts)

	prOpts := &prManager.CreatePrOpts{
		CommitBranch:  commitBranch,
		BaseBranch:    "main",
		AuthorName:    ghUser.User(),
		AuthorEmail:   ghUser.Email(),
		PrSubject:     prSubject,
		PrBranch:      "main",
		PrDescription: prDescription,
	}

	if err := gClient.Commit(commitMsg); err != nil {
		logger.Error(err, "git commit", "message", commitMsg)
		return err
	}

	// Push to forked repository
	if err := gClient.Push(ctx); err != nil {
		logger.Error(err, "git push")
		return err
	}

	prUrl, err := prm.CreatePr(ctx, prOpts)
	if err != nil {
		// This shouldn't be an breaking error at this point the PR is not open but the changes
		// have been pushed and can be created manually.
		logger.Error(err, "github client create pr failed. Create PR manually from github webclient", "create pr opts", prOpts)
		prUrl = ""
	}

	logger.V(3).Info("Update EKS Go Version", "EKS Go Version", r.EksGoReleaseVersion(), "PR", prUrl)
	return nil
}