-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgitlab.go
41 lines (32 loc) · 911 Bytes
/
gitlab.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package condition
import (
"fmt"
"os"
)
var CIVERSION = "dev"
type GitLab struct{}
func (gl *GitLab) Name() string {
return "GitLab CI"
}
func (gl *GitLab) Version() string {
return CIVERSION
}
func (gl *GitLab) GetCurrentBranch() string {
return os.Getenv("CI_COMMIT_BRANCH")
}
func (gl *GitLab) GetCurrentSHA() string {
return os.Getenv("CI_COMMIT_SHA")
}
func (gl *GitLab) IsBranchRef() bool {
return gl.GetCurrentBranch() != ""
}
func (gl *GitLab) RunCondition(config map[string]string) error {
defaultBranch := config["defaultBranch"]
if !gl.IsBranchRef() {
return fmt.Errorf("this test run is not running on a branch build")
}
if branch := gl.GetCurrentBranch(); defaultBranch != "*" && branch != defaultBranch {
return fmt.Errorf("this test run was triggered on the branch %s, while semantic-release is configured to only publish from %s", branch, defaultBranch)
}
return nil
}