Skip to content

Commit 3e8a7f0

Browse files
authored
Clean up method return consistency (#2318)
1 parent 1694b79 commit 3e8a7f0

32 files changed

+320
-48
lines changed

github/actions_artifacts_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestActionsService_ListArtifacts(t *testing.T) {
2525
testFormValues(t, r, values{"page": "2"})
2626
fmt.Fprint(w,
2727
`{
28-
"total_count":1,
28+
"total_count":1,
2929
"artifacts":[{"id":1}]
3030
}`,
3131
)
@@ -107,7 +107,7 @@ func TestActionsService_ListWorkflowRunArtifacts(t *testing.T) {
107107
testFormValues(t, r, values{"page": "2"})
108108
fmt.Fprint(w,
109109
`{
110-
"total_count":1,
110+
"total_count":1,
111111
"artifacts":[{"id":1}]
112112
}`,
113113
)

github/activity_notifications_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestActivityService_ListNotification(t *testing.T) {
5959
})
6060
}
6161

62-
func TestActivityService_ListRepositoryNotification(t *testing.T) {
62+
func TestActivityService_ListRepositoryNotifications(t *testing.T) {
6363
client, mux, _, teardown := setup()
6464
defer teardown()
6565

@@ -81,7 +81,7 @@ func TestActivityService_ListRepositoryNotification(t *testing.T) {
8181

8282
const methodName = "ListRepositoryNotifications"
8383
testBadOptions(t, methodName, func() (err error) {
84-
_, _, err = client.Activity.ListRepositoryNotifications(ctx, "\n", "\n", nil)
84+
_, _, err = client.Activity.ListRepositoryNotifications(ctx, "\n", "\n", &NotificationListOptions{})
8585
return err
8686
})
8787

github/activity_star.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func (s *ActivityService) IsStarred(ctx context.Context, owner, repo string) (bo
108108
if err != nil {
109109
return false, nil, err
110110
}
111+
111112
resp, err := s.client.Do(ctx, req, nil)
112113
starred, err := parseBoolResponse(err)
113114
return starred, resp, err
@@ -122,6 +123,7 @@ func (s *ActivityService) Star(ctx context.Context, owner, repo string) (*Respon
122123
if err != nil {
123124
return nil, err
124125
}
126+
125127
return s.client.Do(ctx, req, nil)
126128
}
127129

@@ -134,5 +136,6 @@ func (s *ActivityService) Unstar(ctx context.Context, owner, repo string) (*Resp
134136
if err != nil {
135137
return nil, err
136138
}
139+
137140
return s.client.Do(ctx, req, nil)
138141
}

github/billing.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (s *BillingService) GetActionsBillingOrg(ctx context.Context, org string) (
7979
return nil, resp, err
8080
}
8181

82-
return actionsOrgBilling, resp, err
82+
return actionsOrgBilling, resp, nil
8383
}
8484

8585
// GetPackagesBillingOrg returns the free and paid storage used for GitHub Packages in gigabytes for an Org.
@@ -98,7 +98,7 @@ func (s *BillingService) GetPackagesBillingOrg(ctx context.Context, org string)
9898
return nil, resp, err
9999
}
100100

101-
return packagesOrgBilling, resp, err
101+
return packagesOrgBilling, resp, nil
102102
}
103103

104104
// GetStorageBillingOrg returns the estimated paid and estimated total storage used for GitHub Actions
@@ -118,7 +118,7 @@ func (s *BillingService) GetStorageBillingOrg(ctx context.Context, org string) (
118118
return nil, resp, err
119119
}
120120

121-
return storageOrgBilling, resp, err
121+
return storageOrgBilling, resp, nil
122122
}
123123

124124
// GetAdvancedSecurityActiveCommittersOrg returns the GitHub Advanced Security active committers for an organization per repository.
@@ -137,7 +137,7 @@ func (s *BillingService) GetAdvancedSecurityActiveCommittersOrg(ctx context.Cont
137137
return nil, resp, err
138138
}
139139

140-
return activeOrgCommitters, resp, err
140+
return activeOrgCommitters, resp, nil
141141
}
142142

