Skip to content

Commit 3135d9d

Browse files
feat: add gitlab flag
1 parent 06dbd49 commit 3135d9d

File tree

6 files changed

+25
-26
lines changed

6 files changed

+25
-26
lines changed

cmd/semantic-release/main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@ func cliHandler(c *cli.Context) error {
6161
err error
6262
)
6363

64-
switch ci.Name() {
65-
case "Gitlab":
66-
repo, err = semrel.NewGitlabRepository(c.Context, conf.Gitlab.BaseURL, conf.Slug, conf.Token, ci.GetCurrentBranch(), conf.Gitlab.ProjectID)
67-
default:
64+
if conf.GitLab {
65+
repo, err = semrel.NewGitlabRepository(c.Context, conf.GitLabBaseURL, conf.Slug, conf.Token, ci.GetCurrentBranch(), conf.GitLabProjectID)
66+
} else {
6867
repo, err = semrel.NewGithubRepository(c.Context, conf.GheHost, conf.Slug, conf.Token)
6968
}
7069

pkg/condition/condition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewCI() CI {
5050
return &TravisCI{}
5151
}
5252
if os.Getenv("GITLAB_CI") == "true" {
53-
return &Gitlab{}
53+
return &GitLab{}
5454
}
5555
return &DefaultCI{}
5656
}

pkg/condition/gitlab.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@ import (
55
"os"
66
)
77

8-
type Gitlab struct {
8+
type GitLab struct {
99
}
1010

11-
func (gl *Gitlab) Name() string {
12-
return "Gitlab"
11+
func (gl *GitLab) Name() string {
12+
return "GitLab CI"
1313
}
1414

15-
func (gl *Gitlab) GetCurrentBranch() string {
15+
func (gl *GitLab) GetCurrentBranch() string {
1616
return os.Getenv("CI_COMMIT_BRANCH")
1717
}
1818

19-
func (gl *Gitlab) GetCurrentSHA() string {
19+
func (gl *GitLab) GetCurrentSHA() string {
2020
return os.Getenv("CI_COMMIT_SHA")
2121
}
2222

23-
func (gl *Gitlab) IsBranchRef() bool {
23+
func (gl *GitLab) IsBranchRef() bool {
2424
return gl.GetCurrentBranch() != ""
2525
}
2626

27-
func (gl *Gitlab) RunCondition(config CIConfig) error {
27+
func (gl *GitLab) RunCondition(config CIConfig) error {
2828
defaultBranch := config["defaultBranch"].(string)
2929
if !gl.IsBranchRef() {
3030
return fmt.Errorf("This test run is not running on a branch build.")

pkg/condition/gitlab_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
func TestGitlabValid(t *testing.T) {
8-
gl := Gitlab{}
8+
gl := GitLab{}
99
err := gl.RunCondition(CIConfig{"defaultBranch": ""})
1010
if err == nil {
1111
t.Fail()

pkg/config/config.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ import (
88
)
99

1010
type (
11-
// Gitlab Specific Config
12-
GitlabConfig struct {
13-
BaseURL string
14-
ProjectID string
15-
}
16-
1711
// Config is a complete set of app configuration
1812
Config struct {
1913
Token string
@@ -25,12 +19,14 @@ type (
2519
Vf bool
2620
Update string
2721
GheHost string
28-
Gitlab GitlabConfig
2922
Prerelease bool
3023
TravisCom bool
3124
BetaRelease BetaRelease
3225
Match string
3326
AllowInitialDevelopmentVersions bool
27+
GitLab bool
28+
GitLabBaseURL string
29+
GitLabProjectID string
3430
}
3531

3632
BetaRelease struct {
@@ -54,10 +50,9 @@ func NewConfig(c *cli.Context) *Config {
5450
TravisCom: c.Bool("travis-com"),
5551
Match: c.String("match"),
5652
AllowInitialDevelopmentVersions: c.Bool("allow-initial-development-versions"),
57-
Gitlab: GitlabConfig{
58-
BaseURL: c.String("gitlab-base-url"),
59-
ProjectID: c.String("gitlab-project-id"),
60-
},
53+
GitLab: c.Bool("gitlab"),
54+
GitLabBaseURL: c.String("gitlab-base-url"),
55+
GitLabProjectID: c.String("gitlab-project-id"),
6156
}
6257

6358
f, err := os.OpenFile(".semrelrc", os.O_RDONLY, 0)

pkg/config/flags.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,19 @@ var CliFlags = []cli.Flag{
5959
Name: "match",
6060
Usage: "Only consider tags matching the given glob(7) pattern, excluding the \"refs/tags/\" prefix.",
6161
},
62+
&cli.BoolFlag{
63+
Name: "gitlab",
64+
Usage: "run semantic-release on GitLab",
65+
EnvVars: []string{"GITLAB_CI"},
66+
},
6267
&cli.StringFlag{
6368
Name: "gitlab-base-url",
64-
Usage: "Gitlab self hosted api path",
69+
Usage: "GitLab self hosted api path",
6570
EnvVars: []string{"CI_SERVER_URL"},
6671
},
6772
&cli.StringFlag{
6873
Name: "gitlab-project-id",
69-
Usage: "Gitlab project unique id",
74+
Usage: "GitLab project unique id",
7075
EnvVars: []string{"CI_PROJECT_ID"},
7176
},
7277
&cli.BoolFlag{

0 commit comments

Comments
 (0)