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

mendersoftware / integration-test-runner / 1887464315

16 Jun 2025 02:47PM UTC coverage: 64.238% (+64.2%) from 0.0%
1887464315

push

gitlab-ci

web-flow
Merge pull request #385 from mzedel/qa-1017

QA-1017 - dependabot reviewers to CODEOWNERS

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

69.47
/gitlab_sync.go
1
package main
2

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

8
        "github.com/sirupsen/logrus"
9

10
        "github.com/mendersoftware/integration-test-runner/git"
11
)
12

13
type branchDepth int
14

15
const fullDepth = -1
16

17
func shouldStartPipeline(branchName string) bool {
8✔
18
        startByName := []string{
8✔
19
                "master",
8✔
20
                "staging",
8✔
21
                "production",
8✔
22
                "hosted",
8✔
23
                "stable",
8✔
24
                "main",
8✔
25
        }
8✔
26
        for _, n := range startByName {
34✔
27
                if branchName == n {
31✔
28
                        return true
5✔
29
                }
5✔
30
        }
31

32
        startByRegEx := []*regexp.Regexp{
3✔
33
                regexp.MustCompile(`^[0-9]+\.[0-9]+\.x`),
3✔
34
                regexp.MustCompile(`^pr_[0-9]+$`),
3✔
35
        }
3✔
36
        for _, n := range startByRegEx {
8✔
37
                if n.MatchString(branchName) {
7✔
38
                        return true
2✔
39
                }
2✔
40
        }
41

42
        return false
1✔
43
}
44

45
func syncRemoteRef(log *logrus.Entry, org, repo, ref string, conf *config) error {
2✔
46

2✔
47
        remoteURLGitLab, err := getRemoteURLGitLab(org, repo)
2✔
48
        if err != nil {
2✔
49
                return fmt.Errorf("getRemoteURLGitLab returned error: %s", err.Error())
×
50
        }
×
51

52
        state, err := git.Commands(
2✔
53
                git.Command("init", "."),
2✔
54
                git.Command("remote", "add", "github",
2✔
55
                        getRemoteURLGitHub(conf.githubProtocol, conf.githubOrganization, repo)),
2✔
56
                git.Command("remote", "add", "gitlab", remoteURLGitLab),
2✔
57
        )
2✔
58
        defer state.Cleanup()
2✔
59
        if err != nil {
2✔
60
                return err
×
61
        }
×
62

63
        depths := []branchDepth{5, 10, 50, 100, fullDepth} // 0 = infinite depth
2✔
64
        for _, depth := range depths {
4✔
65

2✔
66
                log.Infof("Fetching branch at depth: %d", depth)
2✔
67
                err := fetchCmd(ref, repo, state, depth)
2✔
68
                if err == nil {
4✔
69
                        break
2✔
70
                }
71
                log.Infof("Failed to sync the remotes at depth: %d", depth)
×
72
        }
73

74
        log.Infof("Pushed ref to GitLab: %s:%s", repo, ref)
2✔
75
        return nil
2✔
76
}
77

78
func setDepth(depth branchDepth) string {
2✔
79
        switch depth {
2✔
80
        case fullDepth:
×
81
                return ""
×
82
        default:
2✔
83
                return fmt.Sprintf("--depth=%d", depth)
2✔
84

85
        }
86
}
87

88
func fetchCmd(ref, repo string, state *git.State, depth branchDepth) error {
2✔
89

2✔
90
        if strings.Contains(ref, "tags") {
2✔
91
                tagName := strings.TrimPrefix(ref, "refs/tags/")
×
92

×
93
                err := git.Command("fetch", setDepth(depth), "--tags", "github").With(state).Run()
×
94

×
95
                if err != nil {
×
96
                        return err
×
97
                }
×
98
                err = git.Command("push", "-f", "gitlab", tagName).With(state).Run()
×
99
                if err != nil {
×
100
                        return err
×
101
                }
×
102
        } else if strings.Contains(ref, "heads") {
4✔
103
                branchName := strings.TrimPrefix(ref, "refs/heads/")
2✔
104

2✔
105
                err := git.Command("fetch", setDepth(depth), "github").With(state).Run()
2✔
106
                if err != nil {
2✔
107
                        return err
×
108
                }
×
109
                err = git.Command("checkout", "-b", branchName, "github/"+branchName).With(state).Run()
2✔
110
                if err != nil {
2✔
111
                        return err
×
112
                }
×
113
                // For the push, add option ci.skip for mender-qa
114
                cmdArgs := []string{"push", "-f"}
2✔
115
                if repo == "mender-qa" {
3✔
116
                        cmdArgs = append(cmdArgs, "-o", "ci.skip")
1✔
117
                }
1✔
118
                if !shouldStartPipeline(branchName) {
2✔
119
                        cmdArgs = append(cmdArgs, "-o", "ci.skip")
×
120
                }
×
121
                cmdArgs = append(cmdArgs, "gitlab", branchName)
2✔
122
                err = git.Command(cmdArgs...).With(state).Run()
2✔
123
                if err != nil {
2✔
124
                        return err
×
125
                }
×
126
        } else {
×
127
                return fmt.Errorf("Unrecognized ref %s", ref)
×
128
        }
×
129

130
        return nil
2✔
131
}
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