@@ -72,7 +72,7 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
72
72
if response != nil && response .StatusCode == http .StatusUnauthorized {
73
73
return nil , usererrors .New (errorInvalidDestinationToken )
74
74
}
75
- return nil , errors . Wrap ( err , "Error getting current user." )
75
+ return nil , githubapiutil . EnrichResponseError ( response , err , "Error getting current user." )
76
76
}
77
77
78
78
// When creating a repository we can either create it in a named organization or under the current user (represented in go-github by an empty string).
@@ -84,39 +84,39 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
84
84
if destinationOrganization != "" {
85
85
_ , response , err := pushService .githubEnterpriseClient .Organizations .Get (pushService .ctx , pushService .destinationRepositoryOwner )
86
86
if err != nil && (response == nil || response .StatusCode != http .StatusNotFound ) {
87
- return nil , errors . Wrap ( err , "Error checking if destination organization exists." )
87
+ return nil , githubapiutil . EnrichResponseError ( response , err , "Error checking if destination organization exists." )
88
88
}
89
89
if response != nil && response .StatusCode == http .StatusNotFound {
90
90
log .Debugf ("The organization %s does not exist. Creating it..." , pushService .destinationRepositoryOwner )
91
- _ , _ , err := pushService .githubEnterpriseClient .Admin .CreateOrg (pushService .ctx , & github.Organization {
91
+ _ , response , err := pushService .githubEnterpriseClient .Admin .CreateOrg (pushService .ctx , & github.Organization {
92
92
Login : github .String (pushService .destinationRepositoryOwner ),
93
93
Name : github .String (pushService .destinationRepositoryOwner ),
94
94
}, user .GetLogin ())
95
95
if err != nil {
96
96
if response != nil && response .StatusCode == http .StatusNotFound && ! githubapiutil .HasAnyScope (response , "site_admin" ) {
97
97
return nil , usererrors .New ("The destination token you have provided does not have the `site_admin` scope, so the destination organization cannot be created." )
98
98
}
99
- return nil , errors . Wrap ( err , "Error creating organization." )
99
+ return nil , githubapiutil . EnrichResponseError ( response , err , "Error creating organization." )
100
100
}
101
101
}
102
102
103
103
_ , response , err = pushService .githubEnterpriseClient .Organizations .IsMember (pushService .ctx , pushService .destinationRepositoryOwner , user .GetLogin ())
104
104
if err != nil {
105
- return nil , errors . Wrap ( err , "Failed to check membership of destination organization." )
105
+ return nil , githubapiutil . EnrichResponseError ( response , err , "Failed to check membership of destination organization." )
106
106
}
107
107
if (response .StatusCode == http .StatusFound || response .StatusCode == http .StatusNotFound ) && githubapiutil .HasAnyScope (response , "site_admin" ) {
108
108
log .Debugf ("No access to destination organization (status code %d). Switching to impersonation token for %s..." , response .StatusCode , pushService .actionsAdminUser )
109
- impersonationToken , _ , err := pushService .githubEnterpriseClient .Admin .CreateUserImpersonation (pushService .ctx , pushService .actionsAdminUser , & github.ImpersonateUserOptions {Scopes : []string {minimumRepositoryScope , "workflow" }})
109
+ impersonationToken , response , err := pushService .githubEnterpriseClient .Admin .CreateUserImpersonation (pushService .ctx , pushService .actionsAdminUser , & github.ImpersonateUserOptions {Scopes : []string {minimumRepositoryScope , "workflow" }})
110
110
if err != nil {
111
- return nil , errors . Wrap ( err , "Failed to impersonate Actions admin user." )
111
+ return nil , githubapiutil . EnrichResponseError ( response , err , "Failed to impersonate Actions admin user." )
112
112
}
113
113
pushService .destinationToken .AccessToken = impersonationToken .GetToken ()
114
114
}
115
115
}
116
116
117
117
repository , response , err := pushService .githubEnterpriseClient .Repositories .Get (pushService .ctx , pushService .destinationRepositoryOwner , pushService .destinationRepositoryName )
118
118
if err != nil && (response == nil || response .StatusCode != http .StatusNotFound ) {
119
- return nil , errors . Wrap ( err , "Error checking if destination repository exists." )
119
+ return nil , githubapiutil . EnrichResponseError ( response , err , "Error checking if destination repository exists." )
120
120
}
121
121
if response .StatusCode != http .StatusNotFound && repositoryHomepage != repository .GetHomepage () && ! pushService .force {
122
122
return nil , errors .Errorf (errorAlreadyExists )
@@ -143,7 +143,7 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
143
143
if response .StatusCode == http .StatusNotFound && ! githubapiutil .HasAnyScope (response , acceptableRepositoryScopes ... ) {
144
144
return nil , fmt .Errorf ("The destination token you have provided does not have the `%s` scope." , minimumRepositoryScope )
145
145
}
146
- return nil , errors . Wrap ( err , "Error creating destination repository." )
146
+ return nil , githubapiutil . EnrichResponseError ( response , err , "Error creating destination repository." )
147
147
}
148
148
} else {
149
149
log .Debug ("Repository already exists. Updating its metadata..." )
@@ -156,7 +156,7 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
156
156
return nil , fmt .Errorf ("You don't have permission to update the repository at %s/%s. If you wish to update the bundled CodeQL Action please provide a token with the `site_admin` scope." , pushService .destinationRepositoryOwner , pushService .destinationRepositoryName )
157
157
}
158
158
}
159
- return nil , errors . Wrap ( err , "Error updating destination repository." )
159
+ return nil , githubapiutil . EnrichResponseError ( response , err , "Error updating destination repository." )
160
160
}
161
161
}
162
162
@@ -212,6 +212,7 @@ func (pushService *pushService) pushGit(repository *github.Repository, initialPu
212
212
}
213
213
refSpecBatches = append (refSpecBatches , deleteRefSpecs )
214
214
215
+ defaultBranchRefSpec := "+refs/heads/main:refs/heads/main"
215
216
if initialPush {
216
217
releasePathStats , err := ioutil .ReadDir (pushService .cacheDirectory .ReleasesPath ())
217
218
if err != nil {
@@ -228,10 +229,10 @@ func (pushService *pushService) pushGit(repository *github.Repository, initialPu
228
229
}
229
230
refSpecBatches = append (refSpecBatches , initialRefSpecs )
230
231
} else {
231
- // We've got to push `main` on its own, so that it will be made the default branch if the repository has just been created. We then push everything else afterwards.
232
+ // We've got to push the default branch on its own, so that it will be made the default branch if the repository has just been created. We then push everything else afterwards.
232
233
refSpecBatches = append (refSpecBatches ,
233
234
[]config.RefSpec {
234
- config .RefSpec ("+refs/heads/main:refs/heads/main" ),
235
+ config .RefSpec (defaultBranchRefSpec ),
235
236
},
236
237
[]config.RefSpec {
237
238
config .RefSpec ("+refs/*:refs/*" ),
@@ -270,20 +271,20 @@ func (pushService *pushService) createOrUpdateRelease(releaseName string) (*gith
270
271
271
272
release , response , err := pushService .githubEnterpriseClient .Repositories .GetReleaseByTag (pushService .ctx , pushService .destinationRepositoryOwner , pushService .destinationRepositoryName , releaseMetadata .GetTagName ())
272
273
if err != nil && response .StatusCode != http .StatusNotFound {
273
- return nil , errors . Wrap ( err , "Error checking for existing CodeQL release." )
274
+ return nil , githubapiutil . EnrichResponseError ( response , err , "Error checking for existing CodeQL release." )
274
275
}
275
276
if release == nil {
276
277
log .Debugf ("Creating release %s..." , releaseMetadata .GetTagName ())
277
- release , _ , err := pushService .githubEnterpriseClient .Repositories .CreateRelease (pushService .ctx , pushService .destinationRepositoryOwner , pushService .destinationRepositoryName , & releaseMetadata )
278
+ release , response , err := pushService .githubEnterpriseClient .Repositories .CreateRelease (pushService .ctx , pushService .destinationRepositoryOwner , pushService .destinationRepositoryName , & releaseMetadata )
278
279
if err != nil {
279
- return nil , errors . Wrap ( err , "Error creating release." )
280
+ return nil , githubapiutil . EnrichResponseError ( response , err , "Error creating release." )
280
281
}
281
282
return release , nil
282
283
}
283
- release , _ , err = pushService .githubEnterpriseClient .Repositories .EditRelease (pushService .ctx , pushService .destinationRepositoryOwner , pushService .destinationRepositoryName , release .GetID (), & releaseMetadata )
284
+ release , response , err = pushService .githubEnterpriseClient .Repositories .EditRelease (pushService .ctx , pushService .destinationRepositoryOwner , pushService .destinationRepositoryName , release .GetID (), & releaseMetadata )
284
285
if err != nil {
285
286
log .Debugf ("Updating release %s..." , releaseMetadata .GetTagName ())
286
- return nil , errors . Wrap ( err , "Error updating release." )
287
+ return nil , githubapiutil . EnrichResponseError ( response , err , "Error updating release." )
287
288
}
288
289
return release , nil
289
290
}
@@ -301,7 +302,7 @@ func (pushService *pushService) uploadReleaseAsset(release *github.RepositoryRel
301
302
asset := & github.ReleaseAsset {}
302
303
response , err := pushService .githubEnterpriseClient .Do (pushService .ctx , request , asset )
303
304
if err != nil {
304
- return nil , response , errors . Wrap ( err , "Error uploading release asset." )
305
+ return nil , response , githubapiutil . EnrichResponseError ( response , err , "Error uploading release asset." )
305
306
}
306
307
return asset , response , nil
307
308
}
@@ -315,9 +316,9 @@ func (pushService *pushService) createOrUpdateReleaseAsset(release *github.Repos
315
316
return nil
316
317
} else {
317
318
log .Warnf ("Removing existing release asset %s because it was only partially-uploaded (had size %d, but should have been %d)..." , existingAsset .GetName (), actualSize , expectedSize )
318
- _ , err := pushService .githubEnterpriseClient .Repositories .DeleteReleaseAsset (pushService .ctx , pushService .destinationRepositoryOwner , pushService .destinationRepositoryName , existingAsset .GetID ())
319
+ response , err := pushService .githubEnterpriseClient .Repositories .DeleteReleaseAsset (pushService .ctx , pushService .destinationRepositoryOwner , pushService .destinationRepositoryName , existingAsset .GetID ())
319
320
if err != nil {
320
- return errors . Wrap ( err , "Error deleting existing release asset." )
321
+ return githubapiutil . EnrichResponseError ( response , err , "Error deleting existing release asset." )
321
322
}
322
323
}
323
324
}
@@ -333,9 +334,9 @@ func (pushService *pushService) createOrUpdateReleaseAsset(release *github.Repos
333
334
Size : assetPathStat .Size (),
334
335
DrawFunc : ioprogress .DrawTerminalf (os .Stderr , ioprogress .DrawTextFormatBytes ),
335
336
}
336
- _ , _ , err = pushService .uploadReleaseAsset (release , assetPathStat , progressReader )
337
+ _ , response , err : = pushService .uploadReleaseAsset (release , assetPathStat , progressReader )
337
338
if err != nil {
338
- return errors . Wrap ( err , "Error uploading release asset." )
339
+ return githubapiutil . EnrichResponseError ( response , err , "Error uploading release asset." )
339
340
}
340
341
return nil
341
342
}
@@ -358,9 +359,9 @@ func (pushService *pushService) pushReleases() error {
358
359
359
360
existingAssets := []* github.ReleaseAsset {}
360
361
for page := 1 ; ; page ++ {
361
- assets , _ , err := pushService .githubEnterpriseClient .Repositories .ListReleaseAssets (pushService .ctx , pushService .destinationRepositoryOwner , pushService .destinationRepositoryName , release .GetID (), & github.ListOptions {Page : page })
362
+ assets , response , err := pushService .githubEnterpriseClient .Repositories .ListReleaseAssets (pushService .ctx , pushService .destinationRepositoryOwner , pushService .destinationRepositoryName , release .GetID (), & github.ListOptions {Page : page })
362
363
if err != nil {
363
- return errors . Wrap ( err , "Error fetching existing release assets." )
364
+ return githubapiutil . EnrichResponseError ( response , err , "Error fetching existing release assets." )
364
365
}
365
366
if len (assets ) == 0 {
366
367
break
@@ -376,7 +377,7 @@ func (pushService *pushService) pushReleases() error {
376
377
for _ , assetPathStat := range assetPathStats {
377
378
err := pushService .createOrUpdateReleaseAsset (release , existingAssets , assetPathStat )
378
379
if err != nil {
379
- return errors . Wrap ( err , "Error uploading release assets." )
380
+ return err
380
381
}
381
382
}
382
383
}
@@ -410,7 +411,7 @@ func Push(ctx context.Context, cacheDirectory cachedirectory.CacheDirectory, des
410
411
}
411
412
rootResponse , err := client .Do (ctx , rootRequest , nil )
412
413
if err != nil {
413
- return errors . Wrap ( err , "Error checking connectivity for GitHub Enterprise client." )
414
+ return githubapiutil . EnrichResponseError ( rootResponse , err , "Error checking connectivity for GitHub Enterprise client." )
414
415
}
415
416
if rootRequest .URL != rootResponse .Request .URL {
416
417
updatedBaseURL , _ := url .Parse (client .BaseURL .String ())
0 commit comments