-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathforges_test.go
More file actions
1086 lines (935 loc) · 27.5 KB
/
forges_test.go
File metadata and controls
1086 lines (935 loc) · 27.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package forges
import (
"context"
"fmt"
"io"
"net/http"
"net/http/httptest"
"os"
"testing"
)
func assertEqual(t *testing.T, field, want, got string) {
t.Helper()
if want != got {
t.Errorf("%s: want %q, got %q", field, want, got)
}
}
func assertSliceEqual(t *testing.T, field string, want, got []string) {
t.Helper()
if len(want) != len(got) {
t.Errorf("%s: want %v, got %v", field, want, got)
return
}
for i := range want {
if want[i] != got[i] {
t.Errorf("%s[%d]: want %q, got %q", field, i, want[i], got[i])
}
}
}
// ParseRepoURL tests
func TestParseRepoURL(t *testing.T) {
tests := []struct {
input string
domain, owner, repo string
wantErr bool
}{
{
input: "https://github.com/octocat/hello-world",
domain: "github.com", owner: "octocat", repo: "hello-world",
},
{
input: "https://github.com/octocat/hello-world.git",
domain: "github.com", owner: "octocat", repo: "hello-world",
},
{
input: "https://gitlab.com/group/project/tree/main",
domain: "gitlab.com", owner: "group", repo: "project",
},
{
input: "github.com/user/repo",
domain: "github.com", owner: "user", repo: "repo",
},
{
input: "git@github.com:user/repo.git",
domain: "github.com", owner: "user", repo: "repo",
},
{
input: "git@gitlab.com:group/project.git",
domain: "gitlab.com", owner: "group", repo: "project",
},
{
input: "https://bitbucket.org/atlassian/stash-example-plugin",
domain: "bitbucket.org", owner: "atlassian", repo: "stash-example-plugin",
},
{
input: "",
wantErr: true,
},
{
input: "https://github.com/just-owner",
wantErr: true,
},
{
input: "git@github.com",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
domain, owner, repo, err := ParseRepoURL(tt.input)
if tt.wantErr {
if err == nil {
t.Fatal("expected error, got nil")
}
return
}
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
assertEqual(t, "domain", tt.domain, domain)
assertEqual(t, "owner", tt.owner, owner)
assertEqual(t, "repo", tt.repo, repo)
})
}
}
// Client routing tests
func TestClientRouting(t *testing.T) {
mock := &mockForge{repoService: &mockRepoService{}}
c := NewClient(
WithForge("github.com", mock),
WithForge("gitlab.com", mock),
)
// Verify registered domains
for _, domain := range []string{"github.com", "gitlab.com"} {
if _, err := c.forgeFor(domain); err != nil {
t.Errorf("expected forge for %s, got error: %v", domain, err)
}
}
// Unregistered domain returns error
_, err := c.forgeFor("example.com")
if err == nil {
t.Error("expected error for unregistered domain")
}
}
func TestClientFetchRepositoryRoutes(t *testing.T) {
mock := &mockForge{
repoService: &mockRepoService{
repo: &Repository{FullName: "test/repo"},
},
}
c := &Client{
forges: map[string]Forge{"example.com": mock},
tokens: make(map[string]string),
}
repo, err := c.FetchRepository(context.Background(), "https://example.com/test/repo")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if repo.FullName != "test/repo" {
t.Errorf("expected test/repo, got %s", repo.FullName)
}
ms := mock.repoService
if ms.lastOwner != "test" || ms.lastRepo != "repo" {
t.Errorf("expected owner=test repo=repo, got owner=%s repo=%s", ms.lastOwner, ms.lastRepo)
}
}
func TestClientFetchTagsRoutes(t *testing.T) {
mock := &mockForge{
repoService: &mockRepoService{
tags: []Tag{{Name: "v1.0.0", Commit: "abc"}},
},
}
c := &Client{
forges: map[string]Forge{"example.com": mock},
tokens: make(map[string]string),
}
tags, err := c.FetchTags(context.Background(), "https://example.com/test/repo")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(tags) != 1 {
t.Fatalf("expected 1 tag, got %d", len(tags))
}
}
// Detection tests
func TestDetectForgeTypeUsesProvidedClient(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-GitHub-Request-Id", "abc123")
w.WriteHeader(http.StatusOK)
}))
defer srv.Close()
// Using a custom client should work.
customClient := srv.Client()
ft, err := detectFromHeaders(context.Background(), customClient, srv.URL)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if ft != GitHub {
t.Errorf("expected GitHub, got %s", ft)
}
}
func TestDetectForgeTypeHeaders(t *testing.T) {
tests := []struct {
header string
value string
want ForgeType
}{
{"X-GitHub-Request-Id", "abc123", GitHub},
{"X-Gitlab-Meta", `{"cors":"abc"}`, GitLab},
{"X-Gitea-Version", "1.21.0", Gitea},
{"X-Forgejo-Version", "7.0.0", Forgejo},
}
for _, tt := range tests {
t.Run(string(tt.want), func(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set(tt.header, tt.value)
w.WriteHeader(http.StatusOK)
}))
defer srv.Close()
ft, err := detectFromHeaders(context.Background(), http.DefaultClient, srv.URL)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if ft != tt.want {
t.Errorf("want %s, got %s", tt.want, ft)
}
})
}
}
func TestDetectForgeTypeGiteaAPI(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
mux.HandleFunc("GET /api/v1/version", func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintf(w, `{"version":"1.21.0"}`)
})
srv := httptest.NewServer(mux)
defer srv.Close()
ft, err := detectFromAPI(context.Background(), http.DefaultClient, srv.URL)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if ft != Gitea {
t.Errorf("want Gitea, got %s", ft)
}
}
func TestDetectForgeTypeForgejoAPI(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
mux.HandleFunc("GET /api/v1/version", func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintf(w, `{"version":"7.0.0+forgejo"}`)
})
srv := httptest.NewServer(mux)
defer srv.Close()
ft, err := detectFromAPI(context.Background(), http.DefaultClient, srv.URL)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if ft != Forgejo {
t.Errorf("want Forgejo, got %s", ft)
}
}
func TestDetectForgeTypeGitLabAPI(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
mux.HandleFunc("GET /api/v1/version", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
})
mux.HandleFunc("GET /api/v4/version", func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintf(w, `{"version":"16.0.0"}`)
})
srv := httptest.NewServer(mux)
defer srv.Close()
ft, err := detectFromAPI(context.Background(), http.DefaultClient, srv.URL)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if ft != GitLab {
t.Errorf("want GitLab, got %s", ft)
}
}
func TestDetectForgeTypeGitHubAPI(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
mux.HandleFunc("GET /api/v1/version", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
})
mux.HandleFunc("GET /api/v4/version", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
})
mux.HandleFunc("GET /api/v3/meta", func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintf(w, `{"verifiable_password_authentication": true}`)
})
srv := httptest.NewServer(mux)
defer srv.Close()
ft, err := detectFromAPI(context.Background(), http.DefaultClient, srv.URL)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if ft != GitHub {
t.Errorf("want GitHub, got %s", ft)
}
}
func TestClientListRepositoriesRoutes(t *testing.T) {
mock := &mockForge{
repoService: &mockRepoService{
repos: []Repository{
{FullName: "org/repo-a"},
{FullName: "org/repo-b"},
},
},
}
c := &Client{
forges: map[string]Forge{"example.com": mock},
tokens: make(map[string]string),
}
repos, err := c.ListRepositories(context.Background(), "example.com", "org", ListRepoOpts{})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(repos) != 2 {
t.Fatalf("expected 2 repos, got %d", len(repos))
}
if mock.repoService.lastOwner != "org" {
t.Errorf("expected owner=org, got %s", mock.repoService.lastOwner)
}
}
func TestFilterRepos(t *testing.T) {
repos := []Repository{
{FullName: "org/active", Archived: false, Fork: false},
{FullName: "org/archived", Archived: true, Fork: false},
{FullName: "org/fork", Archived: false, Fork: true},
{FullName: "org/archived-fork", Archived: true, Fork: true},
}
tests := []struct {
name string
opts ListRepoOpts
want []string
}{
{"include all", ListRepoOpts{}, []string{"org/active", "org/archived", "org/fork", "org/archived-fork"}},
{"exclude archived", ListRepoOpts{Archived: ArchivedExclude}, []string{"org/active", "org/fork"}},
{"only archived", ListRepoOpts{Archived: ArchivedOnly}, []string{"org/archived", "org/archived-fork"}},
{"exclude forks", ListRepoOpts{Forks: ForkExclude}, []string{"org/active", "org/archived"}},
{"only forks", ListRepoOpts{Forks: ForkOnly}, []string{"org/fork", "org/archived-fork"}},
{"exclude both", ListRepoOpts{Archived: ArchivedExclude, Forks: ForkExclude}, []string{"org/active"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
input := make([]Repository, len(repos))
copy(input, repos)
got := FilterRepos(input, tt.opts)
var names []string
for _, r := range got {
names = append(names, r.FullName)
}
assertSliceEqual(t, "repos", tt.want, names)
})
}
}
// Mock forge for routing tests
type mockForge struct {
repoService *mockRepoService
issueService *mockIssueService
prService *mockPRService
labelService *mockLabelService
milestoneService *mockMilestoneService
releaseService *mockReleaseService
ciService *mockCIService
branchService *mockBranchService
deployKeyService *mockDeployKeyService
secretService *mockSecretService
reviewService *mockReviewService
}
func (m *mockForge) Repos() RepoService {
return m.repoService
}
func (m *mockForge) Issues() IssueService {
if m.issueService != nil {
return m.issueService
}
return &mockIssueService{}
}
func (m *mockForge) PullRequests() PullRequestService {
if m.prService != nil {
return m.prService
}
return &mockPRService{}
}
func (m *mockForge) Labels() LabelService {
if m.labelService != nil {
return m.labelService
}
return &mockLabelService{}
}
func (m *mockForge) Milestones() MilestoneService {
if m.milestoneService != nil {
return m.milestoneService
}
return &mockMilestoneService{}
}
func (m *mockForge) Releases() ReleaseService {
if m.releaseService != nil {
return m.releaseService
}
return &mockReleaseService{}
}
func (m *mockForge) CI() CIService {
if m.ciService != nil {
return m.ciService
}
return &mockCIService{}
}
func (m *mockForge) Branches() BranchService {
if m.branchService != nil {
return m.branchService
}
return &mockBranchService{}
}
func (m *mockForge) DeployKeys() DeployKeyService {
if m.deployKeyService != nil {
return m.deployKeyService
}
return &mockDeployKeyService{}
}
func (m *mockForge) Secrets() SecretService {
if m.secretService != nil {
return m.secretService
}
return &mockSecretService{}
}
func (m *mockForge) Notifications() NotificationService {
return &mockNotificationService{}
}
type mockNotificationService struct{}
func (m *mockNotificationService) List(_ context.Context, opts ListNotificationOpts) ([]Notification, error) {
return nil, nil
}
func (m *mockNotificationService) MarkRead(_ context.Context, opts MarkNotificationOpts) error {
return nil
}
func (m *mockNotificationService) Get(_ context.Context, id string) (*Notification, error) {
return nil, nil
}
func (m *mockForge) Reviews() ReviewService {
if m.reviewService != nil {
return m.reviewService
}
return &mockReviewService{}
}
func (m *mockForge) Files() FileService {
return &mockFileService{}
}
func (m *mockForge) Collaborators() CollaboratorService {
return &mockCollaboratorService{}
}
func (m *mockForge) CommitStatuses() CommitStatusService {
return &mockCommitStatusService{}
}
func (m *mockForge) GetRateLimit(_ context.Context) (*RateLimit, error) {
return nil, ErrNotSupported
}
type mockFileService struct{}
func (m *mockFileService) Get(_ context.Context, _, _, _, _ string) (*FileContent, error) {
return nil, nil
}
func (m *mockFileService) List(_ context.Context, _, _, _, _ string) ([]FileEntry, error) {
return nil, nil
}
type mockCollaboratorService struct{}
func (m *mockCollaboratorService) List(_ context.Context, _, _ string, _ ListCollaboratorOpts) ([]Collaborator, error) {
return nil, nil
}
func (m *mockCollaboratorService) Add(_ context.Context, _, _, _ string, _ AddCollaboratorOpts) error {
return nil
}
func (m *mockCollaboratorService) Remove(_ context.Context, _, _, _ string) error {
return nil
}
type mockCommitStatusService struct{}
func (m *mockCommitStatusService) List(_ context.Context, _, _, _ string) ([]CommitStatus, error) {
return nil, nil
}
func (m *mockCommitStatusService) Set(_ context.Context, _, _, _ string, _ SetCommitStatusOpts) (*CommitStatus, error) {
return nil, nil
}
type mockRepoService struct {
repo *Repository
repos []Repository
tags []Tag
lastOwner string
lastRepo string
}
func (m *mockRepoService) Get(_ context.Context, owner, repo string) (*Repository, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.repo, nil
}
func (m *mockRepoService) List(_ context.Context, owner string, opts ListRepoOpts) ([]Repository, error) {
m.lastOwner = owner
return m.repos, nil
}
func (m *mockRepoService) Create(_ context.Context, opts CreateRepoOpts) (*Repository, error) {
return m.repo, nil
}
func (m *mockRepoService) Edit(_ context.Context, owner, repo string, opts EditRepoOpts) (*Repository, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.repo, nil
}
func (m *mockRepoService) Delete(_ context.Context, owner, repo string) error {
m.lastOwner = owner
m.lastRepo = repo
return nil
}
func (m *mockRepoService) Fork(_ context.Context, owner, repo string, opts ForkRepoOpts) (*Repository, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.repo, nil
}
func (m *mockRepoService) ListForks(_ context.Context, owner, repo string, opts ListForksOpts) ([]Repository, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.repos, nil
}
func (m *mockRepoService) ListTags(_ context.Context, owner, repo string) ([]Tag, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.tags, nil
}
func (m *mockRepoService) ListContributors(_ context.Context, owner, repo string) ([]Contributor, error) {
m.lastOwner = owner
m.lastRepo = repo
return nil, nil
}
func (m *mockRepoService) Search(_ context.Context, opts SearchRepoOpts) ([]Repository, error) {
return m.repos, nil
}
type mockIssueService struct {
issue *Issue
issues []Issue
comment *Comment
comments []Comment
lastOwner string
lastRepo string
lastNumber int
}
func (m *mockIssueService) Get(_ context.Context, owner, repo string, number int) (*Issue, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return m.issue, nil
}
func (m *mockIssueService) List(_ context.Context, owner, repo string, opts ListIssueOpts) ([]Issue, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.issues, nil
}
func (m *mockIssueService) Create(_ context.Context, owner, repo string, opts CreateIssueOpts) (*Issue, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.issue, nil
}
func (m *mockIssueService) Update(_ context.Context, owner, repo string, number int, opts UpdateIssueOpts) (*Issue, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return m.issue, nil
}
func (m *mockIssueService) Close(_ context.Context, owner, repo string, number int) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return nil
}
func (m *mockIssueService) Reopen(_ context.Context, owner, repo string, number int) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return nil
}
func (m *mockIssueService) Delete(_ context.Context, owner, repo string, number int) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return nil
}
func (m *mockIssueService) CreateComment(_ context.Context, owner, repo string, number int, body string) (*Comment, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return m.comment, nil
}
func (m *mockIssueService) ListComments(_ context.Context, owner, repo string, number int) ([]Comment, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return m.comments, nil
}
func (m *mockIssueService) ListReactions(_ context.Context, owner, repo string, number int, commentID int64) ([]Reaction, error) {
return nil, nil
}
func (m *mockIssueService) AddReaction(_ context.Context, owner, repo string, number int, commentID int64, reaction string) (*Reaction, error) {
return nil, nil
}
type mockPRService struct {
pr *PullRequest
prs []PullRequest
comment *Comment
comments []Comment
diff string
lastOwner string
lastRepo string
lastNumber int
}
func (m *mockPRService) Get(_ context.Context, owner, repo string, number int) (*PullRequest, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return m.pr, nil
}
func (m *mockPRService) List(_ context.Context, owner, repo string, opts ListPROpts) ([]PullRequest, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.prs, nil
}
func (m *mockPRService) Create(_ context.Context, owner, repo string, opts CreatePROpts) (*PullRequest, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.pr, nil
}
func (m *mockPRService) Update(_ context.Context, owner, repo string, number int, opts UpdatePROpts) (*PullRequest, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return m.pr, nil
}
func (m *mockPRService) Close(_ context.Context, owner, repo string, number int) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return nil
}
func (m *mockPRService) Reopen(_ context.Context, owner, repo string, number int) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return nil
}
func (m *mockPRService) Merge(_ context.Context, owner, repo string, number int, opts MergePROpts) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return nil
}
func (m *mockPRService) Diff(_ context.Context, owner, repo string, number int) (string, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return m.diff, nil
}
func (m *mockPRService) CreateComment(_ context.Context, owner, repo string, number int, body string) (*Comment, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return m.comment, nil
}
func (m *mockPRService) ListComments(_ context.Context, owner, repo string, number int) ([]Comment, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastNumber = number
return m.comments, nil
}
func (m *mockPRService) ListReactions(_ context.Context, owner, repo string, number int, commentID int64) ([]Reaction, error) {
return nil, nil
}
func (m *mockPRService) AddReaction(_ context.Context, owner, repo string, number int, commentID int64, reaction string) (*Reaction, error) {
return nil, nil
}
type mockLabelService struct {
label *Label
labels []Label
lastOwner string
lastRepo string
lastName string
}
func (m *mockLabelService) List(_ context.Context, owner, repo string, opts ListLabelOpts) ([]Label, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.labels, nil
}
func (m *mockLabelService) Get(_ context.Context, owner, repo, name string) (*Label, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastName = name
return m.label, nil
}
func (m *mockLabelService) Create(_ context.Context, owner, repo string, opts CreateLabelOpts) (*Label, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.label, nil
}
func (m *mockLabelService) Update(_ context.Context, owner, repo, name string, opts UpdateLabelOpts) (*Label, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastName = name
return m.label, nil
}
func (m *mockLabelService) Delete(_ context.Context, owner, repo, name string) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastName = name
return nil
}
type mockMilestoneService struct {
milestone *Milestone
milestones []Milestone
lastOwner string
lastRepo string
lastID int
}
func (m *mockMilestoneService) List(_ context.Context, owner, repo string, opts ListMilestoneOpts) ([]Milestone, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.milestones, nil
}
func (m *mockMilestoneService) Get(_ context.Context, owner, repo string, id int) (*Milestone, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastID = id
return m.milestone, nil
}
func (m *mockMilestoneService) Create(_ context.Context, owner, repo string, opts CreateMilestoneOpts) (*Milestone, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.milestone, nil
}
func (m *mockMilestoneService) Update(_ context.Context, owner, repo string, id int, opts UpdateMilestoneOpts) (*Milestone, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastID = id
return m.milestone, nil
}
func (m *mockMilestoneService) Close(_ context.Context, owner, repo string, id int) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastID = id
return nil
}
func (m *mockMilestoneService) Reopen(_ context.Context, owner, repo string, id int) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastID = id
return nil
}
func (m *mockMilestoneService) Delete(_ context.Context, owner, repo string, id int) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastID = id
return nil
}
type mockReleaseService struct {
release *Release
releases []Release
asset *ReleaseAsset
lastOwner string
lastRepo string
lastTag string
}
func (m *mockReleaseService) List(_ context.Context, owner, repo string, opts ListReleaseOpts) ([]Release, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.releases, nil
}
func (m *mockReleaseService) Get(_ context.Context, owner, repo, tag string) (*Release, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastTag = tag
return m.release, nil
}
func (m *mockReleaseService) GetLatest(_ context.Context, owner, repo string) (*Release, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.release, nil
}
func (m *mockReleaseService) Create(_ context.Context, owner, repo string, opts CreateReleaseOpts) (*Release, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.release, nil
}
func (m *mockReleaseService) Update(_ context.Context, owner, repo, tag string, opts UpdateReleaseOpts) (*Release, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastTag = tag
return m.release, nil
}
func (m *mockReleaseService) Delete(_ context.Context, owner, repo, tag string) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastTag = tag
return nil
}
func (m *mockReleaseService) UploadAsset(_ context.Context, owner, repo, tag string, _ *os.File) (*ReleaseAsset, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastTag = tag
return m.asset, nil
}
func (m *mockReleaseService) DownloadAsset(_ context.Context, owner, repo string, _ int64) (io.ReadCloser, error) {
m.lastOwner = owner
m.lastRepo = repo
return nil, nil
}
type mockCIService struct {
run *CIRun
runs []CIRun
lastOwner string
lastRepo string
lastRunID int64
}
func (m *mockCIService) ListRuns(_ context.Context, owner, repo string, opts ListCIRunOpts) ([]CIRun, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.runs, nil
}
func (m *mockCIService) GetRun(_ context.Context, owner, repo string, runID int64) (*CIRun, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastRunID = runID
return m.run, nil
}
func (m *mockCIService) TriggerRun(_ context.Context, owner, repo string, opts TriggerCIRunOpts) error {
m.lastOwner = owner
m.lastRepo = repo
return nil
}
func (m *mockCIService) CancelRun(_ context.Context, owner, repo string, runID int64) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastRunID = runID
return nil
}
func (m *mockCIService) RetryRun(_ context.Context, owner, repo string, runID int64) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastRunID = runID
return nil
}
func (m *mockCIService) GetJobLog(_ context.Context, owner, repo string, jobID int64) (io.ReadCloser, error) {
m.lastOwner = owner
m.lastRepo = repo
return nil, nil
}
type mockBranchService struct {
branch *Branch
branches []Branch
lastOwner string
lastRepo string
lastName string
}
func (m *mockBranchService) List(_ context.Context, owner, repo string, opts ListBranchOpts) ([]Branch, error) {
m.lastOwner = owner
m.lastRepo = repo
return m.branches, nil
}
func (m *mockBranchService) Create(_ context.Context, owner, repo, name, from string) (*Branch, error) {
m.lastOwner = owner
m.lastRepo = repo
m.lastName = name
return m.branch, nil
}
func (m *mockBranchService) Delete(_ context.Context, owner, repo, name string) error {
m.lastOwner = owner
m.lastRepo = repo
m.lastName = name
return nil
}
type mockDeployKeyService struct {
key *DeployKey
keys []DeployKey
lastOwner string
lastRepo string
lastID int64
}
func (m *mockDeployKeyService) List(_ context.Context, owner, repo string, opts ListDeployKeyOpts) ([]DeployKey, error) {
m.lastOwner = owner