Address trail review follow-ups · Entire
Address trail review follow-ups
2716736→main·
dipree·1mo ago·3 files·+31 added/-34 removed
Sessions
324dce6a13feView transcript
[?
Fix Trail Command Behavior and API AlignmentPi·GPT-5.5·5 steps](/content/gh/entireio/cli/session/019ed4cf-858e-70be-9fde-ff8ea73b50bc#timeline-324dce6a13fe/index.html)
Changes
3
cmd/entire/cli
Mtrail_cmd.go+28/-7
Mtrail_cmd_test.go+3/-3
Mtrail_review_cmd.go-24
33 unmodified lines
34
35
36
37
37
38
39
40
964 unmodified lines
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1030
1031
1032
1033
1034
44 unmodified lines
1079
1080
1081
1058
1059
1060
1082
1083
1084
96 unmodified lines
1181
1182
1183
1163
1184
1185
1165
1186
1187
1188
1189
1190
1191
1192
1172
1193
1194
1195
1196
33 unmodified lines
// trailListServerMaxLimit is the most trails the server returns per
// request (the list endpoint clamps limit to 200).
trailListServerMaxLimit = 200
trailFindMaxPages = 100
trailFindMaxPages = 10
)
func newTrailCmd() *cobra.Command {
964 unmodified lines
}
// findTrailByBranch looks up a trail by branch name via the list API.
func findTrailBySelector(ctx context.Context, client *api.Client, forge, owner, repo, selector string) (*api.TrailResource, error) {
selector = strings.TrimSpace(selector)
if selector == "" {
return nil, nil //nolint:nilnil // empty selector means not found for this helper
}
if n, ok := parseTrailNumberSelector(selector); ok {
found, err := findTrailByNumber(ctx, client, forge, owner, repo, n)
if err != nil || found != nil {
return found, err
}
}
return findTrail(ctx, client, forge, owner, repo, func(t api.TrailResource) bool {
return t.ID == selector || t.Branch == selector
})
}
func parseTrailNumberSelector(selector string) (int, bool) {
n, err := strconv.Atoi(strings.TrimSpace(selector))
if err != nil || n <= 0 {
return 0, false
}
return n, true
}
func findTrailByBranch(ctx context.Context, client *api.Client, forge, owner, repo, branch string) (*api.TrailResource, error) {
return findTrail(ctx, client, forge, owner, repo, func(t api.TrailResource) bool {
return t.Branch == branch
})
}
44 unmodified lines
break
if listResp.Total == 0 {
if offset > 0 {
break
}
pageSignature := trailListPageSignature(listResp.Trails)
if pageSignature != "" && pageSignature == previousPageSignature {
break
}
}
96 unmodified lines
if localCreated {
branchRef := plumbing.NewBranchReferenceName(branchName)
if head, err := repo.Head(); err == nil && head.Name() == branchRef {
fmt.Fprintf(errW, "Warning: not deleting local branch %s after trail creation failed because it is checked out\n", branchName)
fmt.Fprintf(errW, "Warning: not deleting local branch %s after trail creation failed because it is checked out; switch branches and run 'git branch -D %s' if you do not need it\n", branchName, branchName)
} else if err := repo.Storer.RemoveReference(branchRef); err != nil {
fmt.Fprintf(errW, "Warning: failed to delete local branch %s after trail creation failed: %v\n", branchName, err)
fmt.Fprintf(errW, "Warning: failed to delete local branch %s after trail creation failed: %v; run 'git branch -D %s' if you do not need it\n", branchName, err, branchName)
} else {
localRemoved = true
}
}
if remotePushed {
if !localRemoved {
fmt.Fprintf(errW, "Warning: not deleting remote branch %s after trail creation failed because local cleanup did not complete\n", branchName)
fmt.Fprintf(errW, "Warning: not deleting remote branch %s after trail creation failed because local cleanup did not complete; run 'git push origin --delete %s' if you do not need it\n", branchName, branchName)
return
}
if err := deleteBranchFromOrigin(branchName); err != nil {
Mcmd/entire/cli/trail_cmd.go+28/-7
328 unmodified lines
329
330
331
332
332
333
334
335
17 unmodified lines
353
354
355
356
357
356
357
358
359
360
328 unmodified lines
}
func TestFindTrailStopsOnSecondFullPageWithoutTotal(t *testing.T) {
func TestFindTrailStopsAtMaxPagesWithoutTotal(t *testing.T) {
t.Parallel()
var requests int32
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
17 unmodified lines
if found != nil {
t.Fatalf("found = %#v, want nil", found)
}
if got := atomic.LoadInt32(&requests); got != 2 {
t.Fatalf("requests = %d, want 2", got)
}
if got := atomic.LoadInt32(&requests); got != trailFindMaxPages {
t.Fatalf("requests = %d, want %d", got)
}
}
Mcmd/entire/cli/trail_cmd_test.go+3/-3
484 unmodified lines
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
488
489
490
484 unmodified lines
return trailReviewTarget{Host: host, Owner: owner, Repo: repo, Trail: *found}, nil
}
func findTrailBySelector(ctx context.Context, client *api.Client, host, owner, repo, selector string) (*api.TrailResource, error) {
selector = strings.TrimSpace(selector)
if selector == "" {
return nil, nil //nolint:nilnil // empty selector means not found for this helper
}
if n, ok := parseTrailReviewNumberSelector(selector); ok {
found, err := findTrailByNumber(ctx, client, host, owner, repo, n)
if err != nil || found != nil {
return found, err
}
}
return findTrail(ctx, client, host, owner, repo, func(t api.TrailResource) bool {
return t.ID == selector || t.Branch == selector
})
}
func parseTrailReviewNumberSelector(selector string) (int, bool) {
n, err := strconv.Atoi(strings.TrimSpace(selector))
if err != nil || n <= 0 {
return 0, false
}
return n, true
}
func normalizeTrailReviewListOptions(opts trailReviewListOptions) (trailReviewListOptions, error) {
if opts.Limit <= 0 {
return opts, errors.New("limit must be greater than 0")
}