mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-07 13:31:37 +02:00
fix: failing when pull_request.base is empty (#4261)
if the base branch is empty, it'll try to fetch the default branch, which would fail if base repo name/owner are also empty. the default behavior when base owner/name are missing is to using head's, so I changed it do that before trying to get the default branch, which should fix the issue.
This commit is contained in:
parent
94a65fcda1
commit
ec0df9ecd5
@ -196,6 +196,8 @@ func (c *githubClient) OpenPullRequest(
|
|||||||
draft bool,
|
draft bool,
|
||||||
) error {
|
) error {
|
||||||
c.checkRateLimit(ctx)
|
c.checkRateLimit(ctx)
|
||||||
|
base.Owner = firstNonEmpty(base.Owner, head.Owner)
|
||||||
|
base.Name = firstNonEmpty(base.Name, head.Name)
|
||||||
if base.Branch == "" {
|
if base.Branch == "" {
|
||||||
def, err := c.getDefaultBranch(ctx, base)
|
def, err := c.getDefaultBranch(ctx, base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -217,8 +219,8 @@ func (c *githubClient) OpenPullRequest(
|
|||||||
log.Info("opening pull request")
|
log.Info("opening pull request")
|
||||||
pr, res, err := c.client.PullRequests.Create(
|
pr, res, err := c.client.PullRequests.Create(
|
||||||
ctx,
|
ctx,
|
||||||
firstNonEmpty(base.Owner, head.Owner),
|
base.Owner,
|
||||||
firstNonEmpty(base.Name, head.Name),
|
base.Name,
|
||||||
&github.NewPullRequest{
|
&github.NewPullRequest{
|
||||||
Title: github.String(title),
|
Title: github.String(title),
|
||||||
Base: github.String(base.Branch),
|
Base: github.String(base.Branch),
|
||||||
|
@ -652,6 +652,55 @@ func TestGitHubOpenPullRequestBaseEmpty(t *testing.T) {
|
|||||||
}))
|
}))
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
|
|
||||||
|
ctx := testctx.NewWithCfg(config.Project{
|
||||||
|
GitHubURLs: config.GitHubURLs{
|
||||||
|
API: srv.URL + "/",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
client, err := newGitHub(ctx, "test-token")
|
||||||
|
require.NoError(t, err)
|
||||||
|
repo := Repo{
|
||||||
|
Owner: "someone",
|
||||||
|
Name: "something",
|
||||||
|
Branch: "foo",
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NoError(t, client.OpenPullRequest(ctx, Repo{}, repo, "some title", false))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGitHubOpenPullRequestHeadEmpty(t *testing.T) {
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
defer r.Body.Close()
|
||||||
|
|
||||||
|
if r.URL.Path == "/repos/someone/something/contents/.github/PULL_REQUEST_TEMPLATE.md" {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.URL.Path == "/repos/someone/something/pulls" {
|
||||||
|
r, err := os.Open("testdata/github/pull.json")
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = io.Copy(w, r)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.URL.Path == "/repos/someone/something" {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
fmt.Fprint(w, `{"default_branch": "main"}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.URL.Path == "/rate_limit" {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
fmt.Fprint(w, `{"resources":{"core":{"remaining":120}}}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Error("unhandled request: " + r.URL.Path)
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
ctx := testctx.NewWithCfg(config.Project{
|
ctx := testctx.NewWithCfg(config.Project{
|
||||||
GitHubURLs: config.GitHubURLs{
|
GitHubURLs: config.GitHubURLs{
|
||||||
API: srv.URL + "/",
|
API: srv.URL + "/",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user