Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

Commit 2a8e529

Browse files
Add runner client
1 parent 1d7d00d commit 2a8e529

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

gitlab/factory.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type APIClientFactory interface {
1414
GetProjectClient() Project
1515
GetUserClient() User
1616
GetLintClient() Lint
17+
GetRunnerClient() Runner
1718
}
1819

1920
type GitlabClientFactory struct {
@@ -78,6 +79,10 @@ func (f *GitlabClientFactory) GetLintClient() Lint {
7879
return NewLintClient(f.gitlabClient)
7980
}
8081

82+
func (f *GitlabClientFactory) GetRunnerClient() Runner {
83+
return NewRunnerClient(f.gitlabClient)
84+
}
85+
8186
type MockAPIClientFactory struct {
8287
MockGetJobClient func() Job
8388
MockGetIssueClient func() Issue
@@ -89,6 +94,7 @@ type MockAPIClientFactory struct {
8994
MockGetProjectClient func() Project
9095
MockGetUserClient func() User
9196
MockGetLintClient func() Lint
97+
MockGetRunnerClient func() Runner
9298
}
9399

94100
func (m *MockAPIClientFactory) Init(url, token string) error {
@@ -134,3 +140,7 @@ func (m *MockAPIClientFactory) GetUserClient() User {
134140
func (m *MockAPIClientFactory) GetLintClient() Lint {
135141
return m.MockGetLintClient()
136142
}
143+
144+
func (m *MockAPIClientFactory) GetRunnerClient() Runner {
145+
return m.MockGetRunnerClient()
146+
}

gitlab/runner.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package gitlab
2+
3+
import (
4+
"fmt"
5+
6+
gitlab "github.com/xanzy/go-gitlab"
7+
)
8+
9+
type Runner interface {
10+
ListRunners(opt *gitlab.ListRunnersOptions) ([]*gitlab.Runner, error)
11+
}
12+
13+
type RunnerClient struct {
14+
Client *gitlab.Client
15+
}
16+
17+
func NewRunnerClient(client *gitlab.Client) Runner {
18+
return &RunnerClient{Client: client}
19+
}
20+
21+
func (c *RunnerClient) ListRunners(opt *gitlab.ListRunnersOptions) ([]*gitlab.Runner, error) {
22+
res, _, err := c.Client.Runners.ListRunners(opt)
23+
if err != nil {
24+
return nil, fmt.Errorf("failed list tree. %s", err.Error())
25+
}
26+
return res, nil
27+
}
28+
29+
type MockRunnerClient struct {
30+
MockListRunners func(opt *gitlab.ListRunnersOptions) ([]*gitlab.Runner, error)
31+
}
32+
33+
func (m *MockRunnerClient) ListRunners(opt *gitlab.ListRunnersOptions) ([]*gitlab.Runner, error) {
34+
return m.MockListRunners(opt)
35+
}

0 commit comments

Comments
 (0)