mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-04 03:11:55 +02:00
feat(github): allow to open PRs as drafts (#4054)
This allows to open a pull requests as a draft. Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
7c6d6561b5
commit
f6b9ccbd8f
@ -73,7 +73,7 @@ type ReleaseNotesGenerator interface {
|
||||
|
||||
// PullRequestOpener can open pull requests.
|
||||
type PullRequestOpener interface {
|
||||
OpenPullRequest(ctx *context.Context, base, head Repo, title string) error
|
||||
OpenPullRequest(ctx *context.Context, base, head Repo, title string, draft bool) error
|
||||
}
|
||||
|
||||
// New creates a new client depending on the token type.
|
||||
|
@ -170,6 +170,7 @@ func (c *githubClient) OpenPullRequest(
|
||||
ctx *context.Context,
|
||||
base, head Repo,
|
||||
title string,
|
||||
draft bool,
|
||||
) error {
|
||||
c.checkRateLimit(ctx)
|
||||
if base.Branch == "" {
|
||||
@ -181,13 +182,15 @@ func (c *githubClient) OpenPullRequest(
|
||||
}
|
||||
log := log.
|
||||
WithField("base", headString(base, Repo{})).
|
||||
WithField("head", headString(base, head))
|
||||
WithField("head", headString(base, head)).
|
||||
WithField("draft", draft)
|
||||
log.Info("opening pull request")
|
||||
pr, res, err := c.client.PullRequests.Create(ctx, base.Owner, base.Name, &github.NewPullRequest{
|
||||
Title: github.String(title),
|
||||
Base: github.String(base.Branch),
|
||||
Head: github.String(headString(base, head)),
|
||||
Body: github.String("Automatically generated by [GoReleaser](https://goreleaser.com)"),
|
||||
Draft: github.Bool(draft),
|
||||
})
|
||||
if err != nil {
|
||||
if res.StatusCode == 422 {
|
||||
|
@ -450,7 +450,7 @@ func TestOpenPullRequestCrossRepo(t *testing.T) {
|
||||
Name: "something",
|
||||
Branch: "foo",
|
||||
}
|
||||
require.NoError(t, client.OpenPullRequest(ctx, base, head, "some title"))
|
||||
require.NoError(t, client.OpenPullRequest(ctx, base, head, "some title", false))
|
||||
}
|
||||
|
||||
func TestOpenPullRequestHappyPath(t *testing.T) {
|
||||
@ -488,10 +488,10 @@ func TestOpenPullRequestHappyPath(t *testing.T) {
|
||||
Branch: "main",
|
||||
}
|
||||
|
||||
require.NoError(t, client.OpenPullRequest(ctx, repo, Repo{}, "some title"))
|
||||
require.NoError(t, client.OpenPullRequest(ctx, repo, Repo{}, "some title", false))
|
||||
}
|
||||
|
||||
func TestOpenPullRequestNoBaseBranch(t *testing.T) {
|
||||
func TestOpenPullRequestNoBaseBranchDraft(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
|
||||
@ -502,6 +502,7 @@ func TestOpenPullRequestNoBaseBranch(t *testing.T) {
|
||||
require.NoError(t, json.Unmarshal(got, &pr))
|
||||
require.Equal(t, "main", pr.GetBase())
|
||||
require.Equal(t, "someone:something:foo", pr.GetHead())
|
||||
require.Equal(t, true, pr.GetDraft())
|
||||
|
||||
r, err := os.Open("testdata/github/pull.json")
|
||||
require.NoError(t, err)
|
||||
@ -540,7 +541,7 @@ func TestOpenPullRequestNoBaseBranch(t *testing.T) {
|
||||
|
||||
require.NoError(t, client.OpenPullRequest(ctx, repo, Repo{
|
||||
Branch: "foo",
|
||||
}, "some title"))
|
||||
}, "some title", true))
|
||||
}
|
||||
|
||||
func TestOpenPullRequestPRExists(t *testing.T) {
|
||||
@ -579,7 +580,7 @@ func TestOpenPullRequestPRExists(t *testing.T) {
|
||||
Branch: "main",
|
||||
}
|
||||
|
||||
require.NoError(t, client.OpenPullRequest(ctx, repo, Repo{}, "some title"))
|
||||
require.NoError(t, client.OpenPullRequest(ctx, repo, Repo{}, "some title", false))
|
||||
}
|
||||
|
||||
func TestOpenPullRequestBaseEmpty(t *testing.T) {
|
||||
@ -623,7 +624,7 @@ func TestOpenPullRequestBaseEmpty(t *testing.T) {
|
||||
Branch: "main",
|
||||
}
|
||||
|
||||
require.NoError(t, client.OpenPullRequest(ctx, repo, Repo{}, "some title"))
|
||||
require.NoError(t, client.OpenPullRequest(ctx, repo, Repo{}, "some title", false))
|
||||
}
|
||||
|
||||
func TestGitHubCreateFileHappyPathCreate(t *testing.T) {
|
||||
|
@ -42,7 +42,7 @@ type Mock struct {
|
||||
OpenedPullRequest bool
|
||||
}
|
||||
|
||||
func (c *Mock) OpenPullRequest(_ *context.Context, _, _ Repo, _ string) error {
|
||||
func (c *Mock) OpenPullRequest(_ *context.Context, _, _ Repo, _ string, _ bool) error {
|
||||
c.OpenedPullRequest = true
|
||||
return nil
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ func doPublish(ctx *context.Context, formula *artifact.Artifact, cl client.Clien
|
||||
Name: brew.Tap.PullRequest.Base.Name,
|
||||
Owner: brew.Tap.PullRequest.Base.Owner,
|
||||
Branch: brew.Tap.PullRequest.Base.Branch,
|
||||
}, repo, title)
|
||||
}, repo, title, brew.Tap.PullRequest.Draft)
|
||||
}
|
||||
|
||||
func doRun(ctx *context.Context, brew config.Homebrew, cl client.ReleaserURLTemplater) error {
|
||||
|
@ -358,7 +358,7 @@ func doPublish(ctx *context.Context, manifest *artifact.Artifact, cl client.Clie
|
||||
Name: cfg.Index.PullRequest.Base.Name,
|
||||
Owner: cfg.Index.PullRequest.Base.Owner,
|
||||
Branch: cfg.Index.PullRequest.Base.Branch,
|
||||
}, repo, title)
|
||||
}, repo, title, cfg.Index.PullRequest.Draft)
|
||||
}
|
||||
|
||||
func buildManifestPath(folder, filename string) string {
|
||||
|
@ -367,7 +367,7 @@ func doPublish(ctx *context.Context, prefetcher shaPrefetcher, cl client.Client,
|
||||
Name: nix.Repository.PullRequest.Base.Name,
|
||||
Owner: nix.Repository.PullRequest.Base.Owner,
|
||||
Branch: nix.Repository.PullRequest.Base.Branch,
|
||||
}, repo, title)
|
||||
}, repo, title, nix.Repository.PullRequest.Draft)
|
||||
}
|
||||
|
||||
func doBuildPkg(ctx *context.Context, data templateData) (string, error) {
|
||||
|
@ -274,7 +274,7 @@ func doPublish(ctx *context.Context, manifest *artifact.Artifact, cl client.Clie
|
||||
Name: scoop.Bucket.PullRequest.Base.Name,
|
||||
Owner: scoop.Bucket.PullRequest.Base.Owner,
|
||||
Branch: scoop.Bucket.PullRequest.Base.Branch,
|
||||
}, repo, title)
|
||||
}, repo, title, scoop.Bucket.PullRequest.Draft)
|
||||
}
|
||||
|
||||
// Manifest represents a scoop.sh App Manifest.
|
||||
|
@ -142,6 +142,7 @@ func (a PullRequestBase) JSONSchema() *jsonschema.Schema {
|
||||
type PullRequest struct {
|
||||
Enabled bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
|
||||
Base PullRequestBase `yaml:"base,omitempty" json:"base,omitempty"`
|
||||
Draft bool `yaml:"draft,omitempty" json:"draft,omitempty"`
|
||||
}
|
||||
|
||||
// HomebrewDependency represents Homebrew dependency.
|
||||
|
@ -1,6 +1,9 @@
|
||||
# Setting a custom git tag
|
||||
|
||||
You can force the [build tag](/customization/build/#define-build-tag) and [previous changelog tag](/customization/release/#define-previous-tag) using environment variables.
|
||||
You can force the
|
||||
[build tag](/customization/build/#define-build-tag) and
|
||||
[previous changelog tag](/customization/release/#define-previous-tag)
|
||||
using environment variables.
|
||||
This can be useful in cases where one git commit is referenced by multiple git tags.
|
||||
|
||||
Example usage:
|
||||
|
@ -77,11 +77,11 @@ brews:
|
||||
# Whether to enable it or not.
|
||||
enabled: true
|
||||
|
||||
# Base branch of the PR.
|
||||
# If base is a string, the PR will be opened into the same repository.
|
||||
# Whether to open the PR as a draft or not.
|
||||
#
|
||||
# Default: default repository branch.
|
||||
base: main
|
||||
# Default: false
|
||||
# Since: v1.19
|
||||
draft: true
|
||||
|
||||
# Base can also be another repository, in which case the owner and name
|
||||
# above will be used as HEAD, allowing cross-repository pull requests.
|
||||
|
@ -72,11 +72,11 @@ krews:
|
||||
# Whether to enable it or not.
|
||||
enabled: true
|
||||
|
||||
# Base branch of the PR.
|
||||
# If base is a string, the PR will be opened into the same repository.
|
||||
# Whether to open the PR as a draft or not.
|
||||
#
|
||||
# Default: default repository branch.
|
||||
base: main
|
||||
# Default: false
|
||||
# Since: v1.19
|
||||
draft: true
|
||||
|
||||
# Base can also be another repository, in which case the owner and name
|
||||
# above will be used as HEAD, allowing cross-repository pull requests.
|
||||
|
@ -62,11 +62,11 @@ nix:
|
||||
# Whether to enable it or not.
|
||||
enabled: true
|
||||
|
||||
# Base branch of the PR.
|
||||
# If base is a string, the PR will be opened into the same repository.
|
||||
# Whether to open the PR as a draft or not.
|
||||
#
|
||||
# Default: default repository branch.
|
||||
base: main
|
||||
# Default: false
|
||||
# Since: v1.19
|
||||
draft: true
|
||||
|
||||
# Base can also be another repository, in which case the owner and name
|
||||
# above will be used as HEAD, allowing cross-repository pull requests.
|
||||
|
@ -59,11 +59,11 @@ scoops:
|
||||
# Whether to enable it or not.
|
||||
enabled: true
|
||||
|
||||
# Base branch of the PR.
|
||||
# If base is a string, the PR will be opened into the same repository.
|
||||
# Whether to open the PR as a draft or not.
|
||||
#
|
||||
# Default: default repository branch.
|
||||
base: main
|
||||
# Default: false
|
||||
# Since: v1.19
|
||||
draft: true
|
||||
|
||||
# Base can also be another repository, in which case the owner and name
|
||||
# above will be used as HEAD, allowing cross-repository pull requests.
|
||||
|
Loading…
Reference in New Issue
Block a user