Skip to content

Commit

Permalink
feat(changelog): add github markdown support
Browse files Browse the repository at this point in the history
  • Loading branch information
zbindenren committed Jan 4, 2021
1 parent 30cc4d8 commit a1f6009
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 33 deletions.
13 changes: 3 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ var (

// Changelog configures the changelog.
type Changelog struct {
Sections []Section `yaml:"sections"`
Flavor string `yaml:"flavor"`
Sections []Section `yaml:"sections"`
GithubProjectPath string `yaml:"github_project_path"`
}

// Section is a section config.
Expand Down Expand Up @@ -84,10 +84,6 @@ func (c Changelog) Validate() error {
}
}

if !(c.Flavor == "gitlab" || c.Flavor == "github") {
return errors.New("flavor has to be either 'gitlab' or github")
}

return nil
}

Expand Down Expand Up @@ -123,9 +119,7 @@ func Read(r io.Reader) (*Changelog, error) {
return nil, err
}

c := Changelog{
Flavor: "gitlab",
}
c := Changelog{}

if err := yaml.Unmarshal(b, &c); err != nil {
return nil, fmt.Errorf("failed to unmarshal yaml: %w", err)
Expand All @@ -152,7 +146,6 @@ func Write(dir string, c Changelog) error {

// Default represents the default configuration.
var Default = Changelog{
Flavor: "gitlab",
Sections: []Section{
{
Type: "build",
Expand Down
9 changes: 4 additions & 5 deletions internal/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ const (

// Changelog creates a changelog.
type Changelog struct {
githubProjectPath string
typeSections typeSections
cfg config.Changelog
releaseType ReleaseType
logFunc func(msg string, keysAndValues ...interface{})
typeSections typeSections
cfg config.Changelog
releaseType ReleaseType
logFunc func(msg string, keysAndValues ...interface{})
}

// New creates a new Changelog.
Expand Down
8 changes: 4 additions & 4 deletions internal/changelog/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (c *Commit) writeStandard(w io.Writer) {

func (c Changelog) issueURL(issueNumber int) string {
// gitlab renders link automatically for revisions
if c.githubProjectPath == "" {
if c.cfg.GithubProjectPath == "" {
return fmt.Sprintf("#%d", issueNumber)
}

Expand All @@ -123,7 +123,7 @@ func (c Changelog) issueURL(issueNumber int) string {
issuesPath = githubIssuesPath
)

url := path.Join(githubURL, c.githubProjectPath, issuesPath) + "/"
url := path.Join(githubURL, c.cfg.GithubProjectPath, issuesPath) + "/"
issue := fmt.Sprintf("#%d", issueNumber)

s.WriteRune('[')
Expand All @@ -138,7 +138,7 @@ func (c Changelog) issueURL(issueNumber int) string {
}
func (c Changelog) revisionURL(revision string) string {
// gitlab renders link automatically for revisions
if c.githubProjectPath == "" {
if c.cfg.GithubProjectPath == "" {
return revision
}

Expand All @@ -147,7 +147,7 @@ func (c Changelog) revisionURL(revision string) string {
commitPath = githubCommitPath
)

url := path.Join(githubURL, c.githubProjectPath, commitPath) + "/"
url := path.Join(githubURL, c.cfg.GithubProjectPath, commitPath) + "/"

s.WriteRune('[')
s.WriteString(revision[:8])
Expand Down
14 changes: 0 additions & 14 deletions internal/changelog/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ type Option func(*Changelog) error
// LogFunc is a logging function.
type LogFunc func(msg string, keysAndValues ...interface{})

// WithGithubProjectPath configures the project path for github. This determines how links to issues and
// commits are created.
func WithGithubProjectPath(projectPath string) Option {
return func(c *Changelog) error {
if projectPath == "" {
return errors.New("project path is empty")
}

c.githubProjectPath = projectPath

return nil
}
}

// WithConfig configures how header types are mapped to headings and which
// sections are hidden.
func WithConfig(cfg config.Changelog) Option {
Expand Down

0 comments on commit a1f6009

Please sign in to comment.