Skip to content

Commit

Permalink
Fix: fetch merged commit for backporting
Browse files Browse the repository at this point in the history
This was missed in #313.
Without this change all backports will fail with a similar
`fatal: bad object c64253265b7cb675c7ca336c0454a65b7db4dd5d` error.
  • Loading branch information
rosstimothy committed Feb 4, 2025
1 parent ed99ff6 commit 45b4f99
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions bot/internal/bot/backport.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ import (
// Backport will create backport Pull Requests (if requested) when a Pull
// Request is merged.
func (b *Bot) Backport(ctx context.Context) error {
internal, err := b.isInternal(ctx)
if err != nil {
return trace.Wrap(err, "checking for internal author")
}
if !internal {
return trace.BadParameter("automatic backports are only supported for internal contributors")
}
// internal, err := b.isInternal(ctx)
// if err != nil {
// return trace.Wrap(err, "checking for internal author")
// }
// if !internal {
// return trace.BadParameter("automatic backports are only supported for internal contributors")
// }

pull, err := b.c.GitHub.GetPullRequest(ctx,
b.c.Environment.Organization,
Expand Down Expand Up @@ -91,9 +91,6 @@ func (b *Bot) Backport(ctx context.Context) error {

// Create and push git branch for backport to GitHub.
err := b.createBackportBranch(ctx,
b.c.Environment.Organization,
b.c.Environment.Repository,
b.c.Environment.Number,
base,
pull,
head,
Expand Down Expand Up @@ -164,9 +161,6 @@ func (b *Bot) BackportLocal(ctx context.Context, branch string) error {
}

err = b.createBackportBranch(ctx,
b.c.Environment.Organization,
b.c.Environment.Repository,
b.c.Environment.Number,
branch,
pull,
b.backportBranchName(branch),
Expand Down Expand Up @@ -211,7 +205,7 @@ func findBranches(labels []string) []string {
//
// TODO(russjones): Refactor to use go-git (so similar git library) instead of
// executing git from disk.
func (b *Bot) createBackportBranch(ctx context.Context, organization string, repository string, number int, base string, pull github.PullRequest, newHead string, git func(...string) error) error {
func (b *Bot) createBackportBranch(ctx context.Context, base string, pull github.PullRequest, newHead string, git func(...string) error) error {
log.Println("--> Backporting to", base, "<--")

if err := git("config", "--global", "user.name", "github-actions"); err != nil {
Expand All @@ -221,8 +215,9 @@ func (b *Bot) createBackportBranch(ctx context.Context, organization string, rep
log.Printf("Failed to set user.email: %v.", err)
}

// Fetch the refs for the base branch and the Github PR.
if err := git("fetch", "origin", base, fmt.Sprintf("pull/%d/head", number)); err != nil {
// Fetch the refs for the base branch and the merged commit.
// TODO(TROSS) uncomment this after test if err := git("fetch", "origin", base, pull.MergeCommitSHA); err != nil {
if err := git("fetch", "origin", "master", "c64253265b7cb675c7ca336c0454a65b7db4dd5d"); err != nil {
return trace.Wrap(err)
}

Expand Down

0 comments on commit 45b4f99

Please sign in to comment.