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

mendersoftware / integration-test-runner / 1583018314

10 Dec 2024 11:26PM UTC coverage: 68.703%. Remained the same
1583018314

Pull #336

gitlab-ci

danielskinstad
ci: pin docker to v27.3

Fixes runc errors in the hetzner runner
Use dependency proxy

Ticket: QA-823

Signed-off-by: Daniel Skinstad Drabitzius <daniel.drabitzius@northern.tech>
Pull Request #336: ci: pin docker to v27.3

1732 of 2521 relevant lines covered (68.7%)

2.49 hits per line

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

73.61
/conventional_commits.go
1
package main
2

3
import (
4
        "context"
5
        "fmt"
6
        "regexp"
7
        "strings"
8

9
        "github.com/google/go-github/v28/github"
10
        "github.com/sirupsen/logrus"
11

12
        clientgithub "github.com/mendersoftware/integration-test-runner/client/github"
13
        "github.com/mendersoftware/integration-test-runner/git"
14
)
15

16
const (
17
        footer = `Changelog: All
18
Ticket: None`
19
        commentErrorPrefix = "I did my very best, but:\n"
20
)
21

22
func conventionalComittifyDependabotPr(
23
        log *logrus.Entry,
24
        comment *github.IssueCommentEvent,
25
        pr *github.PullRequest,
26
        conf *config,
27
        body string,
28
        githubClient clientgithub.Client,
29
) error {
1✔
30
        err := attemptConventionalComittifyDependabotPr(log, pr, body)
1✔
31

1✔
32
        if err == nil {
2✔
33
                return nil
1✔
34
        }
1✔
35

36
        commentBody := commentErrorPrefix + err.Error()
×
37
        if err := githubClient.CreateComment(
×
38
                context.Background(),
×
39
                conf.githubOrganization,
×
40
                comment.GetRepo().GetName(),
×
41
                pr.GetNumber(),
×
42
                &github.IssueComment{Body: &commentBody}); err != nil {
×
43
                log.Infof("Failed to comment on the pr: %v, Error: %s", pr, err.Error())
×
44
        }
×
45

46
        return err
×
47
}
48

49
func attemptConventionalComittifyDependabotPr(
50
        log *logrus.Entry,
51
        pr *github.PullRequest,
52
        body string,
53
) error {
1✔
54

1✔
55
        typeKeyword, err := getTypeKeyword(body)
1✔
56
        if err != nil {
1✔
57
                return err
×
58
        }
×
59

60
        // take message, and conventional committify it
61
        headBranch := pr.GetHead().GetRef()
1✔
62
        sshCloneUrl := pr.GetHead().GetRepo().GetSSHURL()
1✔
63
        state, err := git.Commands(
1✔
64
                git.Command("clone", "--branch", headBranch, "--single-branch", sshCloneUrl, "."),
1✔
65
        )
1✔
66
        defer state.Cleanup()
1✔
67

1✔
68
        if err != nil {
1✔
69
                return fmt.Errorf("could not clone branch %s from %s, with error:\n%w",
×
70
                        headBranch, sshCloneUrl, err)
×
71
        }
×
72

73
        messageBytes, err := git.Command("--no-pager", "show", "--no-patch", "--format=%B", "HEAD").
1✔
74
                With(state).CombinedOutput()
1✔
75
        if err != nil {
1✔
76
                return fmt.Errorf("could not retrieve last commit message with error:\n%w", err)
×
77
        }
×
78

79
        message := string(messageBytes)
1✔
80

1✔
81
        newMessage := conventionalComittifyDependabotMessage(message, typeKeyword)
1✔
82

1✔
83
        if err := git.CommandsWithState(
1✔
84
                state,
1✔
85
                git.Command("commit", "--amend", "-m", newMessage),
1✔
86
                git.Command("push", "--force"),
1✔
87
        ); err != nil {
1✔
88
                return fmt.Errorf("could not amend and push with error:\n%w", err)
×
89
        }
×
90

91
        return nil
1✔
92
}
93

94
func conventionalComittifyDependabotMessage(message string, typeKeyword string) string {
4✔
95
        message = strings.TrimSpace(message)
4✔
96
        message = strings.TrimPrefix(message, "Changelog:All: ")
4✔
97
        message = strings.TrimPrefix(message, "chore: ")
4✔
98
        message = typeKeyword + ": " + message
4✔
99

4✔
100
        fi := strings.Index(message, "Signed-off-by")
4✔
101
        if fi < 0 {
5✔
102
                fi = len(message)
1✔
103
        }
1✔
104
        message = message[:fi] + footer + "\n" + message[fi:]
4✔
105
        return strings.TrimSpace(message)
4✔
106
}
107

108
func getTypeKeyword(s string) (string, error) {
9✔
109
        r := regexp.MustCompile(commandConventionalCommit +
9✔
110
                `(?::\s*|\s+)(fix|feat|([[:word:]]+))\s*$`)
9✔
111
        matches := r.FindStringSubmatch(s)
9✔
112
        if matches == nil {
10✔
113
                return "", fmt.Errorf("could not parse the body for some reason")
1✔
114
        } else if matches[2] != "" {
10✔
115
                return "", fmt.Errorf("type keyword %s not allowed", matches[2])
1✔
116
        }
1✔
117
        return matches[1], nil
7✔
118
}
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