feat(releaser): add git only as releaser, will create a new tag with version only

This commit is contained in:
Nightapes
2020-01-05 18:41:44 +01:00
parent 6211095c38
commit 42fc522a43
19 changed files with 284 additions and 109 deletions

View File

@@ -34,9 +34,9 @@ type Client struct {
}
// New initialize a new gitlabRelease
func New(config *config.GitLabProvider) (*Client, error) {
func New(config *config.GitLabProvider, checkConfig bool) (*Client, error) {
accessToken, err := util.GetAccessToken(fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(GITLAB)))
if err != nil {
if err != nil && checkConfig {
return nil, err
}
@@ -52,7 +52,7 @@ func New(config *config.GitLabProvider) (*Client, error) {
logger.Debugf("validate gitlab provider config")
if config.Repo == "" {
if config.Repo == "" && checkConfig {
return nil, fmt.Errorf("gitlab Repro is not set")
}
@@ -85,16 +85,10 @@ func (g *Client) GetCompareURL(oldVersion, newVersion string) string {
return fmt.Sprintf("%s/%s/compare/%s...%s", g.baseURL, g.config.Repo, oldVersion, newVersion)
}
//ValidateConfig for gitlab
func (g *Client) ValidateConfig() error {
return nil
}
// CreateRelease creates release on remote
func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error {
tag := releaseVersion.Next.Version.String()
tag := "v" + releaseVersion.Next.Version.String()
g.Release = tag
g.log.Infof("create release with version %s", tag)
url := fmt.Sprintf("%s/projects/%s/releases", g.apiURL, util.PathEscape(g.config.Repo))

View File

@@ -24,7 +24,7 @@ func TestGetCommitURL(t *testing.T) {
client, err := gitlab.New(&config.GitLabProvider{
CustomURL: "https://localhost/",
Repo: "test/test",
})
}, true)
assert.NoError(t, err)
assert.Equal(t, "https://localhost/test/test/commit/{{hash}}", client.GetCommitURL())
}
@@ -35,7 +35,7 @@ func TestGetCompareURL(t *testing.T) {
client, err := gitlab.New(&config.GitLabProvider{
CustomURL: "https://localhost/",
Repo: "test/test",
})
}, true)
assert.NoError(t, err)
assert.Equal(t, "https://localhost/test/test/compare/1.0.0...1.0.1", client.GetCompareURL("1.0.0", "1.0.1"))
}
@@ -45,7 +45,7 @@ func TestValidateConfig_EmptyRepro(t *testing.T) {
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
_, err := gitlab.New(&config.GitLabProvider{
CustomURL: "https://localhost/",
})
}, true)
assert.Error(t, err)
}
@@ -55,7 +55,7 @@ func TestValidateConfig_DefaultURL(t *testing.T) {
config := &config.GitLabProvider{
Repo: "localhost/test",
}
_, err := gitlab.New(config)
_, err := gitlab.New(config, true)
assert.NoError(t, err)
assert.Equal(t, "https://gitlab.com", config.CustomURL)
}
@@ -67,7 +67,7 @@ func TestValidateConfig_CustomURL(t *testing.T) {
Repo: "/localhost/test/",
CustomURL: "https://localhost/",
}
_, err := gitlab.New(config)
_, err := gitlab.New(config, true)
assert.NoError(t, err)
assert.Equal(t, "https://localhost", config.CustomURL)
assert.Equal(t, "localhost/test", config.Repo)
@@ -108,7 +108,7 @@ func TestCreateRelease(t *testing.T) {
},
responseBody: "{}",
responseCode: 200,
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content"}`,
requestBody: `{"tag_name":"v2.0.0","name":"title","ref":"master","description":"content"}`,
valid: true,
},
{
@@ -132,7 +132,7 @@ func TestCreateRelease(t *testing.T) {
},
responseBody: "{}",
responseCode: 500,
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content"}`,
requestBody: `{"tag_name":"v2.0.0","name":"title","ref":"master","description":"content"}`,
valid: false,
},
{
@@ -157,7 +157,7 @@ func TestCreateRelease(t *testing.T) {
},
responseCode: 400,
responseBody: "{}",
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content"}`,
requestBody: `{"tag_name":"v2.0.0","name":"title","ref":"master","description":"content"}`,
valid: false,
},
}
@@ -190,7 +190,7 @@ func TestCreateRelease(t *testing.T) {
}
os.Setenv("GITLAB_ACCESS_TOKEN", "aToken")
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
client, err := gitlab.New(&testObject.config)
client, err := gitlab.New(&testObject.config, false)
assert.NoError(t, err)
err = client.CreateRelease(testObject.releaseVersion, testObject.generatedChangelog)
@@ -317,7 +317,7 @@ func TestUploadAssets(t *testing.T) {
}
os.Setenv("GITLAB_ACCESS_TOKEN", "aToken")
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
client, err := gitlab.New(&testObject.config)
client, err := gitlab.New(&testObject.config, false)
assert.NoError(t, err)
client.Release = "1.0.0"