Skip to content

Commit

Permalink
feat(scoop): sync fork before opening PR
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Mar 27, 2024
1 parent 42b6282 commit 500be66
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
33 changes: 22 additions & 11 deletions internal/pipe/scoop/scoop.go
Expand Up @@ -259,25 +259,36 @@ func doPublish(ctx *context.Context, manifest *artifact.Artifact, cl client.Clie
return err
}

if !scoop.Repository.PullRequest.Enabled {
return cl.CreateFile(ctx, author, repo, content, gpath, commitMessage)
base := client.Repo{
Name: scoop.Repository.PullRequest.Base.Name,
Owner: scoop.Repository.PullRequest.Base.Owner,
Branch: scoop.Repository.PullRequest.Base.Branch,
}

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")
// try to sync branch
fscli, ok := cl.(client.ForkSyncer)
if ok && scoop.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, content, gpath, commitMessage); err != nil {
return err
}

return pcl.OpenPullRequest(ctx, client.Repo{
Name: scoop.Repository.PullRequest.Base.Name,
Owner: scoop.Repository.PullRequest.Base.Owner,
Branch: scoop.Repository.PullRequest.Base.Branch,
}, repo, commitMessage, scoop.Repository.PullRequest.Draft)
if !scoop.Repository.PullRequest.Enabled {
log.Debug("scoop.pull_request disabled")
return nil
}

log.Info("scoop.pull_request enabled, creating a PR")
pcl, ok := cl.(client.PullRequestOpener)
if !ok {
return fmt.Errorf("client does not support pull requests")
}

return pcl.OpenPullRequest(ctx, base, repo, commitMessage, scoop.Repository.PullRequest.Draft)
}

// Manifest represents a scoop.sh App Manifest.
Expand Down
1 change: 1 addition & 0 deletions internal/pipe/scoop/scoop_test.go
Expand Up @@ -782,6 +782,7 @@ func TestRunPipePullRequest(t *testing.T) {
require.NoError(t, publishAll(ctx, client))
require.True(t, client.CreatedFile)
require.True(t, client.OpenedPullRequest)
require.True(t, client.SyncedFork)
golden.RequireEqualJSON(t, []byte(client.Content))
}

Expand Down

0 comments on commit 500be66

Please sign in to comment.