• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / integration-test-runner / 1819289200

15 May 2025 12:48PM UTC coverage: 64.238% (+0.02%) from 64.216%
1819289200

push

gitlab-ci

web-flow
Merge pull request #380 from danielskinstad/fix-comment

fix: remove extra `commandStartClientPipeline` from bot message

0 of 1 new or added line in 1 file covered. (0.0%)

102 existing lines in 2 files now uncovered.

1904 of 2964 relevant lines covered (64.24%)

2.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.74
/client/gitlab/client.go
1
package gitlab
2

3
import (
4
        "encoding/json"
5
        "fmt"
6

7
        gitlab "gitlab.com/gitlab-org/api/client-go"
8

9
        "github.com/mendersoftware/integration-test-runner/logger"
10
)
11

12
// Client represents a GitLab client
13
type Client interface {
14
        CancelPipelineBuild(path string, id int) error
15
        CreatePipeline(path string, options *gitlab.CreatePipelineOptions) (*gitlab.Pipeline, error)
16
        GetPipelineVariables(path string, id int) ([]*gitlab.PipelineVariable, error)
17
        ProtectRepositoryBranches(
18
                path string,
19
                options *gitlab.ProtectRepositoryBranchesOptions,
20
        ) (*gitlab.ProtectedBranch, error)
21
        UnprotectRepositoryBranches(
22
                path string,
23
                branch string,
24
                options gitlab.RequestOptionFunc,
25
        ) (*gitlab.Response, error)
26
        ListProjectPipelines(
27
                path string,
28
                options *gitlab.ListProjectPipelinesOptions,
29
        ) ([]*gitlab.PipelineInfo, error)
30
        DeleteBranch(path string,
31
                branch string,
32
                options *gitlab.RequestOptionFunc,
33
        ) (*gitlab.Response, error)
34
}
35

36
type gitLabClient struct {
37
        client     *gitlab.Client
38
        dryRunMode bool
39
}
40

41
// NewGitLabClient returns a new GitLabClient for the given conf
UNCOV
42
func NewGitLabClient(accessToken string, baseURL string, dryRunMode bool) (Client, error) {
1✔
UNCOV
43
        gitlabClient, err := gitlab.NewClient(accessToken, gitlab.WithBaseURL(baseURL))
1✔
UNCOV
44
        if err != nil {
1✔
45
                return nil, err
×
46
        }
×
UNCOV
47
        return &gitLabClient{
1✔
UNCOV
48
                client:     gitlabClient,
1✔
UNCOV
49
                dryRunMode: dryRunMode,
1✔
UNCOV
50
        }, nil
1✔
51
}
52

53
// CancelPipelineBuild cancel a pipeline
54
func (c *gitLabClient) CancelPipelineBuild(path string, id int) error {
×
55
        if c.dryRunMode {
×
56
                msg := fmt.Sprintf("gitlab.CancelPipelineBuild: path=%s,id=%d",
×
57
                        path, id,
×
58
                )
×
59
                logger.GetRequestLogger().Push(msg)
×
60
                return nil
×
61
        }
×
62
        _, _, err := c.client.Pipelines.CancelPipelineBuild(path, id, nil)
×
63
        return err
×
64
}
65

66
// CreatePipeline creates a pipeline
67
func (c *gitLabClient) CreatePipeline(
68
        path string,
69
        options *gitlab.CreatePipelineOptions,
UNCOV
70
) (*gitlab.Pipeline, error) {
1✔
UNCOV
71
        if c.dryRunMode {
2✔
UNCOV
72
                optionsJSON, _ := json.Marshal(options)
1✔
UNCOV
73
                msg := fmt.Sprintf("gitlab.CreatePipeline: path=%s,options=%s",
1✔
UNCOV
74
                        path, string(optionsJSON),
1✔
UNCOV
75
                )
1✔
UNCOV
76
                logger.GetRequestLogger().Push(msg)
1✔
UNCOV
77
                return &gitlab.Pipeline{}, nil
1✔
UNCOV
78
        }
1✔
79
        pipeline, _, err := c.client.Pipelines.CreatePipeline(path, options, nil)
×
80
        return pipeline, err
×
81
}
82

