• 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

58.67
/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

57
type gitHubClient struct {
58
        client     *github.Client
59
        dryRunMode bool
60
}
61

62
// NewGitHubClient returns a new GitHubClient for the given conf
UNCOV
63
func NewGitHubClient(accessToken string, dryRunMode bool) Client {
1✔
UNCOV
64
        ctx := context.Background()
1✔
UNCOV
65
        ts := oauth2.StaticTokenSource(
1✔
UNCOV
66
                &oauth2.Token{AccessToken: accessToken},
1✔
UNCOV
67
        )
1✔
UNCOV
68
        tc := oauth2.NewClient(ctx, ts)
1✔
UNCOV
69
        client := github.NewClient(tc)
1✔
UNCOV
70
        return &gitHubClient{
1✔
UNCOV
71
                client:     client,
1✔
UNCOV
72
                dryRunMode: dryRunMode,
1✔
UNCOV
73
        }
1✔
UNCOV
74
}
1✔
75

76
func (c *gitHubClient) CreateComment(
77
        ctx context.Context,
78
        org string,
79
        repo string,
80
        number int,
81
        comment *github.IssueComment,
UNCOV
82
) error {
1✔
UNCOV
83
        if c.dryRunMode {
2✔
UNCOV
84
                commentJSON, _ := json.Marshal(comment)
1✔
UNCOV
85
                msg := fmt.Sprintf("github.CreateComment: org=%s,repo=%s,number=%d,comment=%s",
1✔
UNCOV
86
                        org, repo, number, string(commentJSON),
1✔
UNCOV
87
                )
1✔
UNCOV
88
                logger.GetRequestLogger().Push(msg)
1✔
UNCOV
89
                return nil
1✔
UNCOV
90
        }
1✔
91
        _, _, err := c.client.Issues.CreateComment(ctx, org, repo, number, comment)
×
92
        return err
×
93
}
94

95
func (c *gitHubClient) DeleteComment(
96
        ctx context.Context,
97
        org string,
98
        repo string,
99
        commentID int64,
100
) error {
×
101
        if c.dryRunMode {
×
102
                msg := fmt.Sprintf("github.DeleteComment: org=%s,repo=%s,commentID=%d",
×
103
                        org, repo, commentID,
×
104
                )
×
105
                logger.GetRequestLogger().Push(msg)
×
106
                return nil
×
107
        }
×
108
        _, err := c.client.Issues.DeleteComment(ctx, org, repo, commentID)
×
109
        return err
×
110
}
111

UNCOV
112
func (c *gitHubClient) IsOrganizationMember(ctx context.Context, org string, user string) bool {
1✔
UNCOV
113
        if c.dryRunMode {
2✔
UNCOV
114
                msg := fmt.Sprintf("github.IsOrganizationMember: org=%s,user=%s", org, user)
1✔
UNCOV
115
                logger.GetRequestLogger().Push(msg)
1✔
UNCOV
116
                return true
1✔
UNCOV
117
        }
1✔
118
        res, _, _ := c.client.Organizations.IsMember(ctx, org, user)
×
119
        return res
×
120
}
121

122
func (c *gitHubClient) CreatePullRequest(
123
        ctx context.Context,
124
        org string,
125
        repo string,
126
        pr *github.NewPullRequest,
UNCOV
127
) (*github.PullRequest, error) {
1✔
UNCOV
128
        if c.dryRunMode {
2✔
UNCOV
129
                prJSON, _ := json.Marshal(pr)
1✔
UNCOV
130
                msg := fmt.Sprintf("github.CreatePullRequest: org=%s,repo=%s,pr=%s",
1✔
UNCOV
131
                        org, repo, string(prJSON),
1✔
UNCOV
132
                )
1✔
UNCOV
133
                logger.GetRequestLogger().Push(msg)
1✔
UNCOV
134
                return &github.PullRequest{}, nil
1✔
UNCOV
135
        }
1✔
136
        newPR, _, err := c.client.PullRequests.Create(ctx, org, repo, pr)
×
137
        return newPR, err
×
138
}
139

140
func (c *gitHubClient) AssignPullRequest(
141
        ctx context.Context,
142
        owner, repo string,
143
        prNumber int, assignees []string,
144
) error {
×
145
        if len(assignees) == 0 {
×
146
                return nil
×
147
        }
×
148
        _, res, err := c.client.Issues.AddAssignees(ctx, owner, repo, prNumber, assignees)
×
149
        if err != nil {
×
150
                return fmt.Errorf("failed to assign pull request: %w", err)
×
151
        }
×
152
        if res.StatusCode >= 300 {
×
153
                return fmt.Errorf(
×
154
                        "failed to assign pull request: unexpected status code %d",
×
155
                        res.StatusCode,
×
156
                )
×
157
        }
×
158
        return nil
×
159
}
160

161
func (c *gitHubClient) GetPullRequest(
162
        ctx context.Context,
163
        org string,
164
        repo string,
165
        pr int,
UNCOV
166
) (*github.PullRequest, error) {
1✔
UNCOV
167
        newPR, _, err := c.client.PullRequests.Get(ctx, org, repo, pr)
1✔
UNCOV
168
        return newPR, err
1✔
UNCOV
169
}
1✔
170

171
func (c *gitHubClient) ListComments(
172
        ctx context.Context,
173
        owner, repo string,
174
        number int,
175
        opts *github.IssueListCommentsOptions,
UNCOV
176
) ([]*github.IssueComment, error) {
1✔
UNCOV
177
        comments, _, err := c.client.Issues.ListComments(ctx, owner, repo, number, opts)
1✔
UNCOV
178
        return comments, err
1✔
UNCOV
179
}
1✔
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