GitLabgitlab-org

cli

main
ply8 git calls273 ms101 KiB6 cachedprotocol v2
777 lines22 KiBRaw
1//go:build !integration
3package get
5import (
6 "net/http"
7 "testing"
8 "time"
10 "github.com/stretchr/testify/assert"
11 "github.com/stretchr/testify/require"
12 "go.uber.org/mock/gomock"
14 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
15 gitlabtesting "gitlab.com/gitlab-org/api/client-go/v3/testing"
17 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
20func TestCIGet(t *testing.T) {
21 t.Parallel()
23 createdAt, _ := time.Parse(time.RFC3339, "2023-10-10T00:00:00Z")
24 startedAt, _ := time.Parse(time.RFC3339, "2023-10-10T00:00:00Z")
25 updatedAt, _ := time.Parse(time.RFC3339, "2023-10-10T00:00:00Z")
27 // Response indicating last page
28 lastPageResponse := &gitlab.Response{
29 Response: &http.Response{StatusCode: http.StatusOK},
30 NextPage: 0,
31 }
33 type testCase struct {
34 name string
35 args string
36 expectedOut string
37 setupMock func(tc *gitlabtesting.TestClient)
38 }
40 tests := []testCase{
41 {
42 name: "when get is called on an existing pipeline",
43 args: "-p=123 -b=main",
44 expectedOut: `# Pipeline:
45id: 123
46status: pending
47source: push
48ref: main
49sha: 0ff3ae198f8601a285adcf5c0fff204ee6fba5fd
50tag: false
51yaml Errors: -
52user: test
53created: 2023-10-10 00:00:00 +0000 UTC
54started: 2023-10-10 00:00:00 +0000 UTC
55updated: 2023-10-10 00:00:00 +0000 UTC
57# Jobs:
59`,
60 setupMock: func(tc *gitlabtesting.TestClient) {
61 tc.MockPipelines.EXPECT().
62 GetPipeline("OWNER/REPO", int64(123)).
63 Return(&gitlab.Pipeline{
64 ID: 123,
65 IID: 123,
66 Status: "pending",
67 Source: "push",
68 Ref: "main",
69 SHA: "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
70 User: &gitlab.BasicUser{Username: "test"},
71 YamlErrors: "-",
72 CreatedAt: &createdAt,
73 StartedAt: &startedAt,
74 UpdatedAt: &updatedAt,
75 }, nil, nil)
76 tc.MockJobs.EXPECT().
77 ListPipelineJobs("OWNER/REPO", int64(123), gomock.Any(), gomock.Any()).
78 Return([]*gitlab.Job{}, lastPageResponse, nil)
79 },
80 },
81 {
82 name: "when get is called on missing pipeline",
83 args: "-b=main",
84 expectedOut: `# Pipeline:
85id: 123
86status: pending
87source: push
88ref: main
89sha: 0ff3ae198f8601a285adcf5c0fff204ee6fba5fd
90tag: false
91yaml Errors: -
92user: test
93created: 2023-10-10 00:00:00 +0000 UTC
94started: 2023-10-10 00:00:00 +0000 UTC
95updated: 2023-10-10 00:00:00 +0000 UTC
97# Jobs:
99`,
100 setupMock: func(tc *gitlabtesting.TestClient) {
101 // GetPipelineWithFallback first tries GetLatestPipeline
102 tc.MockPipelines.EXPECT().
103 GetLatestPipeline("OWNER/REPO", gomock.Any(), gomock.Any()).
104 Return(&gitlab.Pipeline{
105 ID: 123,
106 IID: 123,
107 Status: "pending",
108 Source: "push",
109 Ref: "main",
110 SHA: "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
111 User: &gitlab.BasicUser{Username: "test"},
112 YamlErrors: "-",
113 CreatedAt: &createdAt,
114 StartedAt: &startedAt,
115 UpdatedAt: &updatedAt,
116 }, nil, nil)
117 // Check if pipeline has jobs
118 tc.MockJobs.EXPECT().
119 ListPipelineJobs("OWNER/REPO", int64(123), gomock.Any()).
120 Return([]*gitlab.Job{
121 {ID: 1, Name: "test"}, // Pipeline has jobs, so it's valid
122 }, nil, nil)
123 // Then GetPipeline is called to get full pipeline details
124 tc.MockPipelines.EXPECT().
125 GetPipeline("OWNER/REPO", int64(123)).
126 Return(&gitlab.Pipeline{
127 ID: 123,
128 IID: 123,
129 Status: "pending",
130 Source: "push",
131 Ref: "main",
132 SHA: "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
133 User: &gitlab.BasicUser{Username: "test"},
134 YamlErrors: "-",
135 CreatedAt: &createdAt,
136 StartedAt: &startedAt,
137 UpdatedAt: &updatedAt,
138 }, nil, nil)
139 // Finally ListPipelineJobs is called to get all jobs for display
140 tc.MockJobs.EXPECT().
141 ListPipelineJobs("OWNER/REPO", int64(123), gomock.Any(), gomock.Any()).
142 Return([]*gitlab.Job{}, lastPageResponse, nil)
143 },
144 },
145 {
146 name: "when get is called on an existing pipeline with job text",
147 args: "-p=123 -b=main",
148 expectedOut: `# Pipeline:
149id: 123
150status: pending
151source: push
152ref: main
153sha: 0ff3ae198f8601a285adcf5c0fff204ee6fba5fd
154tag: false
155yaml Errors: -
156user: test
157created: 2023-10-10 00:00:00 +0000 UTC
158started: 2023-10-10 00:00:00 +0000 UTC
159updated: 2023-10-10 00:00:00 +0000 UTC
161# Jobs:
162publish: failed
164`,
165 setupMock: func(tc *gitlabtesting.TestClient) {
166 tc.MockPipelines.EXPECT().
167 GetPipeline("OWNER/REPO", int64(123)).
168 Return(&gitlab.Pipeline{
169 ID: 123,
170 IID: 123,
171 Status: "pending",
172 Source: "push",
173 Ref: "main",
174 SHA: "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
175 User: &gitlab.BasicUser{Username: "test"},
176 YamlErrors: "-",
177 CreatedAt: &createdAt,
178 StartedAt: &startedAt,
179 UpdatedAt: &updatedAt,
180 }, nil, nil)
181 tc.MockJobs.EXPECT().
182 ListPipelineJobs("OWNER/REPO", int64(123), gomock.Any(), gomock.Any()).
183 Return([]*gitlab.Job{
184 {
185 ID: 123,
186 Name: "publish",
187 Status: "failed",
188 },
189 }, lastPageResponse, nil)
190 },
191 },
192 {
193 name: "when get is called on an existing pipeline with job details",
194 args: "-p=123 -b=main --with-job-details",
195 expectedOut: `# Pipeline:
196id: 123
197status: pending
198source: push
199ref: main
200sha: 0ff3ae198f8601a285adcf5c0fff204ee6fba5fd
201tag: false
202yaml Errors: -
203user: test
204created: 2023-10-10 00:00:00 +0000 UTC
205started: 2023-10-10 00:00:00 +0000 UTC
206updated: 2023-10-10 00:00:00 +0000 UTC
208# Jobs:
209ID Name Stage Status Duration Failure reason URL
210123 publish failed 0 bad timing
212`,
213 setupMock: func(tc *gitlabtesting.TestClient) {
214 tc.MockPipelines.EXPECT().
215 GetPipeline("OWNER/REPO", int64(123)).
216 Return(&gitlab.Pipeline{
217 ID: 123,
218 IID: 123,
219 Status: "pending",
220 Source: "push",
221 Ref: "main",
222 SHA: "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
223 User: &gitlab.BasicUser{Username: "test"},
224 YamlErrors: "-",
225 CreatedAt: &createdAt,
226 StartedAt: &startedAt,
227 UpdatedAt: &updatedAt,
228 }, nil, nil)
229 tc.MockJobs.EXPECT().
230 ListPipelineJobs("OWNER/REPO", int64(123), gomock.Any(), gomock.Any()).
231 Return([]*gitlab.Job{
232 {
233 ID: 123,
234 Name: "publish",
235 Status: "failed",
236 FailureReason: "bad timing",
237 },
238 }, lastPageResponse, nil)
239 },
240 },
241 {
242 name: "when get is called on an existing pipeline with variables",
243 args: "-p=123 -b=main --with-variables",
244 expectedOut: `# Pipeline:
245id: 123
246status: pending
247source: push
248ref: main
249sha: 0ff3ae198f8601a285adcf5c0fff204ee6fba5fd
250tag: false
251yaml Errors: -
252user: test
253created: 2023-10-10 00:00:00 +0000 UTC
254started: 2023-10-10 00:00:00 +0000 UTC
255updated: 2023-10-10 00:00:00 +0000 UTC
257# Jobs:
259# Variables:
260RUN_NIGHTLY_BUILD: true
262`,
263 setupMock: func(tc *gitlabtesting.TestClient) {
264 tc.MockPipelines.EXPECT().
265 GetPipeline("OWNER/REPO", int64(123)).
266 Return(&gitlab.Pipeline{
267 ID: 123,
268 IID: 123,
269 ProjectID: 5,
270 Status: "pending",
271 Source: "push",
272 Ref: "main",
273 SHA: "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
274 User: &gitlab.BasicUser{Username: "test"},
275 YamlErrors: "-",
276 CreatedAt: &createdAt,
277 StartedAt: &startedAt,
278 UpdatedAt: &updatedAt,
279 }, nil, nil)
280 tc.MockJobs.EXPECT().
281 ListPipelineJobs("OWNER/REPO", int64(123), gomock.Any(), gomock.Any()).
282 Return([]*gitlab.Job{}, lastPageResponse, nil)
283 tc.MockPipelines.EXPECT().
284 GetPipelineVariables(int64(5), int64(123)).
285 Return([]*gitlab.PipelineVariable{
286 {
287 Key: "RUN_NIGHTLY_BUILD",
288 VariableType: "env_var",
289 Value: "true",
290 },
291 }, nil, nil)
292 },
293 },
294 {
295 name: "when get is called on an existing pipeline with variables however no variables are found",
296 args: "-p=123 -b=main --with-variables",
297 expectedOut: `# Pipeline:
298id: 123
299status: pending
300source: push
301ref: main
302sha: 0ff3ae198f8601a285adcf5c0fff204ee6fba5fd
303tag: false
304yaml Errors: -
305user: test
306created: 2023-10-10 00:00:00 +0000 UTC
307started: 2023-10-10 00:00:00 +0000 UTC
308updated: 2023-10-10 00:00:00 +0000 UTC
310# Jobs:
312# Variables:
313No variables found in pipeline.
314`,
315 setupMock: func(tc *gitlabtesting.TestClient) {
316 tc.MockPipelines.EXPECT().
317 GetPipeline("OWNER/REPO", int64(123)).
318 Return(&gitlab.Pipeline{
319 ID: 123,
320 IID: 123,
321 ProjectID: 5,
322 Status: "pending",
323 Source: "push",
324 Ref: "main",
325 SHA: "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
326 User: &gitlab.BasicUser{Username: "test"},
327 YamlErrors: "-",
328 CreatedAt: &createdAt,
329 StartedAt: &startedAt,
330 UpdatedAt: &updatedAt,
331 }, nil, nil)
332 tc.MockJobs.EXPECT().
333 ListPipelineJobs("OWNER/REPO", int64(123), gomock.Any(), gomock.Any()).
334 Return([]*gitlab.Job{}, lastPageResponse, nil)
335 tc.MockPipelines.EXPECT().
336 GetPipelineVariables(int64(5), int64(123)).
337 Return([]*gitlab.PipelineVariable{}, nil, nil)
338 },
339 },
340 {
341 name: "when there is a merged result pipeline and no commit pipeline",
342 args: "-b=main",
343 expectedOut: `# Pipeline:
344id: 123
345status: pending
346source: push
347ref: main
348sha: 0ff3ae198f8601a285adcf5c0fff204ee6fba5fd
349tag: false
350yaml Errors: -
351user: test
352created: 2023-10-10 00:00:00 +0000 UTC
353started: 2023-10-10 00:00:00 +0000 UTC
354updated: 2023-10-10 00:00:00 +0000 UTC
356# Jobs:
358`,
359 setupMock: func(tc *gitlabtesting.TestClient) {
360 // GetPipelineWithFallback first tries GetLatestPipeline (returns pipeline with no jobs)
361 tc.MockPipelines.EXPECT().
362 GetLatestPipeline("OWNER/REPO", gomock.Any(), gomock.Any()).
363 Return(&gitlab.Pipeline{
364 ID: 999, // A different pipeline that has no jobs
365 }, nil, nil)
366 // Check if pipeline has jobs (it doesn't)
367 tc.MockJobs.EXPECT().
368 ListPipelineJobs("OWNER/REPO", int64(999), gomock.Any()).
369 Return([]*gitlab.Job{}, nil, nil)
370 // Falls back to MR lookup
371 tc.MockMergeRequests.EXPECT().
372 ListProjectMergeRequests("OWNER/REPO", gomock.Any()).
373 Return([]*gitlab.BasicMergeRequest{
374 {
375 IID: 1,
376 Author: &gitlab.BasicUser{Username: "testuser"},
377 },
378 }, lastPageResponse, nil)
379 tc.MockMergeRequests.EXPECT().
380 GetMergeRequest("OWNER/REPO", int64(1), gomock.Any()).
381 Return(&gitlab.MergeRequest{
382 HeadPipeline: &gitlab.Pipeline{
383 ID: 123,
384 },
385 }, nil, nil)
386 // GetPipeline to get full MR pipeline details (called by GetPipelineWithFallback)
387 tc.MockPipelines.EXPECT().
388 GetPipeline("OWNER/REPO", int64(123), gomock.Any()).
389 Return(&gitlab.Pipeline{
390 ID: 123,
391 IID: 123,
392 ProjectID: 5,
393 Status: "pending",
394 Source: "push",
395 Ref: "main",
396 SHA: "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
397 User: &gitlab.BasicUser{Username: "test"},
398 YamlErrors: "-",
399 CreatedAt: &createdAt,
400 StartedAt: &startedAt,
401 UpdatedAt: &updatedAt,
402 }, nil, nil)
403 // Then GetPipeline is called again to get full pipeline details for display
404 tc.MockPipelines.EXPECT().
405 GetPipeline("OWNER/REPO", int64(123)).
406 Return(&gitlab.Pipeline{
407 ID: 123,
408 IID: 123,
409 ProjectID: 5,
410 Status: "pending",
411 Source: "push",
412 Ref: "main",
413 SHA: "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
414 User: &gitlab.BasicUser{Username: "test"},
415 YamlErrors: "-",
416 CreatedAt: &createdAt,
417 StartedAt: &startedAt,
418 UpdatedAt: &updatedAt,
419 }, nil, nil)
420 // Finally ListPipelineJobs is called to get all jobs for display
421 tc.MockJobs.EXPECT().
422 ListPipelineJobs("OWNER/REPO", int64(123), gomock.Any(), gomock.Any()).
423 Return([]*gitlab.Job{}, lastPageResponse, nil)
424 },
425 },
426 {
427 name: "when --merge-request flag is used to get pipeline from merge request",
428 args: "--merge-request=42",
429 expectedOut: `# Pipeline:
430id: 123
431status: failed
432source: merge_request_event
433ref: feature-branch
434sha: 0ff3ae198f8601a285adcf5c0fff204ee6fba5fd
435tag: false
436yaml Errors: -
437user: test
438created: 2023-10-10 00:00:00 +0000 UTC
439started: 2023-10-10 00:00:00 +0000 UTC
440updated: 2023-10-10 00:00:00 +0000 UTC
442# Jobs:
443build: success
444test: failed
446`,
447 setupMock: func(tc *gitlabtesting.TestClient) {
448 tc.MockMergeRequests.EXPECT().
449 GetMergeRequest("OWNER/REPO", int64(42), gomock.Any()).
450 Return(&gitlab.MergeRequest{
451 BasicMergeRequest: gitlab.BasicMergeRequest{IID: 42},
452 HeadPipeline: &gitlab.Pipeline{
453 ID: 123,
454 },
455 }, nil, nil)
456 tc.MockPipelines.EXPECT().
457 GetPipeline("OWNER/REPO", int64(123)).
458 Return(&gitlab.Pipeline{
459 ID: 123,
460 IID: 123,
461 Status: "failed",
462 Source: "merge_request_event",
463 Ref: "feature-branch",
464 SHA: "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
465 User: &gitlab.BasicUser{Username: "test"},
466 YamlErrors: "-",
467 CreatedAt: &createdAt,
468 StartedAt: &startedAt,
469 UpdatedAt: &updatedAt,
470 }, nil, nil)
471 tc.MockJobs.EXPECT().
472 ListPipelineJobs("OWNER/REPO", int64(123), gomock.Any(), gomock.Any()).
473 Return([]*gitlab.Job{
474 {ID: 1, Name: "build", Status: "success"},
475 {ID: 2, Name: "test", Status: "failed"},
476 }, lastPageResponse, nil)
477 },
478 },
479 {
480 name: "when --status=failed --with-job-details shows all failed jobs including allow_failure",
481 args: "-p=123 --status=failed --with-job-details",
482 expectedOut: `# Pipeline:
483id: 123
484status: failed
485source: push
486ref: main
487sha: 0ff3ae198f8601a285adcf5c0fff204ee6fba5fd
488tag: false
489yaml Errors: -
490user: test
491created: 2023-10-10 00:00:00 +0000 UTC
492started: 2023-10-10 00:00:00 +0000 UTC
493updated: 2023-10-10 00:00:00 +0000 UTC
495# Jobs:
496ID Name Stage Status Duration Failure reason URL
4972 test test failed 0 script_failure https://gitlab.com/OWNER/REPO/-/jobs/2
4983 lint test failed 0 script_failure https://gitlab.com/OWNER/REPO/-/jobs/3
4994 flaky test failed 0 script_failure https://gitlab.com/OWNER/REPO/-/jobs/4
501`,
502 setupMock: func(tc *gitlabtesting.TestClient) {
503 tc.MockPipelines.EXPECT().
504 GetPipeline("OWNER/REPO", int64(123)).
505 Return(&gitlab.Pipeline{
506 ID: 123,
507 IID: 123,
508 Status: "failed",
509 Source: "push",
510 Ref: "main",
511 SHA: "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
512 User: &gitlab.BasicUser{Username: "test"},
513 YamlErrors: "-",
514 CreatedAt: &createdAt,
515 StartedAt: &startedAt,
516 UpdatedAt: &updatedAt,
517 }, nil, nil)
518 tc.MockJobs.EXPECT().
519 ListPipelineJobs("OWNER/REPO", int64(123), gomock.Cond(func(opts *gitlab.ListJobsOptions) bool {
520 return opts.Scope != nil && len(*opts.Scope) == 1 && (*opts.Scope)[0] == gitlab.Failed
521 }), gomock.Any()).
522 Return([]*gitlab.Job{
523 {ID: 2, Name: "test", Stage: "test", Status: "failed", FailureReason: "script_failure", WebURL: "https://gitlab.com/OWNER/REPO/-/jobs/2"},
524 {ID: 3, Name: "lint", Stage: "test", Status: "failed", FailureReason: "script_failure", WebURL: "https://gitlab.com/OWNER/REPO/-/jobs/3"},
525 {ID: 4, Name: "flaky", Stage: "test", Status: "failed", FailureReason: "script_failure", WebURL: "https://gitlab.com/OWNER/REPO/-/jobs/4", AllowFailure: true},
526 }, lastPageResponse, nil)
527 },
528 },
529 }
531 for _, tc := range tests {
532 t.Run(tc.name, func(t *testing.T) {
533 t.Parallel()
535 // GIVEN
536 testClient := gitlabtesting.NewTestClient(t)
537 tc.setupMock(testClient)
539 exec := cmdtest.SetupCmdForTest(
540 t,
541 NewCmdGet,
542 false,
543 cmdtest.WithGitLabClient(testClient.Client),
544 )
546 // WHEN
547 output, err := exec(tc.args)
549 // THEN
550 require.NoError(t, err)
551 assert.Equal(t, tc.expectedOut, output.String())
552 assert.Empty(t, output.Stderr())
553 })
554 }
557func TestCIGetMergeRequestErrors(t *testing.T) {
558 t.Parallel()
560 type testCase struct {
561 name string
562 args string
563 setupMock func(tc *gitlabtesting.TestClient)
564 errMsg string
565 }
567 tests := []testCase{
568 {
569 name: "when MR has no head pipeline",
570 args: "--merge-request=42",
571 setupMock: func(tc *gitlabtesting.TestClient) {
572 tc.MockMergeRequests.EXPECT().
573 GetMergeRequest("OWNER/REPO", int64(42), gomock.Any()).
574 Return(&gitlab.MergeRequest{
575 BasicMergeRequest: gitlab.BasicMergeRequest{IID: 42},
576 HeadPipeline: nil,
577 }, nil, nil)
578 },
579 errMsg: "no pipeline found for merge request !42",
580 },
581 {
582 name: "when MR head pipeline has zero ID",
583 args: "--merge-request=42",
584 setupMock: func(tc *gitlabtesting.TestClient) {
585 tc.MockMergeRequests.EXPECT().
586 GetMergeRequest("OWNER/REPO", int64(42), gomock.Any()).
587 Return(&gitlab.MergeRequest{
588 BasicMergeRequest: gitlab.BasicMergeRequest{IID: 42},
589 HeadPipeline: &gitlab.Pipeline{ID: 0},
590 }, nil, nil)
591 },
592 errMsg: "no pipeline found for merge request !42",
593 },
594 }
596 for _, tc := range tests {
597 t.Run(tc.name, func(t *testing.T) {
598 t.Parallel()
600 testClient := gitlabtesting.NewTestClient(t)
601 tc.setupMock(testClient)
603 exec := cmdtest.SetupCmdForTest(
604 t,
605 NewCmdGet,
606 false,
607 cmdtest.WithGitLabClient(testClient.Client),
608 )
610 _, err := exec(tc.args)
611 require.Error(t, err)
612 assert.Contains(t, err.Error(), tc.errMsg)
613 })
614 }
617func TestCIGetJSON(t *testing.T) {
618 t.Parallel()
620 createdAt, _ := time.Parse(time.RFC3339, "2022-01-20T21:47:16.276Z")
621 startedAt, _ := time.Parse(time.RFC3339, "2022-01-20T21:47:17.448Z")
622 updatedAt, _ := time.Parse(time.RFC3339, "2022-01-20T21:47:31.358Z")
623 finishedAt, _ := time.Parse(time.RFC3339, "2022-01-20T21:47:31.35Z")
625 jobCreatedAt, _ := time.Parse(time.RFC3339, "2022-01-20T21:47:16.291Z")
626 jobStartedAt, _ := time.Parse(time.RFC3339, "2022-01-20T21:47:16.693Z")
627 jobFinishedAt, _ := time.Parse(time.RFC3339, "2022-01-20T21:47:31.274Z")
629 // Response indicating last page
630 lastPageResponse := &gitlab.Response{
631 Response: &http.Response{StatusCode: http.StatusOK},
632 NextPage: 0,
633 }
635 type testCase struct {
636 name string
637 args string
638 setupMock func(tc *gitlabtesting.TestClient)
639 }
641 tests := []testCase{
642 {
643 name: "when getting JSON for pipeline",
644 args: "-p 452959326 -F json -b main",
645 setupMock: func(tc *gitlabtesting.TestClient) {
646 tc.MockPipelines.EXPECT().
647 GetPipeline("OWNER/REPO", int64(452959326)).
648 Return(&gitlab.Pipeline{
649 ID: 452959326,
650 IID: 14,
651 ProjectID: 29316529,
652 SHA: "44eb489568f7cb1a5a730fce6b247cd3797172ca",
653 Ref: "1-fake-issue-3",
654 Status: "success",
655 Source: "push",
656 CreatedAt: &createdAt,
657 UpdatedAt: &updatedAt,
658 StartedAt: &startedAt,
659 FinishedAt: &finishedAt,
660 BeforeSHA: "001eb421e586a3f07f90aea102c8b2d4068ab5b6",
661 Tag: false,
662 User: &gitlab.BasicUser{
663 ID: 8814129,
664 Username: "OWNER",
665 Name: "Some User",
666 State: "active",
667 AvatarURL: "https://gitlab.com/uploads/-/system/user/avatar/8814129/avatar.png",
668 WebURL: "https://gitlab.com/OWNER",
669 },
670 WebURL: "https://gitlab.com/OWNER/REPO/-/pipelines/452959326",
671 Duration: 14,
672 QueuedDuration: 1,
673 DetailedStatus: &gitlab.DetailedStatus{
674 Icon: "status_success",
675 Text: "Passed",
676 Label: "passed",
677 Group: "success",
678 Tooltip: "passed",
679 HasDetails: true,
680 DetailsPath: "/OWNER/REPO/-/pipelines/452959326",
681 Favicon: "/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png",
682 },
683 }, nil, nil)
684 tc.MockJobs.EXPECT().
685 ListPipelineJobs("OWNER/REPO", int64(452959326), gomock.Any(), gomock.Any()).
686 Return([]*gitlab.Job{
687 {
688 ID: 1999017704,
689 Status: "success",
690 Stage: "test",
691 Name: "test_vars",
692 Ref: "1-fake-issue-3",
693 Tag: false,
694 AllowFailure: false,
695 CreatedAt: &jobCreatedAt,
696 StartedAt: &jobStartedAt,
697 FinishedAt: &jobFinishedAt,
698 Duration: 14.580467,
699 QueuedDuration: 0.211715,
700 User: &gitlab.User{
701 ID: 8814129,
702 Username: "OWNER",
703 Name: "Some User",
704 State: "active",
705 Locked: false,
706 AvatarURL: "https://gitlab.com/uploads/-/system/user/avatar/8814129/avatar.png",
707 WebURL: "https://gitlab.com/OWNER",
708 },
709 Commit: &gitlab.Commit{
710 ID: "44eb489568f7cb1a5a730fce6b247cd3797172ca",
711 ShortID: "44eb4895",
712 Title: "Add new file",
713 AuthorName: "Some User",
714 AuthorEmail: "OWNER@gitlab.com",
715 CommitterName: "Some User",
716 CommitterEmail: "OWNER@gitlab.com",
717 Message: "Add new file",
718 ParentIDs: []string{"001eb421e586a3f07f90aea102c8b2d4068ab5b6"},
719 WebURL: "https://gitlab.com/OWNER/REPO/-/commit/44eb489568f7cb1a5a730fce6b247cd3797172ca",
720 },
721 Pipeline: gitlab.JobPipeline{
722 ID: 452959326,
723 ProjectID: 29316529,
724 Sha: "44eb489568f7cb1a5a730fce6b247cd3797172ca",
725 Ref: "1-fake-issue-3",
726 Status: "success",
727 },
728 WebURL: "https://gitlab.com/OWNER/REPO/-/jobs/1999017704",
729 Runner: gitlab.JobRunner{
730 ID: 12270859,
731 Description: "5-green.saas-linux-small-amd64.runners-manager.gitlab.com/default",
732 Active: true,
733 IsShared: true,
734 Name: "gitlab-runner",
735 },
736 Artifacts: []gitlab.JobArtifact{
737 {
738 FileType: "trace",
739 Filename: "job.log",
740 Size: 2770,
741 },
742 },
743 },
744 }, lastPageResponse, nil)
745 },
746 },
747 }
749 for _, tc := range tests {
750 t.Run(tc.name, func(t *testing.T) {
751 t.Parallel()
753 // GIVEN
754 testClient := gitlabtesting.NewTestClient(t)
755 tc.setupMock(testClient)
757 exec := cmdtest.SetupCmdForTest(
758 t,
759 NewCmdGet,
760 false,
761 cmdtest.WithGitLabClient(testClient.Client),
762 )
764 // WHEN
765 output, err := exec(tc.args)
767 // THEN
768 require.NoError(t, err)
769 // Verify it's valid JSON that contains expected fields
770 assert.Contains(t, output.String(), `"id":452959326`)
771 assert.Contains(t, output.String(), `"status":"success"`)
772 assert.Contains(t, output.String(), `"jobs":[`)
773 assert.Contains(t, output.String(), `"test_vars"`)
774 assert.Empty(t, output.Stderr())
775 })
776 }
Diagnostics8 git calls · 273 ms
CallStatusSizeTime0273 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
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 · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=3
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
fetchtree:0 · deepen 1020032 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=3
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
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=3
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:02001.8 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=3
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:0200635 B · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=635
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=517b073a0d5c32bc4e93f86de74b31d60ff8cf03
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=635
git.pkt.payload.max=608
git.sideband.band1.bytes=608
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=608
git.pack.trailer=178abb9456d874b7fd38fa21ad5cf9ca3ebcccaa
Open pack map
fetchtree:0200168 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=168
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=27ab403515eea5ea023c3d05cac03519511924a7
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=168
git.pkt.payload.max=141
git.sideband.band1.bytes=141
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=141
git.pack.trailer=7b9f6926f037354e3f8f733893a53ab7f0c64635
Open pack map
fetch2003.5 KiB257 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=257
git.response.bytes=3571
git.response.cache=MISS
git.response.duration_ms=257
git.fetch.wants=e60efef05bfe1a0ce51d4181b44d5886b2c3f172
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=3571
git.pkt.payload.max=3544
git.sideband.band1.bytes=3544
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
a5e2db0b9be5c125
Request
1db2b462…
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