forked from go-kratos/kratos
/
change.go
45 lines (39 loc) · 990 Bytes
/
change.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
package change
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
// CmdChange is kratos change log tool
var CmdChange = &cobra.Command{
Use: "changelog",
Short: "Get a kratos change log",
Long: "Get a kratos release or commits info. Example: kratos changelog dev or kratos changelog {version}",
Run: run,
}
var (
token string
repoURL string
)
func init() {
if repoURL = os.Getenv("KRATOS_REPO"); repoURL == "" {
repoURL = "https://github.com/SeeMusic/kratos.git"
}
CmdChange.Flags().StringVarP(&repoURL, "repo-url", "r", repoURL, "github repo")
token = os.Getenv("GITHUB_TOKEN")
}
func run(cmd *cobra.Command, args []string) {
owner, repo := ParseGithubURL(repoURL)
api := GithubAPI{Owner: owner, Repo: repo, Token: token}
version := "latest"
if len(args) > 0 {
version = args[0]
}
if version == "dev" {
info := api.GetCommitsInfo()
fmt.Print(ParseCommitsInfo(info))
return
}
info := api.GetReleaseInfo(version)
fmt.Print(ParseReleaseInfo(info))
}