1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-03 13:11:48 +02:00

feat(nix): 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:57 -03:00
parent 2ecd71ee71
commit 42b6282e46
No known key found for this signature in database
2 changed files with 22 additions and 10 deletions

View File

@ -390,8 +390,27 @@ func doPublish(ctx *context.Context, prefetcher shaPrefetcher, cl client.Client,
return err
}
base := client.Repo{
Name: nix.Repository.PullRequest.Base.Name,
Owner: nix.Repository.PullRequest.Base.Owner,
Branch: nix.Repository.PullRequest.Base.Branch,
}
// try to sync branch
fscli, ok := cl.(client.ForkSyncer)
if ok && nix.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, []byte(content), gpath, msg); err != nil {
return err
}
if !nix.Repository.PullRequest.Enabled {
return cl.CreateFile(ctx, author, repo, []byte(content), gpath, msg)
log.Debug("nix.pull_request disabled")
return nil
}
log.Info("nix.pull_request enabled, creating a PR")
@ -400,15 +419,7 @@ func doPublish(ctx *context.Context, prefetcher shaPrefetcher, cl client.Client,
return fmt.Errorf("client does not support pull requests")
}
if err := cl.CreateFile(ctx, author, repo, []byte(content), gpath, msg); err != nil {
return err
}
return pcl.OpenPullRequest(ctx, client.Repo{
Name: nix.Repository.PullRequest.Base.Name,
Owner: nix.Repository.PullRequest.Base.Owner,
Branch: nix.Repository.PullRequest.Base.Branch,
}, repo, msg, nix.Repository.PullRequest.Draft)
return pcl.OpenPullRequest(ctx, base, repo, msg, nix.Repository.PullRequest.Draft)
}
func doBuildPkg(ctx *context.Context, data templateData) (string, error) {

View File

@ -574,6 +574,7 @@ func TestRunPipe(t *testing.T) {
if tt.nix.Repository.PullRequest.Enabled {
require.True(t, client.OpenedPullRequest)
require.True(t, client.SyncedFork)
}
if tt.nix.Path != "" {
require.Equal(t, tt.nix.Path, client.Path)