Skip to content

Commit 9ddb0e9

Browse files
committed
fix lint
1 parent 8945530 commit 9ddb0e9

6 files changed

Lines changed: 58 additions & 56 deletions

File tree

protocol/connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func (vssConnection *VssConnection) CreateSessionExt(ctx context.Context, server
350350
return nil, err
351351
}
352352
if session.BrokerMigrationMessage != nil {
353-
return vssConnection.CreateSessionExt(ctx, session.BrokerMigrationMessage.BrokerBaseUrl)
353+
return vssConnection.CreateSessionExt(ctx, session.BrokerMigrationMessage.BrokerBaseURL)
354354
}
355355
}
356356

protocol/runner_admin.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
package protocol
2-
3-
type Runner struct {
4-
Name string `json:"name"`
5-
Id int64 `json:"id"`
6-
Authorization struct {
7-
AuthorizationURL string `json:"authorization_url"`
8-
ServerURL string `json:"server_url"`
9-
ClientId string `json:"client_id"`
10-
} `json:"authorization"`
11-
}
12-
13-
type RunnerGroup struct {
14-
Id int32 `json:"id,omitempty"`
15-
Name string `json:"name,omitempty"`
16-
IsDefault bool `json:"default,omitempty"`
17-
IsHosted bool `json:"is_hosted,omitempty"`
18-
}
19-
20-
type RunnerGroupList struct {
21-
RunnerGroups []RunnerGroup `json:"runner_groups"`
22-
Count int `json:"total_count"`
23-
}
24-
25-
type ListRunnersResponse struct {
26-
TotalCount int `json:"total_count"`
27-
Runners []Runner `json:"runners"`
28-
}
1+
package protocol
2+
3+
type Runner struct {
4+
Name string `json:"name"`
5+
Id int64 `json:"id"`
6+
Authorization struct {
7+
AuthorizationURL string `json:"authorization_url"`
8+
ServerURL string `json:"server_url"`
9+
ClientId string `json:"client_id"`
10+
} `json:"authorization"`
11+
}
12+
13+
type RunnerGroup struct {
14+
Id int32 `json:"id,omitempty"`
15+
Name string `json:"name,omitempty"`
16+
IsDefault bool `json:"default,omitempty"`
17+
IsHosted bool `json:"is_hosted,omitempty"`
18+
}
19+
20+
type RunnerGroupList struct {
21+
RunnerGroups []RunnerGroup `json:"runner_groups"`
22+
Count int `json:"total_count"`
23+
}
24+
25+
type ListRunnersResponse struct {
26+
TotalCount int `json:"total_count"`
27+
Runners []Runner `json:"runners"`
28+
}

protocol/session.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import (
66
"crypto/cipher"
77
"crypto/rand"
88
"crypto/rsa"
9-
"net/url"
10-
"strings"
11-
129
"crypto/sha1"
1310
"crypto/sha256"
1411
"encoding/base64"
@@ -17,6 +14,7 @@ import (
1714
"fmt"
1815
"hash"
1916
"io"
17+
"net/url"
2018
"strings"
2119
"time"
2220
)

runnerconfiguration/add.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ type RSAKeyValue struct {
275275
Exponent string
276276
}
277277

278-
func registerOrReplaceRunnerV2(taskAgent *protocol.TaskAgent, config *ConfigureRunner, vssConnection *protocol.VssConnection, apiBuilder *GithubApiUrlBuilder, replace bool) error {
278+
func registerOrReplaceRunnerV2(taskAgent *protocol.TaskAgent, config *ConfigureRunner,
279+
vssConnection *protocol.VssConnection, apiBuilder *GithubApiUrlBuilder, replace bool,
280+
) error {
279281
runnerResp := &protocol.Runner{}
280282
pubKeyXml, err := xml.Marshal(&RSAKeyValue{
281283
Modulus: taskAgent.Authorization.PublicKey.Modulus,
@@ -298,7 +300,8 @@ func registerOrReplaceRunnerV2(taskAgent *protocol.TaskAgent, config *ConfigureR
298300
v2Register["runner_id"] = taskAgent.ID
299301
v2Register["replace"] = true
300302
}
301-
err = vssConnection.RequestWithContext2(context.Background(), "POST", apiBuilder.AbsoluteApiUrl("actions/runners/register"), "", v2Register, runnerResp)
303+
err = vssConnection.RequestWithContext2(context.Background(), "POST",
304+
apiBuilder.AbsoluteApiUrl("actions/runners/register"), "", v2Register, runnerResp)
302305
if err != nil {
303306
return err
304307
}

runnerconfiguration/common.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

125125
func (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

131131
func (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,

runnerconfiguration/remove.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ func (config *RemoveRunner) Remove(settings *RunnerSettings, survey Survey, auth
9090
}
9191
runnerURL, err := apiBuilder.ScopedApiUrl(fmt.Sprintf("actions/runners/%d", instance.Agent.ID))
9292
if err != nil {
93-
return fmt.Errorf("failed to remove Runner from server: %v", err)
93+
return fmt.Errorf("failed to remove Runner from server: %w", err)
9494
}
9595
err = vssConnection.RequestWithContext2(context.Background(), "DELETE", runnerURL, "", nil, nil)
9696
if err != nil {
97-
return fmt.Errorf("failed to remove Runner from server: %v", err)
97+
return fmt.Errorf("failed to remove Runner from server: %w", err)
9898
}
9999
} else {
100100
vssConnection := &protocol.VssConnection{
@@ -105,7 +105,7 @@ func (config *RemoveRunner) Remove(settings *RunnerSettings, survey Survey, auth
105105
Trace: config.Trace,
106106
}
107107
if err := vssConnection.DeleteAgent(instance.Agent); err != nil {
108-
return fmt.Errorf("failed to remove Runner from server: %v", err)
108+
return fmt.Errorf("failed to remove Runner from server: %w", err)
109109
}
110110
}
111111

0 commit comments

Comments
 (0)