@@ -106,8 +106,8 @@ type GithubApiUrlBuilder struct {
106106 ApiScope string
107107}
108108
109- func NewGithubApiUrlBuilder (URL string ) (* GithubApiUrlBuilder , error ) {
110- baseUrl , err := url .Parse (URL )
109+ func NewGithubApiUrlBuilder (baseURLString string ) (* GithubApiUrlBuilder , error ) {
110+ baseUrl , err := url .Parse (baseURLString )
111111 if err != nil {
112112 return nil , err
113113 }
@@ -123,49 +123,50 @@ func NewGithubApiUrlBuilder(URL string) (*GithubApiUrlBuilder, error) {
123123}
124124
125125func (apiBuilder * GithubApiUrlBuilder ) AbsoluteApiUrl (p string ) string {
126- url := * apiBuilder .URL
127- url .Path = path .Join (apiBuilder .ApiScope , p )
128- return url .String ()
126+ apiURL := * apiBuilder .URL
127+ apiURL .Path = path .Join (apiBuilder .ApiScope , p )
128+ return apiURL .String ()
129129}
130130
131131func (apiBuilder * GithubApiUrlBuilder ) ScopedApiUrl (p string ) (string , error ) {
132- url := * apiBuilder .URL
133- paths := strings .Split (strings .TrimPrefix (url .Path , "/" ), "/" )
132+ apiURL := * apiBuilder .URL
133+ paths := strings .Split (strings .TrimPrefix (apiURL .Path , "/" ), "/" )
134134 if len (paths ) == 1 {
135- url .Path = path .Join (apiBuilder .ApiScope , "orgs" , paths [0 ], p )
136- } else if len (paths ) == 2 {
135+ apiURL .Path = path .Join (apiBuilder .ApiScope , "orgs" , paths [0 ], p )
136+ } else if len (paths ) == repositoryPathSegments {
137137 scope := "repos"
138138 if strings .EqualFold (paths [0 ], "enterprises" ) {
139139 scope = ""
140140 }
141- url .Path = path .Join (apiBuilder .ApiScope , scope , paths [0 ], paths [1 ], p )
141+ apiURL .Path = path .Join (apiBuilder .ApiScope , scope , paths [0 ], paths [1 ], p )
142142 } else {
143143 return "" , fmt .Errorf ("unsupported registration url" )
144144 }
145- return url .String (), nil
145+ return apiURL .String (), nil
146146}
147147
148- func gitHubAuth (config * ConfigureRemoveRunner , c * http.Client , runnerEvent string , apiEndpoint string , survey Survey ) (* protocol.GitHubAuthResult , error ) {
148+ func gitHubAuth (config * ConfigureRemoveRunner , c * http.Client , runnerEvent , apiEndpoint string , survey Survey ,
149+ ) (* protocol.GitHubAuthResult , error ) {
149150 if config .URL == "" && ! config .Unattended {
150151 config .URL = survey .GetInput ("Which GitHub Url is associated with this runner (Normally this isn't missing):" , "" )
151152 }
152153 apiBuilder , err := NewGithubApiUrlBuilder (config .URL )
153154 if err != nil {
154155 return nil , fmt .Errorf ("invalid Url: %v" , config .URL )
155156 }
156- if len ( config .Token ) == 0 {
157- if len ( config .Pat ) > 0 {
158- url , err := apiBuilder .ScopedApiUrl (path .Join ("actions/runners" , apiEndpoint ))
159- if err != nil {
160- return nil , err
157+ if config .Token == "" {
158+ if config .Pat != "" {
159+ apiURL , serr := apiBuilder .ScopedApiUrl (path .Join ("actions/runners" , apiEndpoint ))
160+ if serr != nil {
161+ return nil , serr
161162 }
162163 client := & protocol.VssConnection {
163164 AuthHeader : fmt .Sprintf ("Basic %v" , base64 .StdEncoding .EncodeToString ([]byte ("GitHub:" + config .Pat ))),
164165 Trace : config .Trace ,
165166 Client : c ,
166167 }
167168 tokenresp := & protocol.GitHubRunnerRegisterToken {}
168- err = client .RequestWithContext2 (context .Background (), "POST" , url , "" , nil , tokenresp )
169+ err = client .RequestWithContext2 (context .Background (), "POST" , apiURL , "" , nil , tokenresp )
169170 if err != nil {
170171 return nil , fmt .Errorf ("failed to retrieve %v token via pat: %v" , apiEndpoint , err .Error ())
171172 }
@@ -178,7 +179,7 @@ func gitHubAuth(config *ConfigureRemoveRunner, c *http.Client, runnerEvent strin
178179 return nil , fmt .Errorf ("no runner registration token provided" )
179180 }
180181
181- finalregisterUrl := apiBuilder .AbsoluteApiUrl ("actions/runner-registration" )
182+ finalregisterURL := apiBuilder .AbsoluteApiUrl ("actions/runner-registration" )
182183
183184 client := & protocol.VssConnection {
184185 AuthHeader : "RemoteAuth " + config .Token ,
0 commit comments