GitLabgitlab-org

cli

main
ply8 git calls220 ms102 KiB6 cachedprotocol v2
1060 lines33 KiBRaw
1//go:build !integration
3package note
5import (
6 "bytes"
7 "errors"
8 "net/http"
9 "testing"
11 "git.sr.ht/~timofurrer/ugh"
12 "github.com/spf13/cobra"
13 "github.com/stretchr/testify/assert"
14 "github.com/stretchr/testify/require"
15 "go.uber.org/mock/gomock"
17 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
18 gitlabtesting "gitlab.com/gitlab-org/api/client-go/v3/testing"
20 "gitlab.com/gitlab-org/cli/internal/cmdutils"
21 "gitlab.com/gitlab-org/cli/internal/config"
22 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
25func Test_NewCmdCreate(t *testing.T) {
26 t.Parallel()
28 t.Run("help explains how to find discussion IDs", func(t *testing.T) {
29 t.Parallel()
31 var output bytes.Buffer
32 cmd := NewCmdCreate(cmdtest.NewTestFactory(nil))
33 cmd.SetArgs([]string{"--help"})
34 cmd.SetOut(&output)
35 require.NoError(t, cmd.Execute())
37 out := output.String()
38 assert.Contains(t, out, "glab mr note list")
39 assert.Contains(t, out, "glab mr note list -F json | jq -r '.[].id'")
40 assert.Contains(t, out, "the `id` field of each discussion object")
41 assert.Contains(t, out, "eight characters before the ellipsis")
42 assert.Contains(t, out, "[discussion: abc12345…]")
43 assert.Contains(t, out, "--reply abc12345")
44 assert.NotContains(t, out, "--reply abc12345…")
45 assert.NotContains(t, out, "top-level `.id`")
46 })
48 t.Run("--message flag specified", func(t *testing.T) {
49 t.Parallel()
51 testClient := setupMR(t)
53 testClient.MockDiscussions.EXPECT().
54 CreateMergeRequestDiscussion("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
55 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
56 assert.Equal(t, "Here is my note", *opts.Body)
57 return &gitlab.Discussion{
58 ID: "disc1",
59 Notes: []*gitlab.Note{
60 {ID: 301, NoteableID: 1, NoteableType: "MergeRequest", NoteableIID: 1},
61 },
62 }, nil, nil
63 })
65 exec := setupCreateExec(t, testClient)
67 output, err := exec(`1 --message "Here is my note"`)
68 require.NoError(t, err)
69 assert.Empty(t, output.Stderr())
70 assert.Equal(t, "https://gitlab.com/OWNER/REPO/merge_requests/1#note_301\n", output.String())
71 })
73 t.Run("merge request not found", func(t *testing.T) {
74 t.Parallel()
76 testClient := setupMRNotFound(t)
78 exec := setupCreateExec(t, testClient)
80 _, err := exec(`122`)
81 require.Error(t, err)
82 assert.Contains(t, err.Error(), "Not Found")
83 })
86func Test_NewCmdCreate_error(t *testing.T) {
87 t.Parallel()
89 t.Run("note could not be created", func(t *testing.T) {
90 t.Parallel()
92 testClient := setupMR(t)
94 unauthorizedResp := &gitlab.Response{
95 Response: &http.Response{StatusCode: http.StatusUnauthorized},
96 }
97 testClient.MockDiscussions.EXPECT().
98 CreateMergeRequestDiscussion("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
99 Return(nil, unauthorizedResp, errors.New("401 Unauthorized"))
101 exec := setupCreateExec(t, testClient)
103 _, err := exec(`1 -m "Some message"`)
104 require.Error(t, err)
105 })
108func Test_cmdCreate_repoOverride(t *testing.T) {
109 t.Parallel()
111 t.Run("--message flag specified", func(t *testing.T) {
112 t.Parallel()
114 testClient := gitlabtesting.NewTestClient(t)
115 mockMR1InRepo(t, testClient, "gitlab-org/cli")
117 testClient.MockDiscussions.EXPECT().
118 CreateMergeRequestDiscussion("gitlab-org/cli", int64(1), gomock.Any(), gomock.Any()).
119 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
120 assert.Equal(t, "Here is my note", *opts.Body)
121 return &gitlab.Discussion{
122 ID: "disc-override-message",
123 Notes: []*gitlab.Note{
124 {ID: 801, NoteableID: 1, NoteableType: "MergeRequest", NoteableIID: 1},
125 },
126 }, nil, nil
127 })
129 exec := setupCreateExecWithRepoOverride(t, testClient, true)
131 output, err := exec(`1 -R gitlab-org/cli --message "Here is my note"`)
132 require.NoError(t, err)
133 assert.Empty(t, output.Stderr())
134 assert.Equal(t, "https://gitlab.com/gitlab-org/cli/merge_requests/1#note_801\n", output.String())
135 })
137 t.Run("reads body from stdin with repo override", func(t *testing.T) {
138 t.Parallel()
140 testClient := gitlabtesting.NewTestClient(t)
141 mockMR1InRepo(t, testClient, "gitlab-org/cli")
143 testClient.MockDiscussions.EXPECT().
144 CreateMergeRequestDiscussion("gitlab-org/cli", int64(1), gomock.Any(), gomock.Any()).
145 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
146 assert.Equal(t, "Message from stdin", *opts.Body)
147 return &gitlab.Discussion{
148 ID: "disc-override-stdin",
149 Notes: []*gitlab.Note{
150 {ID: 802, NoteableID: 1, NoteableType: "MergeRequest", NoteableIID: 1},
151 },
152 }, nil, nil
153 })
155 exec := setupCreateExecWithRepoOverride(t, testClient, false, cmdtest.WithStdin("Message from stdin\n"))
157 output, err := exec(`1 -R gitlab-org/cli`)
158 require.NoError(t, err)
159 assert.Empty(t, output.Stderr())
160 assert.Equal(t, "https://gitlab.com/gitlab-org/cli/merge_requests/1#note_802\n", output.String())
161 })
164func Test_cmdCreate_prompt(t *testing.T) {
165 // NOTE: This test cannot run in parallel because the huh form library
166 // uses global state (charmbracelet/bubbles runeutil sanitizer).
168 t.Run("message provided via prompt", func(t *testing.T) {
169 testClient := setupMR(t)
171 testClient.MockDiscussions.EXPECT().
172 CreateMergeRequestDiscussion("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
173 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
174 assert.Contains(t, *opts.Body, "some note message")
175 return &gitlab.Discussion{
176 ID: "disc1",
177 Notes: []*gitlab.Note{
178 {ID: 301, NoteableID: 1, NoteableType: "MergeRequest", NoteableIID: 1},
179 },
180 }, nil, nil
181 })
183 c := ugh.New(t)
184 c.Expect(ugh.Input("Note message:")).
185 Do(ugh.Type("some note message"))
187 exec := cmdtest.SetupCmdForTest(t, NewCmdCreate, true,
188 cmdtest.WithGitLabClient(testClient.Client),
189 cmdtest.WithBaseRepo("OWNER", "REPO", ""),
190 cmdtest.WithConfig(config.NewFromString("editor: vi")),
191 cmdtest.WithConsole(t, c),
192 )
194 output, err := exec(`1`)
195 require.NoError(t, err)
196 assert.Empty(t, output.Stderr())
197 assert.Contains(t, output.String(), "https://gitlab.com/OWNER/REPO/merge_requests/1#note_301")
198 })
200 t.Run("message is empty", func(t *testing.T) {
201 testClient := setupMR(t)
203 c := ugh.New(t)
204 c.Expect(ugh.Input("Note message:")).
205 Do(ugh.Type(""))
207 exec := cmdtest.SetupCmdForTest(t, NewCmdCreate, true,
208 cmdtest.WithGitLabClient(testClient.Client),
209 cmdtest.WithBaseRepo("OWNER", "REPO", ""),
210 cmdtest.WithConfig(config.NewFromString("editor: vi")),
211 cmdtest.WithConsole(t, c),
212 )
214 _, err := exec(`1`)
215 require.Error(t, err)
216 assert.Equal(t, "aborted: note has an empty message", err.Error())
217 })
220func Test_cmdCreate_unique_prompt(t *testing.T) {
221 // NOTE: This test cannot run in parallel because the huh form library
222 // uses global state (charmbracelet/bubbles runeutil sanitizer).
224 t.Run("duplicate found", func(t *testing.T) {
225 testClient := setupMR(t)
227 testClient.MockNotes.EXPECT().
228 ListMergeRequestNotes("OWNER/REPO", int64(1), gomock.Any()).
229 Return([]*gitlab.Note{
230 {ID: 0, Body: "aaa"},
231 {ID: 111, Body: "bbb"},
232 {ID: 222, Body: "some note message"},
233 {ID: 333, Body: "ccc"},
234 }, nil, nil)
236 c := ugh.New(t)
237 c.Expect(ugh.Input("Note message:")).
238 Do(ugh.Type("some note message"))
240 exec := cmdtest.SetupCmdForTest(t, NewCmdCreate, true,
241 cmdtest.WithGitLabClient(testClient.Client),
242 cmdtest.WithBaseRepo("OWNER", "REPO", ""),
243 cmdtest.WithConfig(config.NewFromString("editor: vi")),
244 cmdtest.WithConsole(t, c),
245 )
247 output, err := exec(`1 --unique`)
248 require.NoError(t, err)
249 assert.Empty(t, output.Stderr())
250 assert.Contains(t, output.String(), "https://gitlab.com/OWNER/REPO/merge_requests/1#note_222")
251 })
254func Test_cmdCreate_unique(t *testing.T) {
255 t.Parallel()
257 t.Run("no duplicate creates new note", func(t *testing.T) {
258 t.Parallel()
260 testClient := setupMR(t)
262 testClient.MockNotes.EXPECT().
263 ListMergeRequestNotes("OWNER/REPO", int64(1), gomock.Any()).
264 Return([]*gitlab.Note{
265 {ID: 100, Body: "other note"},
266 }, nil, nil)
268 testClient.MockDiscussions.EXPECT().
269 CreateMergeRequestDiscussion("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
270 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
271 assert.Equal(t, "brand new note", *opts.Body)
272 return &gitlab.Discussion{
273 ID: "disc1",
274 Notes: []*gitlab.Note{
275 {ID: 301, NoteableID: 1, NoteableType: "MergeRequest", NoteableIID: 1},
276 },
277 }, nil, nil
278 })
280 exec := setupCreateExec(t, testClient)
282 output, err := exec(`1 -m "brand new note" --unique`)
283 require.NoError(t, err)
284 assert.Contains(t, output.String(), "#note_301")
285 })
288func Test_cmdCreate_reply(t *testing.T) {
289 t.Parallel()
291 const fullID = "abc12345deadbeef1234567890abcdef12345678"
293 t.Run("replies to discussion by full ID", func(t *testing.T) {
294 t.Parallel()
296 testClient := setupMR(t)
298 testClient.MockDiscussions.EXPECT().
299 ListMergeRequestDiscussions("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
300 Return([]*gitlab.Discussion{{ID: fullID}}, nil, nil)
302 testClient.MockDiscussions.EXPECT().
303 AddMergeRequestDiscussionNote("OWNER/REPO", int64(1), fullID, gomock.Any(), gomock.Any()).
304 DoAndReturn(func(pid any, mrIID int64, discID string, opts *gitlab.AddMergeRequestDiscussionNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error) {
305 assert.Equal(t, "I agree!", *opts.Body)
306 return &gitlab.Note{ID: 901}, nil, nil
307 })
309 exec := setupCreateExec(t, testClient)
311 output, err := exec(`1 --reply ` + fullID + ` -m "I agree!"`)
312 require.NoError(t, err)
313 assert.Equal(t, "https://gitlab.com/OWNER/REPO/merge_requests/1#note_901\n", output.String())
314 })
316 t.Run("replies to discussion by prefix", func(t *testing.T) {
317 t.Parallel()
319 testClient := setupMR(t)
321 testClient.MockDiscussions.EXPECT().
322 ListMergeRequestDiscussions("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
323 Return([]*gitlab.Discussion{
324 {ID: fullID},
325 {ID: "ff000000deadbeef1234567890abcdef12345678"},
326 }, nil, nil)
328 testClient.MockDiscussions.EXPECT().
329 AddMergeRequestDiscussionNote("OWNER/REPO", int64(1), fullID, gomock.Any(), gomock.Any()).
330 Return(&gitlab.Note{ID: 902}, nil, nil)
332 exec := setupCreateExec(t, testClient)
334 output, err := exec(`1 --reply abc12345 -m "thanks"`)
335 require.NoError(t, err)
336 assert.Contains(t, output.String(), "#note_902")
337 })
339 t.Run("prefix too short", func(t *testing.T) {
340 t.Parallel()
342 testClient := setupMR(t)
344 exec := setupCreateExec(t, testClient)
346 _, err := exec(`1 --reply abc -m "hi"`)
347 require.Error(t, err)
348 assert.Contains(t, err.Error(), "at least 8 characters")
349 })
351 t.Run("prefix not found", func(t *testing.T) {
352 t.Parallel()
354 testClient := setupMR(t)
356 testClient.MockDiscussions.EXPECT().
357 ListMergeRequestDiscussions("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
358 Return([]*gitlab.Discussion{{ID: "ff000000deadbeef1234567890abcdef12345678"}}, nil, nil)
360 exec := setupCreateExec(t, testClient)
362 _, err := exec(`1 --reply abc12345 -m "hi"`)
363 require.Error(t, err)
364 assert.Contains(t, err.Error(), "no discussion found")
365 })
367 t.Run("ambiguous prefix", func(t *testing.T) {
368 t.Parallel()
370 testClient := setupMR(t)
372 testClient.MockDiscussions.EXPECT().
373 ListMergeRequestDiscussions("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
374 Return([]*gitlab.Discussion{
375 {ID: "abc123450000beef1234567890abcdef12345678"},
376 {ID: "abc123459999beef1234567890abcdef12345678"},
377 }, nil, nil)
379 exec := setupCreateExec(t, testClient)
381 _, err := exec(`1 --reply abc12345 -m "hi"`)
382 require.Error(t, err)
383 assert.Contains(t, err.Error(), "matches 2 discussions")
384 })
386 t.Run("AddMergeRequestDiscussionNote error wrapped", func(t *testing.T) {
387 t.Parallel()
389 testClient := setupMR(t)
391 testClient.MockDiscussions.EXPECT().
392 ListMergeRequestDiscussions("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
393 Return([]*gitlab.Discussion{{ID: fullID}}, nil, nil)
395 testClient.MockDiscussions.EXPECT().
396 AddMergeRequestDiscussionNote("OWNER/REPO", int64(1), fullID, gomock.Any(), gomock.Any()).
397 Return(nil, nil, errors.New("boom"))
399 exec := setupCreateExec(t, testClient)
401 _, err := exec(`1 --reply ` + fullID + ` -m "hi"`)
402 require.Error(t, err)
403 assert.Contains(t, err.Error(), "failed to add reply")
404 assert.Contains(t, err.Error(), "boom")
405 })
407 t.Run("--reply and --unique are mutually exclusive", func(t *testing.T) {
408 t.Parallel()
410 testClient := gitlabtesting.NewTestClient(t)
412 exec := setupCreateExec(t, testClient)
414 _, err := exec(`1 --reply abc12345 --unique -m "hi"`)
415 require.Error(t, err)
416 assert.Contains(t, err.Error(), "none of the others can be")
417 })
420func Test_cmdCreate_resolvable(t *testing.T) {
421 t.Parallel()
423 t.Run("default (no flag) posts a resolvable discussion via the Discussions API", func(t *testing.T) {
424 t.Parallel()
426 testClient := setupMR(t)
428 testClient.MockDiscussions.EXPECT().
429 CreateMergeRequestDiscussion("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
430 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
431 assert.Equal(t, "default path", *opts.Body)
432 return &gitlab.Discussion{
433 ID: "disc-default",
434 Notes: []*gitlab.Note{{ID: 500}},
435 }, nil, nil
436 })
438 exec := setupCreateExec(t, testClient)
440 output, err := exec(`1 -m "default path"`)
441 require.NoError(t, err)
442 assert.Equal(t, "https://gitlab.com/OWNER/REPO/merge_requests/1#note_500\n", output.String())
443 })
445 t.Run("--resolvable=false posts a plain note via the Notes API", func(t *testing.T) {
446 t.Parallel()
448 testClient := setupMR(t)
450 testClient.MockNotes.EXPECT().
451 CreateMergeRequestNote("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
452 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error) {
453 assert.Equal(t, "Build status: green", *opts.Body)
454 assert.Nil(t, opts.Internal)
455 return &gitlab.Note{ID: 501}, nil, nil
456 })
458 exec := setupCreateExec(t, testClient)
460 output, err := exec(`1 --resolvable=false -m "Build status: green"`)
461 require.NoError(t, err)
462 assert.Empty(t, output.Stderr())
463 assert.Equal(t, "https://gitlab.com/OWNER/REPO/merge_requests/1#note_501\n", output.String())
464 })
466 t.Run("--resolvable=false --unique skips duplicate then posts a note", func(t *testing.T) {
467 t.Parallel()
469 testClient := setupMR(t)
471 testClient.MockNotes.EXPECT().
472 ListMergeRequestNotes("OWNER/REPO", int64(1), gomock.Any()).
473 Return([]*gitlab.Note{
474 {ID: 100, Body: "other note"},
475 }, nil, nil)
477 testClient.MockNotes.EXPECT().
478 CreateMergeRequestNote("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
479 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error) {
480 assert.Equal(t, "brand new note", *opts.Body)
481 return &gitlab.Note{ID: 502}, nil, nil
482 })
484 exec := setupCreateExec(t, testClient)
486 output, err := exec(`1 --resolvable=false --unique -m "brand new note"`)
487 require.NoError(t, err)
488 assert.Contains(t, output.String(), "#note_502")
489 })
491 t.Run("--resolvable=false and --reply are mutually exclusive", func(t *testing.T) {
492 t.Parallel()
494 testClient := gitlabtesting.NewTestClient(t)
496 exec := setupCreateExec(t, testClient)
498 _, err := exec(`1 --resolvable=false --reply abc12345 -m "hi"`)
499 require.Error(t, err)
500 assert.Contains(t, err.Error(), "--resolvable=false cannot be used with --reply")
501 })
503 t.Run("--resolvable=false and --file are mutually exclusive", func(t *testing.T) {
504 t.Parallel()
506 testClient := gitlabtesting.NewTestClient(t)
508 exec := setupCreateExec(t, testClient)
510 _, err := exec(`1 --resolvable=false --file main.go -m "hi"`)
511 require.Error(t, err)
512 assert.Contains(t, err.Error(), "--resolvable=false cannot be used with --file, --line, or --old-line")
513 })
515 t.Run("--resolvable=true with --reply is allowed (no false positive)", func(t *testing.T) {
516 t.Parallel()
518 const fullID = "abc12345deadbeef1234567890abcdef12345678"
520 testClient := setupMR(t)
522 testClient.MockDiscussions.EXPECT().
523 ListMergeRequestDiscussions("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
524 Return([]*gitlab.Discussion{{ID: fullID}}, nil, nil)
526 testClient.MockDiscussions.EXPECT().
527 AddMergeRequestDiscussionNote("OWNER/REPO", int64(1), fullID, gomock.Any(), gomock.Any()).
528 Return(&gitlab.Note{ID: 503}, nil, nil)
530 exec := setupCreateExec(t, testClient)
532 output, err := exec(`1 --resolvable=true --reply abc12345 -m "hi"`)
533 require.NoError(t, err)
534 assert.Contains(t, output.String(), "#note_503")
535 })
538func Test_cmdCreate_internal(t *testing.T) {
539 t.Parallel()
541 t.Run("--internal posts an internal note via the Notes API", func(t *testing.T) {
542 t.Parallel()
544 testClient := setupMR(t)
546 testClient.MockNotes.EXPECT().
547 CreateMergeRequestNote("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
548 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error) {
549 assert.Equal(t, "Rotating the leaked token now.", *opts.Body)
550 require.NotNil(t, opts.Internal)
551 assert.True(t, *opts.Internal)
552 return &gitlab.Note{ID: 600}, nil, nil
553 })
555 exec := setupCreateExec(t, testClient)
557 output, err := exec(`1 --internal -m "Rotating the leaked token now."`)
558 require.NoError(t, err)
559 assert.Empty(t, output.Stderr())
560 assert.Equal(t, "https://gitlab.com/OWNER/REPO/merge_requests/1#note_600\n", output.String())
561 })
563 t.Run("--internal with an explicit --resolvable=false posts an internal note", func(t *testing.T) {
564 t.Parallel()
566 testClient := setupMR(t)
568 testClient.MockNotes.EXPECT().
569 CreateMergeRequestNote("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
570 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error) {
571 require.NotNil(t, opts.Internal)
572 assert.True(t, *opts.Internal)
573 return &gitlab.Note{ID: 601}, nil, nil
574 })
576 exec := setupCreateExec(t, testClient)
578 output, err := exec(`1 --internal --resolvable=false -m "members only"`)
579 require.NoError(t, err)
580 assert.Contains(t, output.String(), "#note_601")
581 })
583 t.Run("--internal --unique posts when no matching note exists", func(t *testing.T) {
584 t.Parallel()
586 testClient := setupMR(t)
588 testClient.MockNotes.EXPECT().
589 ListMergeRequestNotes("OWNER/REPO", int64(1), gomock.Any()).
590 Return([]*gitlab.Note{{ID: 100, Body: "other note"}}, nil, nil)
592 testClient.MockNotes.EXPECT().
593 CreateMergeRequestNote("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
594 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error) {
595 require.NotNil(t, opts.Internal)
596 assert.True(t, *opts.Internal)
597 return &gitlab.Note{ID: 602}, nil, nil
598 })
600 exec := setupCreateExec(t, testClient)
602 output, err := exec(`1 --internal --unique -m "brand new internal note"`)
603 require.NoError(t, err)
604 assert.Contains(t, output.String(), "#note_602")
605 })
607 t.Run("--internal never falls back to the Discussions API", func(t *testing.T) {
608 t.Parallel()
610 testClient := setupMR(t)
612 testClient.MockDiscussions.EXPECT().
613 CreateMergeRequestDiscussion(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
614 Times(0)
616 testClient.MockNotes.EXPECT().
617 CreateMergeRequestNote("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
618 Return(&gitlab.Note{ID: 603}, nil, nil)
620 exec := setupCreateExec(t, testClient)
622 _, err := exec(`1 --internal -m "members only"`)
623 require.NoError(t, err)
624 })
626 t.Run("--internal and --resolvable=true are mutually exclusive", func(t *testing.T) {
627 t.Parallel()
629 testClient := gitlabtesting.NewTestClient(t)
631 exec := setupCreateExec(t, testClient)
633 _, err := exec(`1 --internal --resolvable=true -m "hi"`)
634 require.Error(t, err)
635 assert.Contains(t, err.Error(), "--internal cannot be used with --resolvable=true")
636 })
638 t.Run("--internal --reply posts to an internal thread, which makes the reply internal", func(t *testing.T) {
639 t.Parallel()
641 const fullID = "abc12345deadbeef1234567890abcdef12345678"
643 testClient := setupMR(t)
645 testClient.MockDiscussions.EXPECT().
646 ListMergeRequestDiscussions("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
647 Return([]*gitlab.Discussion{
648 {ID: fullID, Notes: []*gitlab.Note{{ID: 1, Internal: true}}},
649 }, nil, nil)
651 testClient.MockDiscussions.EXPECT().
652 AddMergeRequestDiscussionNote("OWNER/REPO", int64(1), fullID, gomock.Any(), gomock.Any()).
653 Return(&gitlab.Note{ID: 604}, nil, nil)
655 exec := setupCreateExec(t, testClient)
657 output, err := exec(`1 --reply abc12345 --internal -m "Patch is ready."`)
658 require.NoError(t, err)
659 assert.Contains(t, output.String(), "#note_604")
660 })
662 t.Run("--internal --reply refuses to post to a public thread", func(t *testing.T) {
663 t.Parallel()
665 const fullID = "abc12345deadbeef1234567890abcdef12345678"
667 testClient := setupMR(t)
669 testClient.MockDiscussions.EXPECT().
670 ListMergeRequestDiscussions("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
671 Return([]*gitlab.Discussion{
672 {ID: fullID, Notes: []*gitlab.Note{{ID: 1, Internal: false}}},
673 }, nil, nil)
675 testClient.MockDiscussions.EXPECT().
676 AddMergeRequestDiscussionNote(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
677 Times(0)
679 exec := setupCreateExec(t, testClient)
681 _, err := exec(`1 --reply abc12345 --internal -m "Patch is ready."`)
682 require.Error(t, err)
683 assert.Contains(t, err.Error(), "is not internal")
684 assert.Contains(t, err.Error(), "would be publicly visible")
685 })
687 t.Run("--reply without --internal still posts to an internal thread", func(t *testing.T) {
688 t.Parallel()
690 const fullID = "abc12345deadbeef1234567890abcdef12345678"
692 testClient := setupMR(t)
694 testClient.MockDiscussions.EXPECT().
695 ListMergeRequestDiscussions("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
696 Return([]*gitlab.Discussion{
697 {ID: fullID, Notes: []*gitlab.Note{{ID: 1, Internal: true}}},
698 }, nil, nil)
700 testClient.MockDiscussions.EXPECT().
701 AddMergeRequestDiscussionNote("OWNER/REPO", int64(1), fullID, gomock.Any(), gomock.Any()).
702 Return(&gitlab.Note{ID: 605}, nil, nil)
704 exec := setupCreateExec(t, testClient)
706 output, err := exec(`1 --reply abc12345 -m "no flag needed"`)
707 require.NoError(t, err)
708 assert.Contains(t, output.String(), "#note_605")
709 })
711 t.Run("--internal and --file are mutually exclusive", func(t *testing.T) {
712 t.Parallel()
714 testClient := gitlabtesting.NewTestClient(t)
716 exec := setupCreateExec(t, testClient)
718 _, err := exec(`1 --internal --file main.go --line 42 -m "hi"`)
719 require.Error(t, err)
720 assert.Contains(t, err.Error(), "none of the others can be")
721 })
724func Test_cmdCreate_reply_prompt(t *testing.T) {
725 // NOTE: This test cannot run in parallel because the huh form library
726 // uses global state (charmbracelet/bubbles runeutil sanitizer).
728 const fullID = "abc12345deadbeef1234567890abcdef12345678"
730 t.Run("message provided via prompt", func(t *testing.T) {
731 testClient := setupMR(t)
733 testClient.MockDiscussions.EXPECT().
734 ListMergeRequestDiscussions("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
735 Return([]*gitlab.Discussion{{ID: fullID}}, nil, nil)
737 testClient.MockDiscussions.EXPECT().
738 AddMergeRequestDiscussionNote("OWNER/REPO", int64(1), fullID, gomock.Any(), gomock.Any()).
739 DoAndReturn(func(pid any, mrIID int64, discID string, opts *gitlab.AddMergeRequestDiscussionNoteOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Note, *gitlab.Response, error) {
740 assert.Equal(t, "prompted reply", *opts.Body)
741 return &gitlab.Note{ID: 950}, nil, nil
742 })
744 c := ugh.New(t)
745 c.Expect(ugh.Input("Note message:")).
746 Do(ugh.Type("prompted reply"))
748 exec := cmdtest.SetupCmdForTest(t, NewCmdCreate, true,
749 cmdtest.WithGitLabClient(testClient.Client),
750 cmdtest.WithBaseRepo("OWNER", "REPO", ""),
751 cmdtest.WithConfig(config.NewFromString("editor: vi")),
752 cmdtest.WithConsole(t, c),
753 )
755 output, err := exec(`1 --reply ` + fullID)
756 require.NoError(t, err)
757 assert.Empty(t, output.Stderr())
758 assert.Contains(t, output.String(), "https://gitlab.com/OWNER/REPO/merge_requests/1#note_950")
759 })
762func Test_cmdCreate_stdin(t *testing.T) {
763 t.Parallel()
765 tests := []struct {
766 name string
767 stdin string
768 wantErr string
769 expectedOut string
770 }{
771 {
772 name: "reads body from stdin when not a TTY",
773 stdin: "Message from stdin\n",
774 expectedOut: "https://gitlab.com/OWNER/REPO/merge_requests/1#note_700\n",
775 },
776 {
777 name: "empty stdin produces error",
778 stdin: "",
779 wantErr: "aborted: note has an empty message",
780 },
781 }
783 for _, tt := range tests {
784 t.Run(tt.name, func(t *testing.T) {
785 t.Parallel()
787 testClient := setupMR(t)
789 if tt.wantErr == "" {
790 testClient.MockDiscussions.EXPECT().
791 CreateMergeRequestDiscussion("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
792 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
793 assert.Equal(t, "Message from stdin", *opts.Body)
794 return &gitlab.Discussion{
795 ID: "disc-stdin",
796 Notes: []*gitlab.Note{
797 {ID: 700, NoteableID: 1, NoteableType: "MergeRequest", NoteableIID: 1},
798 },
799 }, nil, nil
800 })
801 }
803 exec := cmdtest.SetupCmdForTest(t, NewCmdCreate, false,
804 cmdtest.WithGitLabClient(testClient.Client),
805 cmdtest.WithBaseRepo("OWNER", "REPO", ""),
806 cmdtest.WithConfig(config.NewFromString("editor: vi")),
807 cmdtest.WithStdin(tt.stdin),
808 )
810 output, err := exec(`1`)
811 if tt.wantErr != "" {
812 require.Error(t, err)
813 assert.Equal(t, tt.wantErr, err.Error())
814 return
815 }
816 require.NoError(t, err)
817 assert.Equal(t, tt.expectedOut, output.String())
818 })
819 }
822func Test_cmdCreate_diffComment(t *testing.T) {
823 t.Parallel()
825 t.Run("diff comment on new-side line", func(t *testing.T) {
826 t.Parallel()
828 testClient := setupMR(t)
829 makeDiffVersion(t, testClient)
831 testClient.MockDiscussions.EXPECT().
832 CreateMergeRequestDiscussion("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
833 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
834 assert.Equal(t, "Comment on new line", *opts.Body)
835 require.NotNil(t, opts.Position)
836 assert.Equal(t, int64(2), *opts.Position.NewLine)
837 return &gitlab.Discussion{
838 ID: "disc-diff-1",
839 Notes: []*gitlab.Note{
840 {ID: 500},
841 },
842 }, nil, nil
843 })
845 exec := setupCreateExec(t, testClient)
847 output, err := exec(`1 --file main.go --line 2 -m "Comment on new line"`)
848 require.NoError(t, err)
849 assert.Contains(t, output.String(), "#note_500")
850 })
852 t.Run("diff comment on old-side line", func(t *testing.T) {
853 t.Parallel()
855 testClient := setupMR(t)
856 makeDiffVersion(t, testClient)
858 testClient.MockDiscussions.EXPECT().
859 CreateMergeRequestDiscussion("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
860 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
861 require.NotNil(t, opts.Position)
862 assert.Equal(t, int64(2), *opts.Position.OldLine)
863 return &gitlab.Discussion{
864 ID: "disc-diff-2",
865 Notes: []*gitlab.Note{
866 {ID: 501},
867 },
868 }, nil, nil
869 })
871 exec := setupCreateExec(t, testClient)
873 output, err := exec(`1 --file main.go --old-line 2 -m "Comment on removed line"`)
874 require.NoError(t, err)
875 assert.Contains(t, output.String(), "#note_501")
876 })
878 t.Run("diff comment with multiline range", func(t *testing.T) {
879 t.Parallel()
881 testClient := setupMR(t)
882 makeDiffVersion(t, testClient)
884 testClient.MockDiscussions.EXPECT().
885 CreateMergeRequestDiscussion("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
886 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
887 require.NotNil(t, opts.Position)
888 require.NotNil(t, opts.Position.LineRange)
889 assert.NotNil(t, opts.Position.LineRange.Start)
890 assert.NotNil(t, opts.Position.LineRange.End)
891 return &gitlab.Discussion{
892 ID: "disc-diff-3",
893 Notes: []*gitlab.Note{
894 {ID: 502},
895 },
896 }, nil, nil
897 })
899 exec := setupCreateExec(t, testClient)
901 output, err := exec(`1 --file main.go --line 2:3 -m "Range comment"`)
902 require.NoError(t, err)
903 assert.Contains(t, output.String(), "#note_502")
904 })
906 t.Run("file-level diff comment (no line)", func(t *testing.T) {
907 t.Parallel()
909 testClient := setupMR(t)
910 makeDiffVersion(t, testClient)
912 testClient.MockDiscussions.EXPECT().
913 CreateMergeRequestDiscussion("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
914 DoAndReturn(func(pid any, mrIID int64, opts *gitlab.CreateMergeRequestDiscussionOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Discussion, *gitlab.Response, error) {
915 require.NotNil(t, opts.Position)
916 assert.Equal(t, "text", *opts.Position.PositionType)
917 return &gitlab.Discussion{
918 ID: "disc-diff-4",
919 Notes: []*gitlab.Note{
920 {ID: 503},
921 },
922 }, nil, nil
923 })
925 exec := setupCreateExec(t, testClient)
927 output, err := exec(`1 --file main.go -m "File-level comment"`)
928 require.NoError(t, err)
929 assert.Contains(t, output.String(), "#note_503")
930 })
932 t.Run("file not found in diff", func(t *testing.T) {
933 t.Parallel()
935 testClient := setupMR(t)
936 makeDiffVersion(t, testClient)
938 exec := setupCreateExec(t, testClient)
940 _, err := exec(`1 --file nonexistent.go --line 1 -m "bad file"`)
941 require.Error(t, err)
942 assert.Contains(t, err.Error(), "not found in MR diff")
943 })
945 t.Run("invalid line format fails before any API call", func(t *testing.T) {
946 t.Parallel()
948 testClient := gitlabtesting.NewTestClient(t)
950 exec := setupCreateExec(t, testClient)
952 _, err := exec(`1 --file main.go --line abc -m "bad line"`)
953 require.Error(t, err)
954 assert.Contains(t, err.Error(), `invalid argument "abc" for "--line" flag: invalid line number "abc"`)
955 })
957 t.Run("--line without --file", func(t *testing.T) {
958 t.Parallel()
960 testClient := setupMR(t)
962 exec := setupCreateExec(t, testClient)
964 _, err := exec(`1 --line 5 -m "test"`)
965 require.Error(t, err)
966 assert.Contains(t, err.Error(), "--line and --old-line require --file")
967 })
969 t.Run("--old-line without --file", func(t *testing.T) {
970 t.Parallel()
972 testClient := setupMR(t)
974 exec := setupCreateExec(t, testClient)
976 _, err := exec(`1 --old-line 3 -m "test"`)
977 require.Error(t, err)
978 assert.Contains(t, err.Error(), "--line and --old-line require --file")
979 })
982// --- test helpers ---
984func setupMR(t *testing.T) *gitlabtesting.TestClient {
985 t.Helper()
986 testClient := gitlabtesting.NewTestClient(t)
987 mockMR1(t, testClient)
988 return testClient
991func makeDiffVersion(t *testing.T, testClient *gitlabtesting.TestClient) {
992 t.Helper()
993 diffContent := `@@ -1,5 +1,6 @@
994 line1
995-old line2
996+new line2
997+added line3
998 line4
999 line5
1001 testClient.MockMergeRequests.EXPECT().
1002 GetMergeRequestDiffVersions("OWNER/REPO", int64(1), gomock.Any(), gomock.Any()).
1003 Return([]*gitlab.MergeRequestDiffVersion{
1004 {ID: 10, BaseCommitSHA: "base", HeadCommitSHA: "head", StartCommitSHA: "start"},
1005 }, nil, nil)
1007 testClient.MockMergeRequests.EXPECT().
1008 GetSingleMergeRequestDiffVersion("OWNER/REPO", int64(1), int64(10), gomock.Any(), gomock.Any()).
1009 Return(&gitlab.MergeRequestDiffVersion{
1010 ID: 10,
1011 BaseCommitSHA: "base",
1012 HeadCommitSHA: "head",
1013 StartCommitSHA: "start",
1014 Diffs: []*gitlab.Diff{
1016 NewPath: "main.go",
1017 OldPath: "main.go",
1018 Diff: diffContent,
1019 },
1020 },
1021 }, nil, nil)
1024func setupMRNotFound(t *testing.T) *gitlabtesting.TestClient {
1025 t.Helper()
1026 testClient := gitlabtesting.NewTestClient(t)
1027 notFoundResp := &gitlab.Response{
1028 Response: &http.Response{StatusCode: http.StatusNotFound},
1030 testClient.MockMergeRequests.EXPECT().
1031 GetMergeRequest("OWNER/REPO", int64(122), gomock.Any()).
1032 Return(nil, notFoundResp, gitlab.ErrNotFound)
1033 return testClient
1036func setupCreateExec(t *testing.T, testClient *gitlabtesting.TestClient) cmdtest.CmdExecFunc {
1037 t.Helper()
1038 return cmdtest.SetupCmdForTest(t, NewCmdCreate, true,
1039 cmdtest.WithGitLabClient(testClient.Client),
1040 cmdtest.WithBaseRepo("OWNER", "REPO", ""),
1041 cmdtest.WithConfig(config.NewFromString("editor: vi")),
1045func setupCreateExecWithRepoOverride(t *testing.T, testClient *gitlabtesting.TestClient, isTTY bool, opts ...cmdtest.FactoryOption) cmdtest.CmdExecFunc {
1046 t.Helper()
1048 factoryOpts := []cmdtest.FactoryOption{
1049 cmdtest.WithGitLabClient(testClient.Client),
1050 cmdtest.WithBaseRepo("WRONG", "REPO", ""),
1051 cmdtest.WithConfig(config.NewFromString("editor: vi")),
1053 factoryOpts = append(factoryOpts, opts...)
1055 return cmdtest.SetupCmdForTest(t, func(f cmdutils.Factory) *cobra.Command {
1056 cmd := NewCmdCreate(f)
1057 cmdutils.AddGlobalRepoOverride(cmd, f)
1058 return cmd
1059 }, isTTY, factoryOpts...)
Diagnostics8 git calls · 220 ms
CallStatusSizeTime0220 ms
discover200185 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB · hit8 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=8
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit5 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=5
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchtree:02001.8 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1857
git.pkt.payload.max=1830
git.sideband.band1.bytes=1830
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1830
git.pack.trailer=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200746 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=746
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=f3d413a22af5a9c2fe9aa49709b1cb36d1351a7f
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=746
git.pkt.payload.max=719
git.sideband.band1.bytes=719
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=719
git.pack.trailer=330baf80c59a4208b55120dff7dd824b7952b790
Open pack map
fetchtree:0200540 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=540
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=d1be7f980a856805fa31e30e01fff4db335cbe1b
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=540
git.pkt.payload.max=513
git.sideband.band1.bytes=513
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=513
git.pack.trailer=6c82398efd91c9e023d583b948fde889bd4991b2
Open pack map
fetch2004.3 KiB204 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=204
git.response.bytes=4426
git.response.cache=MISS
git.response.duration_ms=204
git.fetch.wants=6881e3843450b3c871e6feff61b4eb260402870a
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=4426
git.pkt.payload.max=4399
git.sideband.band1.bytes=4399
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e2c6977d174afc
Request
dd08471e…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format