Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions cmd/spr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ VERSION: fork of {{.Version}}
if c.IsSet("no-rebase") {
cfg.User.NoRebase = c.Bool("no-rebase")
}
if c.IsSet("fetch") && c.IsSet("no-fetch") {
return fmt.Errorf("cannot use both --fetch and --no-fetch")
}
if c.IsSet("fetch") {
cfg.User.NoFetch = !c.Bool("fetch")
}
if c.IsSet("no-fetch") {
cfg.User.NoFetch = c.Bool("no-fetch")
}
Expand Down Expand Up @@ -229,12 +235,18 @@ VERSION: fork of {{.Version}}
// layer ops so it is likely relied on as a feature by users at this point
EnvVars: []string{"SPR_NOREBASE"},
},
&cli.BoolFlag{
Name: "no-fetch",
Aliases: []string{"nf"},
Usage: "Disable fetch",
EnvVars: []string{"SPR_NOFETCH"},
},
&cli.BoolFlag{
Name: "fetch",
Aliases: []string{"f"},
Usage: "Enable fetch (overrides noFetch config)",
EnvVars: []string{"SPR_FETCH"},
},
&cli.BoolFlag{
Name: "no-fetch",
Aliases: []string{"nf"},
Usage: "Disable fetch",
EnvVars: []string{"SPR_NOFETCH"},
},
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

src = self;

vendorHash = "sha256-byl+MF0vlfa4V/3uPrv5Qlcvh5jIozEyUkKSSwlRWhs=";
vendorHash = "sha256-VB7OJ8UkZ0WhEM5l2wR3xA1yxZcr+G+FLt3MxNY83Tg=";

subPackages = [
"cmd/spr"
Expand Down
24 changes: 20 additions & 4 deletions github/githubclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,6 @@ func (c *client) UpdatePullRequest(ctx context.Context, gitcmd git.GitInterface,
info *github.GitHubInfo, pullRequests []*github.PullRequest, pr *github.PullRequest,
commit git.Commit, prevCommit *git.Commit) {

if c.config.User.LogGitHubCalls {
fmt.Printf("> github update %d : %s\n", pr.Number, pr.Title)
}

baseRefName := c.config.Repo.GitHubBranch
if prevCommit != nil {
baseRefName = git.BranchNameFromCommit(c.config, *prevCommit)
Expand All @@ -453,6 +449,26 @@ func (c *client) UpdatePullRequest(ctx context.Context, gitcmd git.GitInterface,
templatizer := config_fetcher.PRTemplatizer(c.config, gitcmd)
title := templatizer.Title(info, commit)
body := templatizer.Body(info, commit, pr)

// Skip the API call if nothing has actually changed. This avoids
// triggering a spurious pull_request "edited" event on GitHub which
// would cause a second (duplicate) Actions run after the force-push
// already triggered a "synchronize" event.
titleUnchanged := c.config.User.PreserveTitleAndBody || title == pr.Title
bodyUnchanged := c.config.User.PreserveTitleAndBody || body == pr.Body
baseUnchanged := pr.InQueue || baseRefName == pr.ToBranch
if titleUnchanged && bodyUnchanged && baseUnchanged {
log.Debug().Int("number", pr.Number).Msg("UpdatePullRequest: skipping, nothing changed")
if c.config.User.LogGitHubCalls {
fmt.Printf("> github update %d : %s (skipped, no changes)\n", pr.Number, pr.Title)
}
return
}

if c.config.User.LogGitHubCalls {
fmt.Printf("> github update %d : %s\n", pr.Number, pr.Title)
}

input := genclient.UpdatePullRequestInput{
PullRequestId: pr.ID,
Title: &title,
Expand Down
33 changes: 33 additions & 0 deletions spr/spr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,39 @@ func testAmendInvalidInput(t *testing.T, sync bool) {
})
}

func TestSPRFetchOverridesNoFetchConfig(t *testing.T) {
// Test that --fetch flag overrides noFetch config (sets NoFetch back to false)
// This simulates: yaml has noFetch: true, user passes --fetch on CLI
s, gitmock, githubmock, _, output := makeTestObjects(t, true)
assert := require.New(t)
ctx := context.Background()

// Start with NoFetch true (as if loaded from yaml config)
s.config.User.NoFetch = true
// Then override it back to false (as the --fetch flag would do)
s.config.User.NoFetch = false

c1 := git.Commit{
CommitID: "00000001",
CommitHash: "c100000000000000000000000000000000000000",
Subject: "test commit 1",
}

// With NoFetch=false, fetch should run
githubmock.ExpectGetInfo()
gitmock.ExpectFetch()
gitmock.ExpectLogAndRespond([]*git.Commit{&c1})
gitmock.ExpectPushCommits([]*git.Commit{&c1})
githubmock.ExpectCreatePullRequest(c1, nil)
githubmock.ExpectUpdatePullRequest(c1, nil)
githubmock.ExpectGetInfo()
s.UpdatePullRequests(ctx, nil, nil)
assert.Equal("[vvvv] 1 : test commit 1\n", output.String())
gitmock.ExpectationsMet()
githubmock.ExpectationsMet()
output.Reset()
}

func uintptr(a uint) *uint {
return &a
}
Expand Down
Loading