func()

in tools/eksDistroBuildToolingOpsTools/pkg/prManager/prManager.go [76:110]


func (p *PrCreator) pushCommit(ctx context.Context, ref *gogithub.Reference, tree *gogithub.Tree, authorName string, authorEmail string, commitMessage string) (err error) {
	// Get the parent commit to attach the commit to.
	parent, _, err := p.client.Repositories.GetCommit(ctx, p.sourceOwner, p.sourceRepo, *ref.Object.SHA, nil)
	if err != nil {
		return err
	}
	// This is not always populated, but is needed.
	parent.Commit.SHA = parent.SHA

	// Create the commit using the tree.
	date := time.Now()
	author := &gogithub.CommitAuthor{
		Date:  &date,
		Name:  &authorName,
		Email: &authorEmail,
	}

	commit := &gogithub.Commit{
		Author:  author,
		Message: &commitMessage,
		Tree:    tree,
		Parents: []*gogithub.Commit{
			parent.Commit,
		},
	}
	newCommit, _, err := p.client.Git.CreateCommit(ctx, p.sourceOwner, p.sourceRepo, commit)
	if err != nil {
		return err
	}

	// Attach the commit to the master branch.
	ref.Object.SHA = newCommit.SHA
	_, _, err = p.client.Git.UpdateRef(ctx, p.sourceOwner, p.sourceRepo, ref, false)
	return err
}