-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
105 changed files
with
20,966 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/angular |
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
# Gopkg.toml example | ||
# | ||
# Refer to /~https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
|
||
[[constraint]] | ||
name = "github.com/stretchr/testify" | ||
version = "1.2.1" | ||
|
||
[[constraint]] | ||
name = "github.com/tsuyoshiwada/go-gitcmd" | ||
version = "0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# CHANGELOG | ||
|
||
{{range .Versions}} | ||
<a name="{{urlquery .Tag.Name}}"></a> | ||
## {{.Tag.Name}} ({{datetime "2006-01-02" .Tag.Date}}) | ||
{{range .CommitGroups}} | ||
### {{.Title}} | ||
{{range .Commits}} | ||
* {{if ne .Scope ""}}**{{.Scope}}:** {{end}}{{.Subject}}{{end}} | ||
{{end}}{{range .NoteGroups}} | ||
### {{.Title}} | ||
{{range .Notes}} | ||
{{.Body}} | ||
{{end}} | ||
{{end}} | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
package chglog | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"text/template" | ||
"time" | ||
|
||
gitcmd "github.com/tsuyoshiwada/go-gitcmd" | ||
) | ||
|
||
// Options ... | ||
type Options struct { | ||
Processor Processor | ||
CommitFilters map[string][]string | ||
CommitSortBy string | ||
CommitGroupBy string | ||
CommitGroupSortBy string | ||
CommitGroupTitleMaps map[string]string | ||
HeaderPattern string | ||
HeaderPatternMaps []string | ||
IssuePrefix []string | ||
RefActions []string | ||
MergeNoteTitle string | ||
MergePattern string | ||
MergePatternMaps []string | ||
RevertNoteTitle string | ||
RevertPattern string | ||
RevertPatternMaps []string | ||
NoteKeywords []string | ||
} | ||
|
||
// Info ... | ||
type Info struct { | ||
Title string | ||
RepositoryURL string | ||
} | ||
|
||
// RenderData ... | ||
type RenderData struct { | ||
Info *Info | ||
Versions []*Version | ||
} | ||
|
||
// Config ... | ||
type Config struct { | ||
Bin string | ||
Path string | ||
Template string | ||
Info *Info | ||
Options *Options | ||
} | ||
|
||
// Generator ... | ||
type Generator struct { | ||
client gitcmd.Client | ||
config *Config | ||
tagReader *tagReader | ||
tagSelector *tagSelector | ||
commitParser *commitParser | ||
commitExtractor *commitExtractor | ||
} | ||
|
||
// NewGenerator ... | ||
func NewGenerator(config *Config) *Generator { | ||
client := gitcmd.New(&gitcmd.Config{ | ||
Bin: config.Bin, | ||
}) | ||
|
||
if config.Options.Processor != nil { | ||
config.Options.Processor.Bootstrap(config) | ||
} | ||
|
||
return &Generator{ | ||
client: client, | ||
config: config, | ||
tagReader: newTagReader(client), | ||
tagSelector: newTagSelector(), | ||
commitParser: newCommitParser(client, config), | ||
commitExtractor: newCommitExtractor(config.Options), | ||
} | ||
} | ||
|
||
// Generate ... | ||
func (gen *Generator) Generate(w io.Writer, query string) error { | ||
back, err := gen.workdir() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
versions, err := gen.readVersions(query) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
back() | ||
|
||
return gen.render(w, versions) | ||
} | ||
|
||
func (gen *Generator) readVersions(query string) ([]*Version, error) { | ||
tags, err := gen.tagReader.ReadAll() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
first := "" | ||
if query != "" { | ||
tags, first, err = gen.tagSelector.Select(tags, query) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
versions := []*Version{} | ||
|
||
for i, tag := range tags { | ||
var rev string | ||
|
||
if i+1 < len(tags) { | ||
rev = tags[i+1].Name + ".." + tag.Name | ||
} else { | ||
if first != "" { | ||
rev = first + ".." + tag.Name | ||
} else { | ||
rev = tag.Name | ||
} | ||
} | ||
|
||
commits, err := gen.commitParser.Parse(rev) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
commitGroups, noteGroups := gen.commitExtractor.Extract(commits) | ||
|
||
versions = append(versions, &Version{ | ||
Tag: tag, | ||
CommitGroups: commitGroups, | ||
NoteGroups: noteGroups, | ||
}) | ||
} | ||
|
||
return versions, nil | ||
} | ||
|
||
func (gen *Generator) workdir() (func() error, error) { | ||
cwd, err := os.Getwd() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = os.Chdir(gen.config.Path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return func() error { | ||
return os.Chdir(cwd) | ||
}, nil | ||
} | ||
|
||
func (gen *Generator) render(w io.Writer, versions []*Version) error { | ||
fmap := template.FuncMap{ | ||
"datetime": func(layout string, input time.Time) string { | ||
return input.Format(layout) | ||
}, | ||
} | ||
|
||
fname := filepath.Base(gen.config.Template) | ||
|
||
t := template.Must(template.New(fname).Funcs(fmap).ParseFiles(gen.config.Template)) | ||
|
||
return t.Execute(w, &RenderData{ | ||
Info: gen.config.Info, | ||
Versions: versions, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package chglog | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func workdir(dir string) func() { | ||
cwd, _ := os.Getwd() | ||
os.Chdir(dir) | ||
return func() { | ||
os.Chdir(cwd) | ||
} | ||
} | ||
|
||
func TestGenerator(t *testing.T) { | ||
t.Skip("TODO: test") | ||
assert := assert.New(t) | ||
assert.True(true) | ||
} |
Oops, something went wrong.