Skip to content

Commit

Permalink
feat(brew): sync fork before opening PR
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Mar 27, 2024
1 parent 3687c09 commit b9b8a65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
30 changes: 20 additions & 10 deletions internal/pipe/brew/brew.go
Expand Up @@ -171,9 +171,27 @@ func doPublish(ctx *context.Context, formula *artifact.Artifact, cl client.Clien
return err
}

base := client.Repo{
Name: brew.Repository.PullRequest.Base.Name,
Owner: brew.Repository.PullRequest.Base.Owner,
Branch: brew.Repository.PullRequest.Base.Branch,
}

// try to sync branch
fscli, ok := cl.(client.ForkSyncer)
if ok && brew.Repository.PullRequest.Enabled {
if err := fscli.SyncFork(ctx, repo, base); err != nil {
log.WithError(err).Warn("could not sync fork")
}
}

if err := cl.CreateFile(ctx, author, repo, content, gpath, msg); err != nil {
return err
}

if !brew.Repository.PullRequest.Enabled {
log.Debug("brews.pull_request disabled")
return cl.CreateFile(ctx, author, repo, content, gpath, msg)
return nil
}

log.Info("brews.pull_request enabled, creating a PR")
Expand All @@ -182,15 +200,7 @@ func doPublish(ctx *context.Context, formula *artifact.Artifact, cl client.Clien
return fmt.Errorf("client does not support pull requests")
}

if err := cl.CreateFile(ctx, author, repo, content, gpath, msg); err != nil {
return err
}

return pcl.OpenPullRequest(ctx, client.Repo{
Name: brew.Repository.PullRequest.Base.Name,
Owner: brew.Repository.PullRequest.Base.Owner,
Branch: brew.Repository.PullRequest.Base.Branch,
}, repo, msg, brew.Repository.PullRequest.Draft)
return pcl.OpenPullRequest(ctx, base, repo, msg, brew.Repository.PullRequest.Draft)
}

func doRun(ctx *context.Context, brew config.Homebrew, cl client.ReleaseURLTemplater) error {
Expand Down
1 change: 1 addition & 0 deletions internal/pipe/brew/brew_test.go
Expand Up @@ -1107,6 +1107,7 @@ func TestRunPipePullRequest(t *testing.T) {
require.NoError(t, publishAll(ctx, client))
require.True(t, client.CreatedFile)
require.True(t, client.OpenedPullRequest)
require.True(t, client.SyncedFork)
golden.RequireEqualRb(t, []byte(client.Content))
}

Expand Down

0 comments on commit b9b8a65

Please sign in to comment.