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