83
// GetPipelineVariables get the pipeline variables
84
func (c *gitLabClient) GetPipelineVariables(
85
        path string,
86
        id int,
UNCOV
87
) ([]*gitlab.PipelineVariable, error) {
1✔
UNCOV
88
        if c.dryRunMode {
2✔
UNCOV
89
                msg := fmt.Sprintf("gitlab.GetPipelineVariables: path=%s,id=%d",
1✔
UNCOV
90
                        path, id,
1✔
UNCOV
91
                )
1✔
UNCOV
92
                logger.GetRequestLogger().Push(msg)
1✔
UNCOV
93
                return []*gitlab.PipelineVariable{}, nil
1✔
UNCOV
94
        }
1✔
95
        variables, _, err := c.client.Pipelines.GetPipelineVariables(path, id, nil)
×
96
        return variables, err
×
97
}
98

99
// ListProjectPipelines list the project pipelines
100
func (c *gitLabClient) ListProjectPipelines(
101
        path string,
102
        options *gitlab.ListProjectPipelinesOptions,
UNCOV
103
) ([]*gitlab.PipelineInfo, error) {
1✔
UNCOV
104
        if c.dryRunMode {
2✔
UNCOV
105
                optionsJSON, _ := json.Marshal(options)
1✔
UNCOV
106
                msg := fmt.Sprintf("gitlab.ListProjectPipelines: path=%s,options=%s",
1✔
UNCOV
107
                        path, string(optionsJSON),
1✔
UNCOV
108
                )
1✔
UNCOV
109
                logger.GetRequestLogger().Push(msg)
1✔
UNCOV
110
                return []*gitlab.PipelineInfo{{ID: 1}}, nil
1✔
UNCOV
111
        }
1✔
112
        pipelines, _, err := c.client.Pipelines.ListProjectPipelines(path, options, nil)
×
113
        return pipelines, err
×
114
}
115

116
// ProtectRepositoryBranches protects branches
117
func (c *gitLabClient) ProtectRepositoryBranches(
118
        path string,
119
        options *gitlab.ProtectRepositoryBranchesOptions,
UNCOV
120
) (*gitlab.ProtectedBranch, error) {
1✔
UNCOV
121
        if c.dryRunMode {
2✔
UNCOV
122
                optionsJSON, _ := json.Marshal(options)
1✔
UNCOV
123
                msg := fmt.Sprintf("gitlab.ProtectedBranch: path=%s,options=%s",
1✔
UNCOV
124
                        path, string(optionsJSON),
1✔
UNCOV
125
                )
1✔
UNCOV
126
                logger.GetRequestLogger().Push(msg)
1✔
UNCOV
127
                return &gitlab.ProtectedBranch{}, nil
1✔
UNCOV
128
        }
1✔
129
        protected_branch, _, err := c.client.ProtectedBranches.ProtectRepositoryBranches(
×
130
                path,
×
131
                options,
×
132
                nil)
×
133
        return protected_branch, err
×
134
}
135

136
// UnprotectRepositoryBranches unprotects branches
137
func (c *gitLabClient) UnprotectRepositoryBranches(
138
        path string,
139
        branch string,
140
        options gitlab.RequestOptionFunc,
UNCOV
141
) (*gitlab.Response, error) {
1✔
UNCOV
142
        if c.dryRunMode {
2✔
UNCOV
143
                msg := fmt.Sprintf("gitlab.UnprotectedBranch: path=%s,branch=%s",
1✔
UNCOV
144
                        path, branch,
1✔
UNCOV
145
                )
1✔
UNCOV
146
                logger.GetRequestLogger().Push(msg)
1✔
UNCOV
147
                return nil, nil
1✔
UNCOV
148
        }
1✔
149
        response, err := c.client.ProtectedBranches.UnprotectRepositoryBranches(
×
150
                path,
×
151
                branch,
×
152
                options)
×
153
        return response, err
×
154
}
155

156
// DeleteBranch deletes branches
157
func (c *gitLabClient) DeleteBranch(
158
        path string,
159
        branch string,
160
        options *gitlab.RequestOptionFunc,
UNCOV
161
) (*gitlab.Response, error) {
1✔
UNCOV
162
        if c.dryRunMode {
2✔
UNCOV
163
                msg := fmt.Sprintf("gitlab.DeleteBranch: path=%s,branch=%s",
1✔
UNCOV
164
                        path, branch,
1✔
UNCOV
165
                )
1✔
UNCOV
166
                logger.GetRequestLogger().Push(msg)
1✔
UNCOV
167
                return nil, nil
1✔
UNCOV
168
        }
1✔
169
        response, err := c.client.Branches.DeleteBranch(path,
×
170
                branch,
×
171
                nil)
×
172

×
173
        return response, err
×
174
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc