You've already forked go-semantic-release
feat(changelog): add docker usage to changelog
This commit is contained in:
@@ -31,17 +31,34 @@ introduced by commit:
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
{{ if .HasDocker}}
|
||||
## Docker image
|
||||
|
||||
New docker image is released under {{$.Backtick}}{{.DockerRepository}}:{{.Version}}{{$.Backtick}}
|
||||
|
||||
### Usage
|
||||
|
||||
{{$.Backtick}}docker run {{.DockerRepository}}:{{.Version}}{{$.Backtick}}
|
||||
{{ if .HasDockerLatest}}
|
||||
or
|
||||
|
||||
{{$.Backtick}}docker run {{.DockerRepository}}:latest{{$.Backtick}}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
`
|
||||
|
||||
type changelogContent struct {
|
||||
Commits map[string][]shared.AnalyzedCommit
|
||||
BreakingChanges []shared.AnalyzedCommit
|
||||
Order []string
|
||||
Version string
|
||||
Now time.Time
|
||||
Backtick string
|
||||
HasURL bool
|
||||
URL string
|
||||
Commits map[string][]shared.AnalyzedCommit
|
||||
BreakingChanges []shared.AnalyzedCommit
|
||||
Order []string
|
||||
Version string
|
||||
Now time.Time
|
||||
Backtick string
|
||||
HasURL bool
|
||||
URL string
|
||||
HasDocker bool
|
||||
HasDockerLatest bool
|
||||
DockerRepository string
|
||||
}
|
||||
|
||||
//Changelog struct
|
||||
@@ -92,14 +109,17 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
|
||||
}
|
||||
|
||||
changelogContent := changelogContent{
|
||||
Version: templateConfig.Version,
|
||||
Commits: commitsPerScope,
|
||||
Now: c.releaseTime,
|
||||
BreakingChanges: commitsBreakingChange,
|
||||
Backtick: "`",
|
||||
Order: order,
|
||||
HasURL: templateConfig.CommitURL != "",
|
||||
URL: templateConfig.CommitURL,
|
||||
Version: templateConfig.Version,
|
||||
Commits: commitsPerScope,
|
||||
Now: c.releaseTime,
|
||||
BreakingChanges: commitsBreakingChange,
|
||||
Backtick: "`",
|
||||
Order: order,
|
||||
HasURL: templateConfig.CommitURL != "",
|
||||
URL: templateConfig.CommitURL,
|
||||
HasDocker: c.config.Changelog.Docker.Repository != "",
|
||||
HasDockerLatest: c.config.Changelog.Docker.Latest,
|
||||
DockerRepository: c.config.Changelog.Docker.Repository,
|
||||
}
|
||||
|
||||
title, err := generateTemplate(defaultChangelogTitle, changelogContent)
|
||||
|
||||
@@ -2,7 +2,6 @@ package gitlab
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -26,7 +25,6 @@ const GITLAB = "gitlab"
|
||||
// Client type struct
|
||||
type Client struct {
|
||||
config *config.GitLabProvider
|
||||
context context.Context
|
||||
client *http.Client
|
||||
baseURL string
|
||||
apiURL string
|
||||
@@ -36,8 +34,12 @@ type Client struct {
|
||||
}
|
||||
|
||||
// New initialize a new gitlabRelease
|
||||
func New(config *config.GitLabProvider, accessToken string) (*Client, error) {
|
||||
ctx := context.Background()
|
||||
func New(config *config.GitLabProvider) (*Client, error) {
|
||||
accessToken, err := util.GetAccessToken(fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(GITLAB)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tokenHeader := util.NewAddHeaderTransport(nil, "PRIVATE-TOKEN", accessToken)
|
||||
acceptHeader := util.NewAddHeaderTransport(tokenHeader, "Accept", "application/json")
|
||||
httpClient := &http.Client{
|
||||
@@ -65,7 +67,6 @@ func New(config *config.GitLabProvider, accessToken string) (*Client, error) {
|
||||
return &Client{
|
||||
token: accessToken,
|
||||
config: config,
|
||||
context: ctx,
|
||||
baseURL: config.CustomURL,
|
||||
apiURL: config.CustomURL + "/api/v4",
|
||||
client: httpClient,
|
||||
|
||||
@@ -20,47 +20,55 @@ import (
|
||||
)
|
||||
|
||||
func TestGetCommitURL(t *testing.T) {
|
||||
|
||||
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||
client, err := gitlab.New(&config.GitLabProvider{
|
||||
CustomURL: "https://localhost/",
|
||||
Repo: "test/test",
|
||||
}, "aToken")
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "https://localhost/test/test/commit/{{hash}}", client.GetCommitURL())
|
||||
}
|
||||
|
||||
func TestGetCompareURL(t *testing.T) {
|
||||
|
||||
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||
client, err := gitlab.New(&config.GitLabProvider{
|
||||
CustomURL: "https://localhost/",
|
||||
Repo: "test/test",
|
||||
}, "aToken")
|
||||
})
|
||||
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"))
|
||||
}
|
||||
|
||||
func TestValidateConfig_EmptyRepro(t *testing.T) {
|
||||
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||
_, err := gitlab.New(&config.GitLabProvider{
|
||||
CustomURL: "https://localhost/",
|
||||
}, "aToken")
|
||||
})
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestValidateConfig_DefaultURL(t *testing.T) {
|
||||
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||
config := &config.GitLabProvider{
|
||||
Repo: "localhost/test",
|
||||
}
|
||||
_, err := gitlab.New(config, "aToken")
|
||||
_, err := gitlab.New(config)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "https://gitlab.com", config.CustomURL)
|
||||
}
|
||||
|
||||
func TestValidateConfig_CustomURL(t *testing.T) {
|
||||
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||
config := &config.GitLabProvider{
|
||||
Repo: "/localhost/test/",
|
||||
CustomURL: "https://localhost/",
|
||||
}
|
||||
_, err := gitlab.New(config, "aToken")
|
||||
_, err := gitlab.New(config)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "https://localhost", config.CustomURL)
|
||||
assert.Equal(t, "localhost/test", config.Repo)
|
||||
@@ -181,8 +189,9 @@ func TestCreateRelease(t *testing.T) {
|
||||
if testObject.config.CustomURL == "" {
|
||||
testObject.config.CustomURL = testServer.URL
|
||||
}
|
||||
|
||||
client, err := gitlab.New(&testObject.config, "aToken")
|
||||
os.Setenv("GITLAB_ACCESS_TOKEN", "aToken")
|
||||
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||
client, err := gitlab.New(&testObject.config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = client.CreateRelease(testObject.releaseVersion, testObject.generatedChangelog)
|
||||
@@ -307,8 +316,9 @@ func TestUploadAssets(t *testing.T) {
|
||||
if testObject.config.CustomURL == "" {
|
||||
testObject.config.CustomURL = testServer.URL
|
||||
}
|
||||
|
||||
client, err := gitlab.New(&testObject.config, "aToken")
|
||||
os.Setenv("GITLAB_ACCESS_TOKEN", "aToken")
|
||||
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||
client, err := gitlab.New(&testObject.config)
|
||||
assert.NoError(t, err)
|
||||
client.Release = "1.0.0"
|
||||
|
||||
|
||||
@@ -2,11 +2,9 @@ package releaser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/internal/releaser/github"
|
||||
"github.com/Nightapes/go-semantic-release/internal/releaser/gitlab"
|
||||
"github.com/Nightapes/go-semantic-release/internal/releaser/util"
|
||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||
@@ -42,11 +40,7 @@ func (r *Releasers) GetReleaser() (Releaser, error) {
|
||||
return github.New(&r.config.GitHubProvider)
|
||||
case gitlab.GITLAB:
|
||||
log.Debugf("initialize new %s-provider", gitlab.GITLAB)
|
||||
accessToken, err := util.GetAccessToken(fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(gitlab.GITLAB)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gitlab.New(&r.config.GitLabProvider, accessToken)
|
||||
return gitlab.New(&r.config.GitLabProvider)
|
||||
}
|
||||
return nil, fmt.Errorf("could not initialize a releaser from this type: %s", r.config.Release)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user