mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-21 22:10:39 +00:00
feat: add special value next for tag filters
This commit is contained in:
parent
e5c4415f1e
commit
be1b592470
@ -16,6 +16,7 @@ func ChangelogFlags(settings *app.ChangelogSettings) []cli.Flag {
|
|||||||
Name: "size",
|
Name: "size",
|
||||||
Value: 10, //nolint:gomnd
|
Value: 10, //nolint:gomnd
|
||||||
Aliases: []string{"n"},
|
Aliases: []string{"n"},
|
||||||
|
Destination: &settings.Size,
|
||||||
Usage: "get changelog from last 'n' tags",
|
Usage: "get changelog from last 'n' tags",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
@ -43,7 +44,7 @@ func ChangelogFlags(settings *app.ChangelogSettings) []cli.Flag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gocognit
|
//nolint:gocognit
|
||||||
func ChangelogHandler(g app.GitSV) cli.ActionFunc {
|
func ChangelogHandler(g app.GitSV, settings *app.ChangelogSettings) cli.ActionFunc {
|
||||||
return func(c *cli.Context) error {
|
return func(c *cli.Context) error {
|
||||||
tags, err := g.Tags()
|
tags, err := g.Tags()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -56,7 +57,7 @@ func ChangelogHandler(g app.GitSV) cli.ActionFunc {
|
|||||||
|
|
||||||
var releaseNotes []sv.ReleaseNote
|
var releaseNotes []sv.ReleaseNote
|
||||||
|
|
||||||
if g.Settings.ChangelogSettings.AddNext {
|
if settings.AddNext {
|
||||||
rnVersion, updated, date, commits, uerr := getNextVersionInfo(g, g.CommitProcessor)
|
rnVersion, updated, date, commits, uerr := getNextVersionInfo(g, g.CommitProcessor)
|
||||||
if uerr != nil {
|
if uerr != nil {
|
||||||
return uerr
|
return uerr
|
||||||
@ -68,7 +69,7 @@ func ChangelogHandler(g app.GitSV) cli.ActionFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, tag := range tags {
|
for i, tag := range tags {
|
||||||
if !g.Settings.ChangelogSettings.All && i >= g.Settings.ChangelogSettings.Size {
|
if !settings.All && i >= settings.Size {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +78,7 @@ func ChangelogHandler(g app.GitSV) cli.ActionFunc {
|
|||||||
previousTag = tags[i+1].Name
|
previousTag = tags[i+1].Name
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.Settings.ChangelogSettings.Strict && !sv.IsValidVersion(tag.Name) {
|
if settings.Strict && !sv.IsValidVersion(tag.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,13 +96,13 @@ func ChangelogHandler(g app.GitSV) cli.ActionFunc {
|
|||||||
return fmt.Errorf("could not format changelog: %w", err)
|
return fmt.Errorf("could not format changelog: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.Settings.ChangelogSettings.Out == "" {
|
if settings.Out == "" {
|
||||||
os.Stdout.WriteString(fmt.Sprintf("%s\n", output))
|
os.Stdout.WriteString(fmt.Sprintf("%s\n", output))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
w, err := os.Create(g.Settings.ChangelogSettings.Out)
|
w, err := os.Create(settings.Out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not write changelog: %w", err)
|
return fmt.Errorf("could not write changelog: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/thegeeklab/git-sv/app"
|
"github.com/thegeeklab/git-sv/app"
|
||||||
"github.com/thegeeklab/git-sv/sv"
|
"github.com/thegeeklab/git-sv/sv"
|
||||||
@ -16,56 +17,61 @@ var (
|
|||||||
errUnknownTag = errors.New("unknown tag")
|
errUnknownTag = errors.New("unknown tag")
|
||||||
)
|
)
|
||||||
|
|
||||||
func CommitLogFlags() []cli.Flag {
|
func CommitLogFlags(settings *app.CommitLogSettings) []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "t",
|
Name: "t",
|
||||||
Aliases: []string{"tag"},
|
Aliases: []string{"tag"},
|
||||||
Usage: "get commit log from a specific tag",
|
Usage: "get commit log from a specific tag",
|
||||||
|
Destination: &settings.Tag,
|
||||||
|
Value: "next",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "r",
|
Name: "r",
|
||||||
Aliases: []string{"range"},
|
Aliases: []string{"range"},
|
||||||
Usage: "type of range of commits, use: tag, date or hash",
|
Usage: "type of range of commits, use: tag, date or hash",
|
||||||
|
Destination: &settings.Range,
|
||||||
Value: string(app.TagRange),
|
Value: string(app.TagRange),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "s",
|
Name: "s",
|
||||||
Aliases: []string{"start"},
|
Aliases: []string{"start"},
|
||||||
Usage: "start range of git log revision range, if date, the value is used on since flag instead",
|
Usage: "start range of git log revision range, if date, the value is used on since flag instead",
|
||||||
|
Destination: &settings.Start,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "e",
|
Name: "e",
|
||||||
Aliases: []string{"end"},
|
Aliases: []string{"end"},
|
||||||
Usage: "end range of git log revision range, if date, the value is used on until flag instead",
|
Usage: "end range of git log revision range, if date, the value is used on until flag instead",
|
||||||
|
Destination: &settings.End,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CommitLogHandler(g app.GitSV) cli.ActionFunc {
|
func CommitLogHandler(g app.GitSV, settings *app.CommitLogSettings) cli.ActionFunc {
|
||||||
return func(c *cli.Context) error {
|
return func(c *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
commits []sv.CommitLog
|
commits []sv.CommitLog
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
tagFlag := c.String("t")
|
tagDefault := "next"
|
||||||
rangeFlag := c.String("r")
|
tagFlag := strings.TrimSpace(strings.ToLower(settings.Tag))
|
||||||
startFlag := c.String("s")
|
|
||||||
endFlag := c.String("e")
|
|
||||||
|
|
||||||
if tagFlag != "" && (rangeFlag != string(app.TagRange) || startFlag != "" || endFlag != "") {
|
if tagFlag != tagDefault &&
|
||||||
|
(settings.Range != string(app.TagRange) || settings.Start != "" || settings.End != "") {
|
||||||
return errCanNotCreateTagFlag
|
return errCanNotCreateTagFlag
|
||||||
}
|
}
|
||||||
|
|
||||||
if tagFlag != "" {
|
if tagFlag == tagDefault {
|
||||||
commits, err = getTagCommits(g, tagFlag)
|
r, rerr := logRange(g, settings.Range, settings.Start, settings.End)
|
||||||
} else {
|
|
||||||
r, rerr := logRange(g, rangeFlag, startFlag, endFlag)
|
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
return rerr
|
return rerr
|
||||||
}
|
}
|
||||||
|
|
||||||
commits, err = g.Log(r)
|
commits, err = g.Log(r)
|
||||||
|
} else {
|
||||||
|
commits, err = getTagCommits(g, tagFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -38,20 +38,18 @@ func CommitNotesFlags(settings *app.CommitNotesSettings) []cli.Flag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CommitNotesHandler(g app.GitSV) cli.ActionFunc {
|
func CommitNotesHandler(g app.GitSV, settings *app.CommitNotesSettings) cli.ActionFunc {
|
||||||
return func(c *cli.Context) error {
|
return func(c *cli.Context) error {
|
||||||
var date time.Time
|
var date time.Time
|
||||||
|
|
||||||
rangeFlag := g.Settings.CommitNotesSettings.Range
|
lr, err := logRange(g, settings.Range, settings.Start, settings.End)
|
||||||
|
|
||||||
lr, err := logRange(g, rangeFlag, g.Settings.CommitNotesSettings.Start, g.Settings.CommitNotesSettings.End)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
commits, err := g.Log(lr)
|
commits, err := g.Log(lr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting git log from range: %s: %w", rangeFlag, err)
|
return fmt.Errorf("error getting git log from range: %s: %w", settings.Range, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(commits) > 0 {
|
if len(commits) > 0 {
|
||||||
@ -63,13 +61,13 @@ func CommitNotesHandler(g app.GitSV) cli.ActionFunc {
|
|||||||
return fmt.Errorf("could not format commit notes: %w", err)
|
return fmt.Errorf("could not format commit notes: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.Settings.CommitNotesSettings.Out == "" {
|
if settings.End == "" {
|
||||||
os.Stdout.WriteString(fmt.Sprintf("%s\n", output))
|
os.Stdout.WriteString(fmt.Sprintf("%s\n", output))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
w, err := os.Create(g.Settings.CommitNotesSettings.Out)
|
w, err := os.Create(settings.End)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not write commit notes: %w", err)
|
return fmt.Errorf("could not write commit notes: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package commands
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Masterminds/semver/v3"
|
"github.com/Masterminds/semver/v3"
|
||||||
@ -18,6 +19,7 @@ func ReleaseNotesFlags(settings *app.ReleaseNotesSettings) []cli.Flag {
|
|||||||
Aliases: []string{"tag"},
|
Aliases: []string{"tag"},
|
||||||
Usage: "get release note from tag",
|
Usage: "get release note from tag",
|
||||||
Destination: &settings.Tag,
|
Destination: &settings.Tag,
|
||||||
|
Value: "next",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "o",
|
Name: "o",
|
||||||
@ -28,7 +30,7 @@ func ReleaseNotesFlags(settings *app.ReleaseNotesSettings) []cli.Flag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReleaseNotesHandler(g app.GitSV) cli.ActionFunc {
|
func ReleaseNotesHandler(g app.GitSV, settings *app.ReleaseNotesSettings) cli.ActionFunc {
|
||||||
return func(c *cli.Context) error {
|
return func(c *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
commits []sv.CommitLog
|
commits []sv.CommitLog
|
||||||
@ -38,11 +40,13 @@ func ReleaseNotesHandler(g app.GitSV) cli.ActionFunc {
|
|||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
if tag = g.Settings.ReleaseNotesSettings.Tag; tag != "" {
|
tagFlag := strings.TrimSpace(strings.ToLower(settings.Tag))
|
||||||
rnVersion, date, commits, err = getTagVersionInfo(g, tag)
|
|
||||||
} else {
|
if tagFlag == "next" {
|
||||||
// TODO: should generate release notes if version was not updated?
|
// TODO: should generate release notes if version was not updated?
|
||||||
rnVersion, _, date, commits, err = getNextVersionInfo(g, g.CommitProcessor)
|
rnVersion, _, date, commits, err = getNextVersionInfo(g, g.CommitProcessor)
|
||||||
|
} else {
|
||||||
|
rnVersion, date, commits, err = getTagVersionInfo(g, tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -56,13 +60,13 @@ func ReleaseNotesHandler(g app.GitSV) cli.ActionFunc {
|
|||||||
return fmt.Errorf("could not format release notes: %w", err)
|
return fmt.Errorf("could not format release notes: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.Settings.ReleaseNotesSettings.Out == "" {
|
if settings.Out == "" {
|
||||||
os.Stdout.WriteString(fmt.Sprintf("%s\n", output))
|
os.Stdout.WriteString(fmt.Sprintf("%s\n", output))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
w, err := os.Create(g.Settings.ReleaseNotesSettings.Out)
|
w, err := os.Create(settings.Out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not write release notes: %w", err)
|
return fmt.Errorf("could not write release notes: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ type Settings struct {
|
|||||||
ChangelogSettings ChangelogSettings
|
ChangelogSettings ChangelogSettings
|
||||||
ReleaseNotesSettings ReleaseNotesSettings
|
ReleaseNotesSettings ReleaseNotesSettings
|
||||||
CommitNotesSettings CommitNotesSettings
|
CommitNotesSettings CommitNotesSettings
|
||||||
|
CommitLogSettings CommitLogSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChangelogSettings struct {
|
type ChangelogSettings struct {
|
||||||
@ -40,6 +41,13 @@ type CommitNotesSettings struct {
|
|||||||
Out string
|
Out string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CommitLogSettings struct {
|
||||||
|
Tag string
|
||||||
|
Range string
|
||||||
|
Start string
|
||||||
|
End string
|
||||||
|
}
|
||||||
|
|
||||||
// Config cli yaml config.
|
// Config cli yaml config.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Version string `yaml:"version"`
|
Version string `yaml:"version"`
|
||||||
|
@ -86,8 +86,8 @@ func main() {
|
|||||||
Description: `The range filter is used based on git log filters, check https://git-scm.com/docs/git-log
|
Description: `The range filter is used based on git log filters, check https://git-scm.com/docs/git-log
|
||||||
for more info. When flag range is "tag" and start is empty, last tag created will be used instead.
|
for more info. When flag range is "tag" and start is empty, last tag created will be used instead.
|
||||||
When flag range is "date", if "end" is YYYY-MM-DD the range will be inclusive.`,
|
When flag range is "date", if "end" is YYYY-MM-DD the range will be inclusive.`,
|
||||||
Action: commands.CommitLogHandler(gsv),
|
Action: commands.CommitLogHandler(gsv, &gsv.Settings.CommitLogSettings),
|
||||||
Flags: commands.CommitLogFlags(),
|
Flags: commands.CommitLogFlags(&gsv.Settings.CommitLogSettings),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "commit-notes",
|
Name: "commit-notes",
|
||||||
@ -96,21 +96,21 @@ When flag range is "date", if "end" is YYYY-MM-DD the range will be inclusive.`,
|
|||||||
Description: `The range filter is used based on git log filters, check https://git-scm.com/docs/git-log
|
Description: `The range filter is used based on git log filters, check https://git-scm.com/docs/git-log
|
||||||
for more info. When flag range is "tag" and start is empty, last tag created will be used instead.
|
for more info. When flag range is "tag" and start is empty, last tag created will be used instead.
|
||||||
When flag range is "date", if "end" is YYYY-MM-DD the range will be inclusive.`,
|
When flag range is "date", if "end" is YYYY-MM-DD the range will be inclusive.`,
|
||||||
Action: commands.CommitNotesHandler(gsv),
|
Action: commands.CommitNotesHandler(gsv, &gsv.Settings.CommitNotesSettings),
|
||||||
Flags: commands.CommitNotesFlags(&gsv.Settings.CommitNotesSettings),
|
Flags: commands.CommitNotesFlags(&gsv.Settings.CommitNotesSettings),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "release-notes",
|
Name: "release-notes",
|
||||||
Aliases: []string{"rn"},
|
Aliases: []string{"rn"},
|
||||||
Usage: "generate release notes",
|
Usage: "generate release notes",
|
||||||
Action: commands.ReleaseNotesHandler(gsv),
|
Action: commands.ReleaseNotesHandler(gsv, &gsv.Settings.ReleaseNotesSettings),
|
||||||
Flags: commands.ReleaseNotesFlags(&gsv.Settings.ReleaseNotesSettings),
|
Flags: commands.ReleaseNotesFlags(&gsv.Settings.ReleaseNotesSettings),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "changelog",
|
Name: "changelog",
|
||||||
Aliases: []string{"cgl"},
|
Aliases: []string{"cgl"},
|
||||||
Usage: "generate changelog",
|
Usage: "generate changelog",
|
||||||
Action: commands.ChangelogHandler(gsv),
|
Action: commands.ChangelogHandler(gsv, &gsv.Settings.ChangelogSettings),
|
||||||
Flags: commands.ChangelogFlags(&gsv.Settings.ChangelogSettings),
|
Flags: commands.ChangelogFlags(&gsv.Settings.ChangelogSettings),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user