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

mendersoftware / integration-test-runner / 1681953125

21 Feb 2025 08:24AM UTC coverage: 59.965% (-4.4%) from 64.328%
1681953125

Pull #357

gitlab-ci

danielskinstad
feat: run integration pipeline on demand

Allow you to run the full integration pipeline on a protected branch
when a trusted member runs `start integration pipeline`.

As of now, this will only run with main - and you cannot specify PRs to
run the pipeline with.

Ticket: QA-863

Signed-off-by: Daniel Skinstad Drabitzius <daniel.drabitzius@northern.tech>
Pull Request #357: wip: integration tests on demand

77 of 311 new or added lines in 7 files covered. (24.76%)

2 existing lines in 1 file now uncovered.

1736 of 2895 relevant lines covered (59.97%)

2.19 hits per line

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

50.77
/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
        ListProjectPipelines(
22
                path string,
23
                options *gitlab.ListProjectPipelinesOptions,
24
        ) ([]*gitlab.PipelineInfo, error)
25
}
26

27
type gitLabClient struct {
28
        client     *gitlab.Client
29
        dryRunMode bool
30
}
31

32
// NewGitLabClient returns a new GitLabClient for the given conf
33
func NewGitLabClient(accessToken string, baseURL string, dryRunMode bool) (Client, error) {
1✔
34
        gitlabClient, err := gitlab.NewClient(accessToken, gitlab.WithBaseURL(baseURL))
1✔
35
        if err != nil {
1✔
36
                return nil, err
×
37
        }
×
38
        return &gitLabClient{
1✔
39
                client:     gitlabClient,
1✔
40
                dryRunMode: dryRunMode,
1✔
41
        }, nil
1✔
42
}
43

44
// CancelPipelineBuild cancel a pipeline
45
func (c *gitLabClient) CancelPipelineBuild(path string, id int) error {
×
46
        if c.dryRunMode {
×
47
                msg := fmt.Sprintf("gitlab.CancelPipelineBuild: path=%s,id=%d",
×
48
                        path, id,
×
49
                )
×
50
                logger.GetRequestLogger().Push(msg)
×
51
                return nil
×
52
        }
×
53
        _, _, err := c.client.Pipelines.CancelPipelineBuild(path, id, nil)
×
54
        return err
×
55
}
56

57
// CreatePipeline creates a pipeline
58
func (c *gitLabClient) CreatePipeline(
59
        path string,
60
        options *gitlab.CreatePipelineOptions,
61
) (*gitlab.Pipeline, error) {
1✔
62
        if c.dryRunMode {
2✔
63
                optionsJSON, _ := json.Marshal(options)
1✔
64
                msg := fmt.Sprintf("gitlab.CreatePipeline: path=%s,options=%s",
1✔
65
                        path, string(optionsJSON),
1✔
66
                )
1✔
67
                logger.GetRequestLogger().Push(msg)
1✔
68
                return &gitlab.Pipeline{}, nil
1✔
69
        }
1✔
70
        pipeline, _, err := c.client.Pipelines.CreatePipeline(path, options, nil)
×
71
        return pipeline, err
×
72
}
73

74
// GetPipelineVariables get the pipeline variables
75
func (c *gitLabClient) GetPipelineVariables(
76
        path string,
77
        id int,
78
) ([]*gitlab.PipelineVariable, error) {
1✔
79
        if c.dryRunMode {
2✔
80
                msg := fmt.Sprintf("gitlab.GetPipelineVariables: path=%s,id=%d",
1✔
81
                        path, id,
1✔
82
                )
1✔
83
                logger.GetRequestLogger().Push(msg)
1✔
84
                return []*gitlab.PipelineVariable{}, nil
1✔
85
        }
1✔
86
        variables, _, err := c.client.Pipelines.GetPipelineVariables(path, id, nil)
×
87
        return variables, err
×
88
}
89

90
// ListProjectPipelines list the project pipelines
91
func (c *gitLabClient) ListProjectPipelines(
92
        path string,
93
        options *gitlab.ListProjectPipelinesOptions,
94
) ([]*gitlab.PipelineInfo, error) {
1✔
95
        if c.dryRunMode {
2✔
96
                optionsJSON, _ := json.Marshal(options)
1✔
97
                msg := fmt.Sprintf("gitlab.ListProjectPipelines: path=%s,options=%s",
1✔
98
                        path, string(optionsJSON),
1✔
99
                )
1✔
100
                logger.GetRequestLogger().Push(msg)
1✔
101
                return []*gitlab.PipelineInfo{{ID: 1}}, nil
1✔
102
        }
1✔
103
        pipelines, _, err := c.client.Pipelines.ListProjectPipelines(path, options, nil)
×
104
        return pipelines, err
×
105
}
106

107
// ProtectRepositoryBranches protects branches
108
func (c *gitLabClient) ProtectRepositoryBranches(
109
        path string,
110
        options *gitlab.ProtectRepositoryBranchesOptions,
NEW
111
) (*gitlab.ProtectedBranch, error) {
×
NEW
112
        if c.dryRunMode {
×
NEW
113
                optionsJSON, _ := json.Marshal(options)
×
NEW
114
                msg := fmt.Sprintf("gitlab.ProtectedBranch: path=%s,options=%s",
×
NEW
115
                        path, string(optionsJSON),
×
NEW
116
                )
×
NEW
117
                logger.GetRequestLogger().Push(msg)
×
NEW
118
                return &gitlab.ProtectedBranch{}, nil
×
NEW
119
        }
×
NEW
120
        protected_branch, _, err := c.client.ProtectedBranches.ProtectRepositoryBranches(
×
NEW
121
                path,
×
NEW
122
                options,
×
NEW
123
                nil)
×
NEW
124
        return protected_branch, err
×
125
}
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