143143
// GetActionsBillingUser returns the summary of the free and paid GitHub Actions minutes used for a user.
@@ -156,7 +156,7 @@ func (s *BillingService) GetActionsBillingUser(ctx context.Context, user string)
156156
return nil, resp, err
157157
}
158158

159-
return actionsUserBilling, resp, err
159+
return actionsUserBilling, resp, nil
160160
}
161161

162162
// GetPackagesBillingUser returns the free and paid storage used for GitHub Packages in gigabytes for a user.
@@ -175,7 +175,7 @@ func (s *BillingService) GetPackagesBillingUser(ctx context.Context, user string
175175
return nil, resp, err
176176
}
177177

178-
return packagesUserBilling, resp, err
178+
return packagesUserBilling, resp, nil
179179
}
180180

181181
// GetStorageBillingUser returns the estimated paid and estimated total storage used for GitHub Actions
@@ -195,5 +195,5 @@ func (s *BillingService) GetStorageBillingUser(ctx context.Context, user string)
195195
return nil, resp, err
196196
}
197197

198-
return storageUserBilling, resp, err
198+
return storageUserBilling, resp, nil
199199
}

github/gists.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ func (s *GistsService) Delete(ctx context.Context, id string) (*Response, error)
279279
if err != nil {
280280
return nil, err
281281
}
282+
282283
return s.client.Do(ctx, req, nil)
283284
}
284285

@@ -291,6 +292,7 @@ func (s *GistsService) Star(ctx context.Context, id string) (*Response, error) {
291292
if err != nil {
292293
return nil, err
293294
}
295+
294296
return s.client.Do(ctx, req, nil)
295297
}
296298

@@ -303,6 +305,7 @@ func (s *GistsService) Unstar(ctx context.Context, id string) (*Response, error)
303305
if err != nil {
304306
return nil, err
305307
}
308+
306309
return s.client.Do(ctx, req, nil)
307310
}
308311

@@ -315,6 +318,7 @@ func (s *GistsService) IsStarred(ctx context.Context, id string) (bool, *Respons
315318
if err != nil {
316319
return false, nil, err
317320
}
321+
318322
resp, err := s.client.Do(ctx, req, nil)
319323
starred, err := parseBoolResponse(err)
320324
return starred, resp, err

github/git_blobs.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ func (s *GitService) GetBlob(ctx context.Context, owner string, repo string, sha
3333

3434
blob := new(Blob)
3535
resp, err := s.client.Do(ctx, req, blob)
36-
return blob, resp, err
36+
if err != nil {
37+
return nil, resp, err
38+
}
39+
40+
return blob, resp, nil
3741
}
3842

3943
// GetBlobRaw fetches a blob's contents from a repo.
@@ -46,11 +50,16 @@ func (s *GitService) GetBlobRaw(ctx context.Context, owner, repo, sha string) ([
4650
if err != nil {
4751
return nil, nil, err
4852
}
53+
4954
req.Header.Set("Accept", "application/vnd.github.v3.raw")
5055

5156
var buf bytes.Buffer
5257
resp, err := s.client.Do(ctx, req, &buf)
53-
return buf.Bytes(), resp, err
58+
if err != nil {
59+
return nil, resp, err
60+
}
61+
62+
return buf.Bytes(), resp, nil
5463
}
5564

5665
// CreateBlob creates a blob object.
@@ -65,5 +74,9 @@ func (s *GitService) CreateBlob(ctx context.Context, owner string, repo string,
6574

6675
t := new(Blob)
6776
resp, err := s.client.Do(ctx, req, t)
68-
return t, resp, err
77+
if err != nil {
78+
return nil, resp, err
79+
}
80+
81+
return t, resp, nil
6982
}

github/git_blobs_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ func TestGitService_GetBlob(t *testing.T) {
4949
_, _, err = client.Git.GetBlob(ctx, "\n", "\n", "\n")
5050
return err
5151
})
52+
53+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
54+
got, resp, err := client.Git.GetBlob(ctx, "o", "r", "s")
55+
if got != nil {
56+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
57+
}
58+
return resp, err
59+
})
5260
}
5361

