1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-11-06 09:09:29 +02:00

feat(brew): sync fork before opening PR

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2024-03-26 23:04:12 -03:00
parent 3687c097cd
commit b9b8a65618
2 changed files with 21 additions and 10 deletions

View File

@@ -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")
@@ -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 {

View File

@@ -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))
}