github.com/mloves0824/enron/cmd/enron@v0.0.0-20230830012320-113bbf6be3c8/internal/change/change.go (about) 1 package change 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/spf13/cobra" 8 ) 9 10 // CmdChange is enron change log tool 11 var CmdChange = &cobra.Command{ 12 Use: "changelog", 13 Short: "Get a enron change log", 14 Long: "Get a enron release or commits info. Example: enron changelog dev or enron changelog {version}", 15 Run: run, 16 } 17 18 var ( 19 token string 20 repoURL string 21 ) 22 23 func init() { 24 if repoURL = os.Getenv("ENRON_REPO"); repoURL == "" { 25 repoURL = "https://github.com/mloves0824/enron.git" 26 } 27 CmdChange.Flags().StringVarP(&repoURL, "repo-url", "r", repoURL, "github repo") 28 token = os.Getenv("GITHUB_TOKEN") 29 } 30 31 func run(_ *cobra.Command, args []string) { 32 owner, repo := ParseGithubURL(repoURL) 33 api := GithubAPI{Owner: owner, Repo: repo, Token: token} 34 version := "latest" 35 if len(args) > 0 { 36 version = args[0] 37 } 38 if version == "dev" { 39 info := api.GetCommitsInfo() 40 fmt.Print(ParseCommitsInfo(info)) 41 return 42 } 43 info := api.GetReleaseInfo(version) 44 fmt.Print(ParseReleaseInfo(info)) 45 }