Add flag to specify git tag #58

Merged
6543 merged 1 commits from 6543/gitea_changelog_tool:tag-flag into master 2022-03-13 02:33:03 +00:00
8 changed files with 23 additions and 7 deletions

@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package main

@ -11,6 +11,7 @@ import (
var (
MilestoneFlag string
TagFlag string
ConfigPathFlag string
TokenFlag string
DetailsFlag bool

@ -30,7 +30,7 @@ func runContributors(cmd *cli.Context) error {
return err
}
s, err := service.New(cfg.Service, cfg.Repo, cfg.BaseURL, MilestoneFlag, TokenFlag, IssuesFlag)
s, err := service.New(cfg.Service, cfg.Repo, cfg.BaseURL, MilestoneFlag, TagFlag, TokenFlag, IssuesFlag)
if err != nil {
return err
}

@ -37,7 +37,7 @@ func runGenerate(cmd *cli.Context) error {
processGroups(cfg.Groups)
s, err := service.New(cfg.Service, cfg.Repo, cfg.BaseURL, MilestoneFlag, TokenFlag, IssuesFlag)
s, err := service.New(cfg.Service, cfg.Repo, cfg.BaseURL, MilestoneFlag, TagFlag, TokenFlag, IssuesFlag)
if err != nil {
return err
}

@ -33,6 +33,12 @@ func main() {
Usage: "Targeted milestone",
Destination: &cmd.MilestoneFlag,
},
&cli.StringFlag{
Name: "tag",
Aliases: []string{"T"},
Usage: "Git tag for milestone url, if not set milestone is used",
Destination: &cmd.TagFlag,
},
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},

@ -14,6 +14,7 @@ import (
// Gitea defines a Gitea service
type Gitea struct {
Milestone string
GitTag string
Token string
BaseURL string
Owner string
@ -40,7 +41,7 @@ func (ge *Gitea) Generate() (string, []Entry, error) {
from = "issues"
}
tagURL := getGiteaTagURL(client, ge.BaseURL, ge.Owner, ge.Repo, ge.Milestone, from, milestone.ID)
tagURL := getGiteaTagURL(client, ge.BaseURL, ge.Owner, ge.Repo, ge.Milestone, ge.GitTag, from, milestone.ID)
perPage := ge.perPage(client)
for p := 1; ; p++ {
@ -81,11 +82,11 @@ func (ge *Gitea) Generate() (string, []Entry, error) {
return tagURL, entries, nil
}
func getGiteaTagURL(c *gitea.Client, baseURL, owner, repo, mileName, from string, mileID int64) string {
func getGiteaTagURL(c *gitea.Client, baseURL, owner, repo, mileName, gitTag, from string, mileID int64) string {
if err := c.CheckServerVersionConstraint(">=1.12"); err != nil {
return fmt.Sprintf("## [%s](%s/%s/%s/%s?q=&type=all&state=closed&milestone=%d) - %s", mileName, baseURL, owner, repo, from, mileID, time.Now().Format("2006-01-02"))
}
return fmt.Sprintf("## [%s](%s/%s/%s/releases/tag/%s) - %s", mileName, baseURL, owner, repo, mileName, time.Now().Format("2006-01-02"))
return fmt.Sprintf("## [%s](%s/%s/%s/releases/tag/%s) - %s", mileName, baseURL, owner, repo, gitTag, time.Now().Format("2006-01-02"))
}
func convertToEntry(issue gitea.Issue) Entry {

@ -15,6 +15,7 @@ import (
// GitHub defines a GitHub service
type GitHub struct {
Milestone string
GitTag string
Token string
Repo string
Issues bool
@ -22,7 +23,7 @@ type GitHub struct {
// Generate returns a GitHub changelog
func (gh *GitHub) Generate() (string, []Entry, error) {
tagURL := fmt.Sprintf("## [%s](https://github.com/%s/releases/tag/v%s) - %s", gh.Milestone, gh.Repo, gh.Milestone, time.Now().Format("2006-01-02"))
tagURL := fmt.Sprintf("## [%s](https://github.com/%s/releases/tag/%s) - %s", gh.Milestone, gh.Repo, gh.GitTag, time.Now().Format("2006-01-02"))
client := github.NewClient(nil)
ctx := context.Background()

@ -12,11 +12,16 @@ import (
const defaultGitea = "https://gitea.com"
// New returns a service from a string
func New(serviceType, repo, baseURL, milestone, token string, issues bool) (Service, error) {
func New(serviceType, repo, baseURL, milestone, tag, token string, issues bool) (Service, error) {
if len(tag) == 0 {
tag = milestone
noerw marked this conversation as resolved Outdated
Outdated
Review

could you add a comment explaining / warning that we default tag to milestone?

could you add a comment explaining / warning that we default tag to milestone?
Outdated
Review

It's already in the flag description, should I print to stdout?

@noerw

It's already in the flag description, should I print to stdout? @noerw
Outdated
Review

ah i see, never mind then.

ah i see, never mind then.
}
switch strings.ToLower(serviceType) {
case "github":
return &GitHub{
Milestone: milestone,
GitTag: tag,
Token: token,
Repo: repo,
Issues: issues,
@ -28,6 +33,7 @@ func New(serviceType, repo, baseURL, milestone, token string, issues bool) (Serv
}
return &Gitea{
Milestone: milestone,
GitTag: tag,
Token: token,
BaseURL: baseURL,
Owner: ownerRepo[0],