mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-13 13:48:40 +02:00
feat(winget): sync fork before opening PR
closes https://github.com/goreleaser/goreleaser/issues/4720 Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
10a4a20122
commit
3687c097cd
@ -90,6 +90,11 @@ type ReleaseNotesGenerator interface {
|
|||||||
GenerateReleaseNotes(ctx *context.Context, repo Repo, prev, current string) (string, error)
|
GenerateReleaseNotes(ctx *context.Context, repo Repo, prev, current string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ForkSyncer can sync forks.
|
||||||
|
type ForkSyncer interface {
|
||||||
|
SyncFork(ctx *context.Context, head, base Repo) error
|
||||||
|
}
|
||||||
|
|
||||||
// PullRequestOpener can open pull requests.
|
// PullRequestOpener can open pull requests.
|
||||||
type PullRequestOpener interface {
|
type PullRequestOpener interface {
|
||||||
OpenPullRequest(ctx *context.Context, base, head Repo, title string, draft bool) error
|
OpenPullRequest(ctx *context.Context, base, head Repo, title string, draft bool) error
|
||||||
|
@ -28,6 +28,7 @@ var (
|
|||||||
_ Client = &githubClient{}
|
_ Client = &githubClient{}
|
||||||
_ ReleaseNotesGenerator = &githubClient{}
|
_ ReleaseNotesGenerator = &githubClient{}
|
||||||
_ PullRequestOpener = &githubClient{}
|
_ PullRequestOpener = &githubClient{}
|
||||||
|
_ ForkSyncer = &githubClient{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type githubClient struct {
|
type githubClient struct {
|
||||||
@ -217,6 +218,7 @@ func (c *githubClient) OpenPullRequest(
|
|||||||
if len(tpl) > 0 {
|
if len(tpl) > 0 {
|
||||||
log.Info("got a pr template")
|
log.Info("got a pr template")
|
||||||
}
|
}
|
||||||
|
|
||||||
log := log.
|
log := log.
|
||||||
WithField("base", headString(base, Repo{})).
|
WithField("base", headString(base, Repo{})).
|
||||||
WithField("head", headString(base, head)).
|
WithField("head", headString(base, head)).
|
||||||
@ -245,6 +247,31 @@ func (c *githubClient) OpenPullRequest(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *githubClient) SyncFork(ctx *context.Context, head, base Repo) error {
|
||||||
|
branch := base.Branch
|
||||||
|
if branch == "" {
|
||||||
|
def, err := c.getDefaultBranch(ctx, base)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
branch = def
|
||||||
|
}
|
||||||
|
res, _, err := c.client.Repositories.MergeUpstream(
|
||||||
|
ctx,
|
||||||
|
head.Owner,
|
||||||
|
head.Name,
|
||||||
|
&github.RepoMergeUpstreamRequest{
|
||||||
|
Branch: github.String(branch),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if res != nil {
|
||||||
|
log.WithField("merge_type", res.GetMergeType()).
|
||||||
|
WithField("base_branch", res.GetBaseBranch()).
|
||||||
|
Info(res.GetMessage())
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (c *githubClient) CreateFile(
|
func (c *githubClient) CreateFile(
|
||||||
ctx *context.Context,
|
ctx *context.Context,
|
||||||
commitAuthor config.CommitAuthor,
|
commitAuthor config.CommitAuthor,
|
||||||
|
@ -16,6 +16,7 @@ var (
|
|||||||
_ Client = &Mock{}
|
_ Client = &Mock{}
|
||||||
_ ReleaseNotesGenerator = &Mock{}
|
_ ReleaseNotesGenerator = &Mock{}
|
||||||
_ PullRequestOpener = &Mock{}
|
_ PullRequestOpener = &Mock{}
|
||||||
|
_ ForkSyncer = &Mock{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewMock() *Mock {
|
func NewMock() *Mock {
|
||||||
@ -42,6 +43,12 @@ type Mock struct {
|
|||||||
ReleaseNotes string
|
ReleaseNotes string
|
||||||
ReleaseNotesParams []string
|
ReleaseNotesParams []string
|
||||||
OpenedPullRequest bool
|
OpenedPullRequest bool
|
||||||
|
SyncedFork bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Mock) SyncFork(ctx *context.Context, head Repo, base Repo) error {
|
||||||
|
c.SyncedFork = true
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Mock) OpenPullRequest(_ *context.Context, _, _ Repo, _ string, _ bool) error {
|
func (c *Mock) OpenPullRequest(_ *context.Context, _, _ Repo, _ string, _ bool) error {
|
||||||
|
@ -315,6 +315,20 @@ func doPublish(ctx *context.Context, cl client.Client, wingets []*artifact.Artif
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base := client.Repo{
|
||||||
|
Name: winget.Repository.PullRequest.Base.Name,
|
||||||
|
Owner: winget.Repository.PullRequest.Base.Owner,
|
||||||
|
Branch: winget.Repository.PullRequest.Base.Branch,
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to sync branch
|
||||||
|
fscli, ok := cl.(client.ForkSyncer)
|
||||||
|
if ok && winget.Repository.PullRequest.Enabled {
|
||||||
|
if err := fscli.SyncFork(ctx, repo, base); err != nil {
|
||||||
|
log.WithError(err).Warn("could not sync fork")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if err := cl.CreateFile(
|
if err := cl.CreateFile(
|
||||||
ctx,
|
ctx,
|
||||||
@ -339,11 +353,7 @@ func doPublish(ctx *context.Context, cl client.Client, wingets []*artifact.Artif
|
|||||||
return fmt.Errorf("client does not support pull requests")
|
return fmt.Errorf("client does not support pull requests")
|
||||||
}
|
}
|
||||||
|
|
||||||
return pcl.OpenPullRequest(ctx, client.Repo{
|
return pcl.OpenPullRequest(ctx, base, repo, msg, winget.Repository.PullRequest.Draft)
|
||||||
Name: winget.Repository.PullRequest.Base.Name,
|
|
||||||
Owner: winget.Repository.PullRequest.Base.Owner,
|
|
||||||
Branch: winget.Repository.PullRequest.Base.Branch,
|
|
||||||
}, repo, msg, winget.Repository.PullRequest.Draft)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func langserverLineFor(tp artifact.Type) string {
|
func langserverLineFor(tp artifact.Type) string {
|
||||||
|
@ -127,6 +127,10 @@ func TestRunPipe(t *testing.T) {
|
|||||||
Branch: "update-{{.Version}}",
|
Branch: "update-{{.Version}}",
|
||||||
PullRequest: config.PullRequest{
|
PullRequest: config.PullRequest{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
|
Base: config.PullRequestBase{
|
||||||
|
Owner: "ms",
|
||||||
|
Name: "winget",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -753,6 +757,7 @@ func TestRunPipe(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if tt.winget.Repository.PullRequest.Enabled {
|
if tt.winget.Repository.PullRequest.Enabled {
|
||||||
|
require.True(t, client.SyncedFork)
|
||||||
require.True(t, client.OpenedPullRequest)
|
require.True(t, client.OpenedPullRequest)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -41,6 +41,7 @@ something: # can be nix, brews, etc...
|
|||||||
|
|
||||||
This will:
|
This will:
|
||||||
|
|
||||||
|
- Try to sync the `john/repo` fork with `mike/repo:main` (if on GitHub).
|
||||||
- Create the files into `john/repo`, in the branch `foo-1.2.3` (assuming
|
- Create the files into `john/repo`, in the branch `foo-1.2.3` (assuming
|
||||||
`ProjectName=foo` and `Version=1.2.3`). [^head]
|
`ProjectName=foo` and `Version=1.2.3`). [^head]
|
||||||
- Open a pull request from `john/repo` into `mike/repo`, with the branch `main`
|
- Open a pull request from `john/repo` into `mike/repo`, with the branch `main`
|
||||||
@ -51,8 +52,6 @@ This will:
|
|||||||
|
|
||||||
### Things that don't work
|
### Things that don't work
|
||||||
|
|
||||||
- **GoReleaser will not keep your fork in sync!!!** It might or might not be a
|
|
||||||
problem in your case, in which case you'll have to sync it manually.
|
|
||||||
- Opening pull requests to a forked repository (`go-github` does not have the
|
- Opening pull requests to a forked repository (`go-github` does not have the
|
||||||
required fields to do it).
|
required fields to do it).
|
||||||
- Since this can fail for a myriad of reasons, if an error happen, it'll log it
|
- Since this can fail for a myriad of reasons, if an error happen, it'll log it
|
||||||
|
Loading…
x
Reference in New Issue
Block a user