mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-22 18:30:40 +00:00
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/thegeeklab/git-sv/v2/app"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func CommitNotesFlags() []cli.Flag {
|
|
return []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "r", Aliases: []string{"range"},
|
|
Usage: "type of range of commits, use: tag, date or hash",
|
|
Required: true,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "s",
|
|
Aliases: []string{"start"},
|
|
Usage: "start range of git log revision range, if date, the value is used on since flag instead",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "e",
|
|
Aliases: []string{"end"},
|
|
Usage: "end range of git log revision range, if date, the value is used on until flag instead",
|
|
},
|
|
}
|
|
}
|
|
|
|
func CommitNotesHandler(g app.GitSV) cli.ActionFunc {
|
|
return func(c *cli.Context) error {
|
|
var date time.Time
|
|
|
|
rangeFlag := c.String("r")
|
|
|
|
lr, err := logRange(g, rangeFlag, c.String("s"), c.String("e"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
commits, err := g.Log(lr)
|
|
if err != nil {
|
|
return fmt.Errorf("error getting git log from range: %s, message: %w", rangeFlag, err)
|
|
}
|
|
|
|
if len(commits) > 0 {
|
|
date, _ = time.Parse("2006-01-02", commits[0].Date)
|
|
}
|
|
|
|
output, err := g.OutputFormatter.FormatReleaseNote(g.ReleasenotesProcessor.Create(nil, "", date, commits))
|
|
if err != nil {
|
|
return fmt.Errorf("could not format release notes, message: %w", err)
|
|
}
|
|
|
|
fmt.Println(output)
|
|
|
|
return nil
|
|
}
|
|
}
|