5462
func TestGitService_GetBlob_invalidOwner(t *testing.T) {
@@ -144,6 +152,14 @@ func TestGitService_CreateBlob(t *testing.T) {
144152
_, _, err = client.Git.CreateBlob(ctx, "\n", "\n", input)
145153
return err
146154
})
155+
156+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
157+
got, resp, err := client.Git.CreateBlob(ctx, "o", "r", input)
158+
if got != nil {
159+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
160+
}
161+
return resp, err
162+
})
147163
}
148164

149165
func TestGitService_CreateBlob_invalidOwner(t *testing.T) {

github/git_commits_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,18 @@ func TestGitService_CreateSignedCommitWithInvalidParams(t *testing.T) {
285285
ctx := context.Background()
286286
_, _, err := client.Git.CreateCommit(ctx, "o", "r", input)
287287
if err == nil {
288-
t.Errorf("Expected error to be returned because invalid params was passed")
288+
t.Errorf("Expected error to be returned because invalid params were passed")
289+
}
290+
}
291+
292+
func TestGitService_CreateSignedCommitWithNilCommit(t *testing.T) {
293+
client, _, _, teardown := setup()
294+
defer teardown()
295+
296+
ctx := context.Background()
297+
_, _, err := client.Git.CreateCommit(ctx, "o", "r", nil)
298+
if err == nil {
299+
t.Errorf("Expected error to be returned because commit=nil")
289300
}
290301
}
291302

github/git_tags.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ func (s *GitService) GetTag(ctx context.Context, owner string, repo string, sha
4545

4646
tag := new(Tag)
4747
resp, err := s.client.Do(ctx, req, tag)
48-
return tag, resp, err
48+
if err != nil {
49+
return nil, resp, err
50+
}
51+
52+
return tag, resp, nil
4953
}
5054

5155
// CreateTag creates a tag object.
@@ -72,5 +76,9 @@ func (s *GitService) CreateTag(ctx context.Context, owner string, repo string, t
7276

7377
t := new(Tag)
7478
resp, err := s.client.Do(ctx, req, t)
75-
return t, resp, err
79+
if err != nil {
80+
return nil, resp, err
81+
}
82+
83+
return t, resp, nil
7684
}

github/git_tags_test.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ func TestGitService_GetTag(t *testing.T) {
4040
_, _, err = client.Git.GetTag(ctx, "\n", "\n", "\n")
4141
return err
4242
})
43+
44+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
45+
got, resp, err := client.Git.GetTag(ctx, "o", "r", "s")
46+
if got != nil {
47+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
48+
}
49+
return resp, err
50+
})
4351
}
4452

4553
func TestGitService_CreateTag(t *testing.T) {
@@ -61,10 +69,11 @@ func TestGitService_CreateTag(t *testing.T) {
6169
})
6270

6371
ctx := context.Background()
64-
tag, _, err := client.Git.CreateTag(ctx, "o", "r", &Tag{
72+
inputTag := &Tag{
6573
Tag: input.Tag,
6674
Object: &GitObject{SHA: input.Object},
67-
})
75+
}
76+
tag, _, err := client.Git.CreateTag(ctx, "o", "r", inputTag)
6877
if err != nil {
6978
t.Errorf("Git.CreateTag returned error: %v", err)
7079
}
@@ -76,12 +85,17 @@ func TestGitService_CreateTag(t *testing.T) {
7685

7786
const methodName = "CreateTag"
7887
testBadOptions(t, methodName, func() (err error) {
79-
_, _, err = client.Git.CreateTag(ctx, "\n", "\n", &Tag{
80-
Tag: input.Tag,
81-
Object: &GitObject{SHA: input.Object},
82-
})
88+
_, _, err = client.Git.CreateTag(ctx, "\n", "\n", inputTag)
8389
return err
8490
})
91+
92+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
93+
got, resp, err := client.Git.CreateTag(ctx, "o", "r", inputTag)
94+
if got != nil {
95+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
96+
}
97+
return resp, err
98+
})
8599
}
86100

87101
func TestTag_Marshal(t *testing.T) {

0 commit comments

Comments
 (0)