@@ -51,7 +51,7 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
51
51
log .Debug ("Ensuring repository exists..." )
52
52
user , response , err := pushService .githubEnterpriseClient .Users .Get (pushService .ctx , "" )
53
53
if err != nil {
54
- if response .StatusCode == http .StatusUnauthorized {
54
+ if response != nil && response .StatusCode == http .StatusUnauthorized {
55
55
return nil , usererrors .New (errorInvalidDestinationToken )
56
56
}
57
57
return nil , errors .Wrap (err , "Error getting current user." )
@@ -68,14 +68,14 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
68
68
if err != nil && (response == nil || response .StatusCode != http .StatusNotFound ) {
69
69
return nil , errors .Wrap (err , "Error checking if destination organization exists." )
70
70
}
71
- if response .StatusCode == http .StatusNotFound {
71
+ if response != nil && response .StatusCode == http .StatusNotFound {
72
72
log .Debugf ("The organization %s does not exist. Creating it..." , pushService .destinationRepositoryOwner )
73
73
_ , _ , err := pushService .githubEnterpriseClient .Admin .CreateOrg (pushService .ctx , & github.Organization {
74
74
Login : github .String (pushService .destinationRepositoryOwner ),
75
75
Name : github .String (pushService .destinationRepositoryOwner ),
76
76
}, user .GetLogin ())
77
77
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" ) {
79
79
return nil , usererrors .New ("The destination token you have provided does not have the `site_admin` scope, so the destination organization cannot be created." )
80
80
}
81
81
return nil , errors .Wrap (err , "Error creating organization." )
0 commit comments