diff --git a/internal/pipe/scoop/scoop.go b/internal/pipe/scoop/scoop.go index c2c82bac1..757125e06 100644 --- a/internal/pipe/scoop/scoop.go +++ b/internal/pipe/scoop/scoop.go @@ -174,14 +174,24 @@ func doPublish(ctx *context.Context, cl client.Client) error { scoop.Bucket = ref repo := client.RepoFromRef(scoop.Bucket) - return cl.CreateFile( - ctx, - author, - repo, - content, - path.Join(scoop.Folder, manifest.Name), - commitMessage, - ) + gpath := path.Join(scoop.Folder, manifest.Name) + + if !scoop.Bucket.PullRequest.Enabled { + return cl.CreateFile(ctx, author, repo, content, gpath, commitMessage) + } + + log.Info("brews.pull_request enabled, creating a PR") + pcl, ok := cl.(client.PullRequestOpener) + if !ok { + return fmt.Errorf("client does not support pull requests") + } + + if err := cl.CreateFile(ctx, author, repo, content, gpath, commitMessage); err != nil { + return err + } + + title := fmt.Sprintf("Updated %s to %s", ctx.Config.ProjectName, ctx.Version) + return pcl.OpenPullRequest(ctx, repo, scoop.Bucket.PullRequest.Base, title) } // Manifest represents a scoop.sh App Manifest. diff --git a/internal/pipe/scoop/scoop_test.go b/internal/pipe/scoop/scoop_test.go index 02c2651ad..381d76113 100644 --- a/internal/pipe/scoop/scoop_test.go +++ b/internal/pipe/scoop/scoop_test.go @@ -510,6 +510,56 @@ func Test_doRun(t *testing.T) { } } +func TestRunPipePullRequest(t *testing.T) { + folder := t.TempDir() + ctx := testctx.NewWithCfg( + config.Project{ + Dist: folder, + ProjectName: "foo", + Scoop: config.Scoop{ + Name: "foo", + Homepage: "https://goreleaser.com", + Description: "Fake desc", + Bucket: config.RepoRef{ + Owner: "foo", + Name: "bar", + Branch: "update-{{.Version}}", + PullRequest: config.PullRequest{ + Enabled: true, + }, + }, + }, + }, + testctx.WithVersion("1.2.1"), + testctx.WithCurrentTag("v1.2.1"), + ) + path := filepath.Join(folder, "dist/foo_windows_amd64/foo.exe") + ctx.Artifacts.Add(&artifact.Artifact{ + Name: "foo_windows_amd64.tar.gz", + Path: path, + Goos: "windows", + Goarch: "amd64", + Type: artifact.UploadableArchive, + Extra: map[string]interface{}{ + artifact.ExtraID: "foo", + artifact.ExtraFormat: "tar.gz", + artifact.ExtraBinary: "foo", + }, + }) + + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + f, err := os.Create(path) + require.NoError(t, err) + require.NoError(t, f.Close()) + + client := client.NewMock() + require.NoError(t, doRun(ctx, client)) + require.NoError(t, doPublish(ctx, client)) + require.True(t, client.CreatedFile) + require.True(t, client.OpenedPullRequest) + golden.RequireEqualJSON(t, []byte(client.Content)) +} + func Test_buildManifest(t *testing.T) { folder := t.TempDir() file := filepath.Join(folder, "archive") diff --git a/internal/pipe/scoop/testdata/TestRunPipePullRequest.json.golden b/internal/pipe/scoop/testdata/TestRunPipePullRequest.json.golden new file mode 100644 index 000000000..fd5fdfc46 --- /dev/null +++ b/internal/pipe/scoop/testdata/TestRunPipePullRequest.json.golden @@ -0,0 +1,12 @@ +{ + "version": "1.2.1", + "architecture": { + "64bit": { + "url": "https://dummyhost/download/v1.2.1/foo_windows_amd64.tar.gz", + "bin": null, + "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + } + }, + "homepage": "https://goreleaser.com", + "description": "Fake desc" +} \ No newline at end of file diff --git a/www/docs/customization/scoop.md b/www/docs/customization/scoop.md index 7640c7ce4..6e29de0d8 100644 --- a/www/docs/customization/scoop.md +++ b/www/docs/customization/scoop.md @@ -40,6 +40,20 @@ scoop: # to GoReleaser token: "{{ .Env.SCOOP_TAP_GITHUB_TOKEN }}" + # Sets up pull request creation instead of just pushing to the given branch. + # Make sure the 'branch' property is different from base before enabling + # it. + # + # Since: v1.17 + pull_request: + # Whether to enable it or not. + enabled: true + + # Base branch of the PR. + # + # Default: default repository branch. + base: main + # Folder inside the repository to put the scoop. # # Note that while scoop works if the manifests are in a folder,