Skip to content

Commit 13b8bf5

Browse files
authored
avoid unnecessary pr update calls (#738)
resending unchanged fields like BaseRefName makes github fire extra pull_request webhooks, doubling workflow runs in consumer repos.
1 parent 5b9a755 commit 13b8bf5

19 files changed

Lines changed: 146 additions & 64 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ man/
2020
# Output of the go coverage tool, specifically when used with LiteIDE
2121
*.out
2222
cmd/av/av
23-
.claude/settings.local.json
23+
.claude/

cmd/av/auth.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ func checkAviatorAuthStatus(ctx context.Context) error {
4444
return errors.Wrap(err, "Failed to query Aviator")
4545
}
4646

47-
fmt.Fprint(os.Stderr,
47+
fmt.Fprint(
48+
os.Stderr,
4849
"Logged in to Aviator as ", colors.UserInput(query.Viewer.FullName),
4950
" (", colors.UserInput(query.Viewer.Email), ").\n",
5051
)
@@ -69,7 +70,8 @@ func checkGitHubAuthStatus(ctx context.Context) error {
6970
return errors.Wrap(err, "Failed to query GitHub")
7071
}
7172

72-
fmt.Fprint(os.Stderr,
73+
fmt.Fprint(
74+
os.Stderr,
7375
"Logged in to GitHub as ", colors.UserInput(viewer.Name),
7476
" (", colors.UserInput(viewer.Login), ").\n",
7577
)

cmd/av/branch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ func createBranch(
368368
// On failure, we want to delete the branch we created so that the user
369369
// can try again (e.g., to fix issues surfaced by a pre-commit hook).
370370
cu.Add(func() {
371-
fmt.Fprint(os.Stderr,
371+
fmt.Fprint(
372+
os.Stderr,
372373
colors.Faint(" - Cleaning up branch "),
373374
colors.UserInput(branchName),
374375
colors.Faint(" because commit was not successful."),

cmd/av/commit.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ func runCreate(ctx context.Context, repo *git.Repo, db meta.DB) error {
114114
ExitError: true,
115115
})
116116
if err != nil {
117-
fmt.Fprint(os.Stderr,
117+
fmt.Fprint(
118+
os.Stderr,
118119
"\n", colors.Failure("Failed to stage files: ", err.Error()), "\n",
119120
)
120121
return actions.ErrExitSilently{ExitCode: 1}
@@ -217,7 +218,8 @@ func runAmend(
217218
ExitError: true,
218219
})
219220
if err != nil {
220-
fmt.Fprint(os.Stderr,
221+
fmt.Fprint(
222+
os.Stderr,
221223
"\n", colors.Failure("Failed to stage files: ", err.Error()), "\n",
222224
)
223225
return actions.ErrExitSilently{ExitCode: 1}
@@ -292,7 +294,8 @@ func branchAndCommit(
292294
ExitError: true,
293295
})
294296
if err != nil {
295-
fmt.Fprint(os.Stderr,
297+
fmt.Fprint(
298+
os.Stderr,
296299
"\n", colors.Failure("Failed to stage files: ", err.Error()), "\n",
297300
)
298301
return actions.ErrExitSilently{ExitCode: 1}
@@ -309,7 +312,8 @@ func branchAndCommit(
309312
ExitError: true,
310313
Interactive: true,
311314
}); err != nil {
312-
fmt.Fprint(os.Stderr,
315+
fmt.Fprint(
316+
os.Stderr,
313317
"\n", colors.Failure("Failed to create commit."), "\n",
314318
)
315319
return actions.ErrExitSilently{ExitCode: 1}

cmd/av/diff.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ Generates the diff between the working tree and the parent branch
113113
// We need to display this **after** the diff to ensure that the diff
114114
// output pager doesn't eat this message.
115115
if notUpToDate {
116-
fmt.Fprint(os.Stderr,
116+
fmt.Fprint(
117+
os.Stderr,
117118
colors.Warning("\nWARNING: Branch "), colors.UserInput(currentBranchName),
118119
colors.Warning(" is not up to date with parent branch "),
119120
colors.UserInput(branch.Parent.Name), colors.Warning(". Run "),

cmd/av/helpers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ func getOrCreateDB(repo *git.Repo) (meta.DB, bool, error) {
7171
dbPath := filepath.Join(repo.AvDir(), "av.db")
7272
db, exists, err := jsonfiledb.OpenPath(dbPath)
7373
if err != nil {
74-
return nil, false, errors.WrapIff(err,
74+
return nil, false, errors.WrapIff(
75+
err,
7576
"failed to open av database at %q (the file may be corrupted; try deleting it and running 'av init')",
7677
dbPath,
7778
)

cmd/av/pr.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ func init() {
419419
)
420420
prCmd.Flags().BoolVar(
421421
&prFlags.Current, "current", false,
422-
"create pull requests up to the current branch")
422+
"create pull requests up to the current branch",
423+
)
423424
_ = prCmd.Flags().MarkHidden("current")
424425

425426
deprecatedCreateCmd := deprecateCommand(*prCmd, "av pr", "create")

cmd/av/reorder.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ squashed, dropped, or moved within the stack.
5050
var continuation reorder.Continuation
5151
if err := repo.ReadStateFile(git.StateFileKindReorder, &continuation); os.IsNotExist(err) {
5252
if reorderFlags.Continue || reorderFlags.Abort {
53-
fmt.Fprint(os.Stderr,
53+
fmt.Fprint(
54+
os.Stderr,
5455
colors.Failure("ERROR: no reorder in progress\n"),
5556
)
5657
return actions.ErrExitSilently{ExitCode: 127}
@@ -90,7 +91,8 @@ squashed, dropped, or moved within the stack.
9091
}
9192
if stat != nil {
9293
if err := repo.CherryPick(ctx, git.CherryPick{Resume: git.CherryPickContinue}); err != nil {
93-
fmt.Fprint(os.Stderr,
94+
fmt.Fprint(
95+
os.Stderr,
9496
colors.Failure("Failed to continue cherry-pick: ", err.Error(), "\n"),
9597
colors.Warning("Resolve the conflict and run "),
9698
colors.CliCmd("av reorder --continue"),
@@ -126,7 +128,8 @@ squashed, dropped, or moved within the stack.
126128
return err
127129
}
128130
if currentHead == state.Head {
129-
fmt.Fprint(os.Stderr,
131+
fmt.Fprint(
132+
os.Stderr,
130133
colors.Failure("ERROR: cannot continue squash/fixup — the cherry-pick was not applied.\n"),
131134
colors.Warning("If you aborted or skipped the cherry-pick, run "),
132135
colors.CliCmd("av reorder --abort"),
@@ -137,7 +140,8 @@ squashed, dropped, or moved within the stack.
137140

138141
if err := pickCmd.PerformSquash(ctx, repo, state.BranchBase); err != nil {
139142
if errors.Is(err, reorder.ErrEmptySquashMessage) {
140-
fmt.Fprint(os.Stderr,
143+
fmt.Fprint(
144+
os.Stderr,
141145
colors.Failure("squash commit message is empty after editing\n"),
142146
colors.Warning("Edit the message and run "),
143147
colors.CliCmd("av reorder --continue"),
@@ -165,7 +169,8 @@ squashed, dropped, or moved within the stack.
165169
state.Head = head
166170
} else {
167171
if continuation.State != nil {
168-
fmt.Fprint(os.Stderr,
172+
fmt.Fprint(
173+
os.Stderr,
169174
colors.Failure("ERROR: reorder already in progress\n"),
170175
colors.Failure(" use --continue or --abort to continue or abort the reorder\n"),
171176
)
@@ -178,7 +183,8 @@ squashed, dropped, or moved within the stack.
178183
}
179184
root, ok := meta.Root(tx, currentBranch)
180185
if !ok {
181-
fmt.Fprint(os.Stderr,
186+
fmt.Fprint(
187+
os.Stderr,
182188
colors.Failure("ERROR: branch "), colors.UserInput(currentBranch),
183189
colors.Failure(" is not part of a stack\n"),
184190
)
@@ -215,7 +221,8 @@ squashed, dropped, or moved within the stack.
215221
if err := repo.WriteStateFile(git.StateFileKindReorder, nil); err != nil {
216222
return err
217223
}
218-
fmt.Fprint(os.Stderr,
224+
fmt.Fprint(
225+
os.Stderr,
219226
colors.Success("\nThe stack was reordered successfully.\n"),
220227
)
221228
return nil
@@ -225,7 +232,8 @@ squashed, dropped, or moved within the stack.
225232
if err := repo.WriteStateFile(git.StateFileKindReorder, &continuation); err != nil {
226233
return err
227234
}
228-
fmt.Fprint(os.Stderr,
235+
fmt.Fprint(
236+
os.Stderr,
229237
colors.Warning("\nThe reorder was interrupted by a conflict.\n"),
230238
colors.Warning("Resolve the conflict and run "),
231239
colors.CliCmd("av reorder --continue"),
@@ -255,7 +263,8 @@ edit:
255263
return nil, err
256264
}
257265
if len(plan) == 0 {
258-
fmt.Fprint(os.Stderr,
266+
fmt.Fprint(
267+
os.Stderr,
259268
colors.Failure("ERROR: reorder plan is empty\n"),
260269
)
261270
return nil, actions.ErrExitSilently{ExitCode: 127}

cmd/av/stack_foreach.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ Examples:
7474
}
7575
}
7676

77-
_, _ = fmt.Fprint(os.Stderr,
77+
_, _ = fmt.Fprint(
78+
os.Stderr,
7879
"Executing command ", colors.CliCmd(executils.FormatCommandLine(args)),
7980
" for ", colors.UserInput(len(branches)), " branches:\n",
8081
)
8182
for _, branch := range branches {
82-
_, _ = fmt.Fprint(os.Stderr,
83+
_, _ = fmt.Fprint(
84+
os.Stderr,
8385
" - switching to branch ", colors.UserInput(branch), "\n",
8486
)
8587
if _, err := repo.CheckoutBranch(ctx, &git.CheckoutBranch{Name: branch}); err != nil {

cmd/av/switch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ var switchCmd = &cobra.Command{
6666
for _, node := range rootNodes {
6767
branchList = append(
6868
branchList,
69-
switchBranchList(ctx, repo, tx, branches, node)...)
69+
switchBranchList(ctx, repo, tx, branches, node)...,
70+
)
7071
}
7172
if len(branchList) == 0 {
7273
return errors.New("no branches found")

0 commit comments

Comments
 (0)