-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
84 lines (78 loc) · 2.19 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli"
)
var app = cli.NewApp()
func info() {
app.Name = "PAT"
app.Usage = "CLI Tools for pipelines."
app.Author = "Guestlogix"
app.Version = "0.0.2"
}
func commands() {
app.Commands = []cli.Command{
{
Name: "release",
Aliases: []string{"r"},
Usage: "Tools to aid in a release.",
Subcommands: []cli.Command{
{
Name: "notes",
Aliases: []string{"rn"},
Usage: "Generates the release notes between two tags",
ArgsUsage: "<path> <from> <to>",
Flags: []cli.Flag{
cli.StringFlag{Name: "output, o", Usage: "The filepath and file name to output the yml template to.", Value: "./issue.yml"},
cli.StringFlag{Name: "project, p", Usage: "The Jira project to create the issue on", Value: "RL"},
},
Action: func(c *cli.Context) {
repo := openRepo(c.Args().Get(0))
sinceTag := semverFromString(c.Args().Get(1))
untilTag := semverFromString(c.Args().Get(2))
sinceRef := tagRef(repo, sinceTag)
untilRef := tagRef(repo, untilTag)
commits := commitsBetweenRefs(repo, sinceRef, untilRef)
notes := formatReleaseNotes(commits, sinceRef, untilRef, untilTag, c.String("project"))
writeFile(notes, c.String("output"))
},
},
{
Name: "version",
Aliases: []string{"rv"},
Usage: "Obtains the last semver tag in the git history",
ArgsUsage: "<path>",
Action: func(c *cli.Context) {
repo := openRepo(c.Args().Get(0))
tag, _ := latestSemverTag(repo)
fmt.Println(tag.toString())
},
},
{
Name: "next",
Aliases: []string{"nv"},
Usage: "Returns the next version number based on commit names",
ArgsUsage: "<path>",
Action: func(c *cli.Context) {
repo := openRepo(c.Args().Get(0))
currentSemver, _ := latestSemverTag(repo)
sinceRef := tagRef(repo, currentSemver)
commits := commitsBetweenRefs(repo, sinceRef, nil)
newSemver := semverBump(commits, currentSemver)
fmt.Println(newSemver.toString())
},
},
},
},
}
}
func main() {
info()
commands()
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}