-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd): add kratos changelog command (#1140)
- Loading branch information
1 parent
c268f98
commit 7755bd3
Showing
3 changed files
with
251 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package change | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// CmdNew represents the new command. | ||
var CmdNew = &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 | ||
var repoURL string | ||
|
||
func init() { | ||
if repoURL = os.Getenv("KRATOS_REPO"); repoURL == "" { | ||
repoURL = "https://github.com/go-kratos/kratos.git" | ||
} | ||
CmdNew.Flags().StringVarP(&repoURL, "repo-url", "r", repoURL, "github repo") | ||
token = os.Getenv("GITHUB_TOKEN") | ||
} | ||
|
||
func run(cmd *cobra.Command, args []string) { | ||
owner, repo := base.ParseGithubUrl(repoURL) | ||
api := base.GithubApi{Owner: owner, Repo: repo, Token: token} | ||
version := "latest" | ||
if len(args) > 0 { | ||
version = args[0] | ||
} | ||
if version == "dev" { | ||
info := api.GetCommitsInfo() | ||
fmt.Print(base.ParseCommitsInfo(info)) | ||
} else { | ||
info := api.GetReleaseInfo(version) | ||
fmt.Print(base.ParseReleaseInfo(info)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters