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

mendersoftware / integration-test-runner / 2361347207

03 Mar 2026 03:58PM UTC coverage: 71.625% (+0.7%) from 70.917%
2361347207

Pull #437

gitlab-ci

pasinskim
chore: Fix cyclomatic complexity

Signed-off-by: pasinskim <marcin.pasinski@northern.tech>
Pull Request #437: Add a functionality to analyze PRs by the test-bot.

518 of 697 new or added lines in 5 files covered. (74.32%)

2398 of 3348 relevant lines covered (71.62%)

2.78 hits per line

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

50.57
/client/github/client.go
1
package github
2

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

8
        "github.com/google/go-github/v28/github"
9
        "golang.org/x/oauth2"
10

11
        "github.com/mendersoftware/integration-test-runner/logger"
12
)
13

14
// Client represents a GitHub client
15
type Client interface {
16
        CreateComment(
17
                ctx context.Context,
18
                org string,
19
                repo string,
20
                number int,
21
                comment *github.IssueComment,
22
        ) error
23
        DeleteComment(
24
                ctx context.Context,
25
                org string,
26
                repo string,
27
                commentID int64,
28
        ) error
29
        IsOrganizationMember(ctx context.Context, org string, user string) bool
30
        CreatePullRequest(
31
                ctx context.Context,
32
                org string,
33
                repo string,
34
                pr *github.NewPullRequest,
35
        ) (*github.PullRequest, error)
36
        AssignPullRequest(
37
                ctx context.Context,
38
                owner, repo string,
39
                prNumber int,
40
                assignees []string,
41
        ) error
42

43
        GetPullRequest(
44
                ctx context.Context,
45
                org string,
46
                repo string,
47
                pr int,
48
        ) (*github.PullRequest, error)
49
        ListComments(
50
                ctx context.Context,
51
                owner, repo string,
52
                number int,
53
                opts *github.IssueListCommentsOptions,
54
        ) ([]*github.IssueComment, error)
55

56
        ListPullRequests(
57
                ctx context.Context,
58
                owner, repo string,
59
                opts *github.PullRequestListOptions,
60
        ) ([]*github.PullRequest, error)
61
        ListReviews(
62
                ctx context.Context,
63
                owner, repo string,
64
                number int,
65
                opts *github.ListOptions,
66
        ) ([]*github.PullRequestReview, error)
67
        ListTimeline(
68
                ctx context.Context,
69
                owner, repo string,
70
                number int,
71
                opts *github.ListOptions,
72
        ) ([]*github.Timeline, error)
73
}
74

75
type gitHubClient struct {
76
        client     *github.Client
77
        dryRunMode bool
78
}
79

80
// NewGitHubClient returns a new GitHubClient for the given conf
81
func NewGitHubClient(accessToken string, dryRunMode bool) Client {
1✔
82
        ctx := context.Background()
1✔
83
        ts := oauth2.StaticTokenSource(
1✔
84
                &oauth2.Token{AccessToken: accessToken},
1✔
85
        )
1✔
86
        tc := oauth2.NewClient(ctx, ts)
1✔
87
        client := github.NewClient(tc)
1✔
88
        return &gitHubClient{
1✔
89
                client:     client,
1✔
90
                dryRunMode: dryRunMode,
1✔
91
        }
1✔
92
}
1✔
93

94
func (c *gitHubClient) CreateComment(
95
        ctx context.Context,
96
        org string,
97
        repo string,
98
        number int,
99
        comment *github.IssueComment,
100
) error {
1✔
101
        if c.dryRunMode {
2✔
102
                commentJSON, _ := json.Marshal(comment)
1✔
103
                msg := fmt.Sprintf("github.CreateComment: org=%s,repo=%s,number=%d,comment=%s",
1✔
104
                        org, repo, number, string(commentJSON),
1✔
105
                )
1✔
106
                logger.GetRequestLogger().Push(msg)
1✔
107
                return nil
1✔
108
        }
1✔
109
        _, _, err := c.client.Issues.CreateComment(ctx, org, repo, number, comment)
×
110
        return err
×
111
}
112

113
func (c *gitHubClient) DeleteComment(
114
        ctx context.Context,
115
        org string,
116
        repo string,
117
        commentID int64,
118
) error {
×
119
        if c.dryRunMode {
×
120
                msg := fmt.Sprintf("github.DeleteComment: org=%s,repo=%s,commentID=%d",
×
121
                        org, repo, commentID,
×
122
                )
×
123
                logger.GetRequestLogger().Push(msg)
×
124
                return nil
×
125
        }
×
126
        _, err := c.client.Issues.DeleteComment(ctx, org, repo, commentID)
×
127
        return err
×
128
}
129

130
func (c *gitHubClient) IsOrganizationMember(ctx context.Context, org string, user string) bool {
1✔
131
        if c.dryRunMode {
2✔
132
                msg := fmt.Sprintf("github.IsOrganizationMember: org=%s,user=%s", org, user)
1✔
133
                logger.GetRequestLogger().Push(msg)
1✔
134
                return true
1✔
135
        }
1✔
136
        res, _, _ := c.client.Organizations.IsMember(ctx, org, user)
×
137
        return res
×
138
}
139

140
func (c *gitHubClient) CreatePullRequest(
141
        ctx context.Context,
142
        org string,
143
        repo string,
144
        pr *github.NewPullRequest,
145
) (*github.PullRequest, error) {
1✔
146
        if c.dryRunMode {
2✔
147
                prJSON, _ := json.Marshal(pr)
1✔
148
                msg := fmt.Sprintf("github.CreatePullRequest: org=%s,repo=%s,pr=%s",
1✔
149
                        org, repo, string(prJSON),
1✔
150
                )
1✔
151
                logger.GetRequestLogger().Push(msg)
1✔
152
                return &github.PullRequest{}, nil
1✔
153
        }
1✔
154
        newPR, _, err := c.client.PullRequests.Create(ctx, org, repo, pr)
×
155
        return newPR, err
×
156
}
157

158
func (c *gitHubClient) AssignPullRequest(
159
        ctx context.Context,
160
        owner, repo string,
161
        prNumber int, assignees []string,
162
) error {
×
163
        if len(assignees) == 0 {
×
164
                return nil
×
165
        }
×
166
        _, res, err := c.client.Issues.AddAssignees(ctx, owner, repo, prNumber, assignees)
×
167
        if err != nil {
×
168
                return fmt.Errorf("failed to assign pull request: %w", err)
×
169
        }
×
170
        if res.StatusCode >= 300 {
×
171
                return fmt.Errorf(
×
172
                        "failed to assign pull request: unexpected status code %d",
×
173
                        res.StatusCode,
×
174
                )
×
175
        }
×
176
        return nil
×
177
}
178

179
func (c *gitHubClient) GetPullRequest(
180
        ctx context.Context,
181
        org string,
182
        repo string,
183
        pr int,
184
) (*github.PullRequest, error) {
1✔
185
        newPR, _, err := c.client.PullRequests.Get(ctx, org, repo, pr)
1✔
186
        return newPR, err
1✔
187
}
1✔
188

189
func (c *gitHubClient) ListComments(
190
        ctx context.Context,
191
        owner, repo string,
192
        number int,
193
        opts *github.IssueListCommentsOptions,
194
) ([]*github.IssueComment, error) {
1✔
195
        comments, _, err := c.client.Issues.ListComments(ctx, owner, repo, number, opts)
1✔
196
        return comments, err
1✔
197
}
1✔
198

199
func (c *gitHubClient) ListPullRequests(
200
        ctx context.Context,
201
        owner, repo string,
202
        opts *github.PullRequestListOptions,
NEW
203
) ([]*github.PullRequest, error) {
×
NEW
204
        prs, _, err := c.client.PullRequests.List(ctx, owner, repo, opts)
×
NEW
205
        return prs, err
×
NEW
206
}
×
207

208
func (c *gitHubClient) ListReviews(
209
        ctx context.Context,
210
        owner, repo string,
211
        number int,
212
        opts *github.ListOptions,
NEW
213
) ([]*github.PullRequestReview, error) {
×
NEW
214
        reviews, _, err := c.client.PullRequests.ListReviews(ctx, owner, repo, number, opts)
×
NEW
215
        return reviews, err
×
NEW
216
}
×
217

218
func (c *gitHubClient) ListTimeline(
219
        ctx context.Context,
220
        owner, repo string,
221
        number int,
222
        opts *github.ListOptions,
NEW
223
) ([]*github.Timeline, error) {
×
NEW
224
        timeline, _, err := c.client.Issues.ListIssueTimeline(ctx, owner, repo, number, opts)
×
NEW
225
        return timeline, err
×
NEW
226
}
×
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

© 2026 Coveralls, Inc