Skip to content

Commit 9ab49c4

Browse files
authored
Merge pull request #42 from github/fix-nil-pointer-errors
Fix some nil-pointer dereferences.
2 parents 747f0b3 + 2ddf495 commit 9ab49c4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

internal/push/push.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
5151
log.Debug("Ensuring repository exists...")
5252
user, response, err := pushService.githubEnterpriseClient.Users.Get(pushService.ctx, "")
5353
if err != nil {
54-
if response.StatusCode == http.StatusUnauthorized {
54+
if response != nil && response.StatusCode == http.StatusUnauthorized {
5555
return nil, usererrors.New(errorInvalidDestinationToken)
5656
}
5757
return nil, errors.Wrap(err, "Error getting current user.")
@@ -68,14 +68,14 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
6868
if err != nil && (response == nil || response.StatusCode != http.StatusNotFound) {
6969
return nil, errors.Wrap(err, "Error checking if destination organization exists.")
7070
}
71-
if response.StatusCode == http.StatusNotFound {
71+
if response != nil && response.StatusCode == http.StatusNotFound {
7272
log.Debugf("The organization %s does not exist. Creating it...", pushService.destinationRepositoryOwner)
7373
_, _, err := pushService.githubEnterpriseClient.Admin.CreateOrg(pushService.ctx, &github.Organization{
7474
Login: github.String(pushService.destinationRepositoryOwner),
7575
Name: github.String(pushService.destinationRepositoryOwner),
7676
}, user.GetLogin())
7777
if err != nil {
78-
if response.StatusCode == http.StatusNotFound && githubapiutil.MissingAllScopes(response, "site_admin") {
78+
if response != nil && response.StatusCode == http.StatusNotFound && githubapiutil.MissingAllScopes(response, "site_admin") {
7979
return nil, usererrors.New("The destination token you have provided does not have the `site_admin` scope, so the destination organization cannot be created.")
8080
}
8181
return nil, errors.Wrap(err, "Error creating organization.")

0 commit comments

Comments
 (0)