diff --git a/changelog.example.go b/changelog.example.go index b9baf98..b370761 100644 --- a/changelog.example.go +++ b/changelog.example.go @@ -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 diff --git a/cmd/cmd.go b/cmd/cmd.go index 739e4b3..434cb41 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -11,6 +11,7 @@ import ( var ( MilestoneFlag string + TagFlag string ConfigPathFlag string TokenFlag string DetailsFlag bool diff --git a/cmd/contributors.go b/cmd/contributors.go index fa04b9f..d0b09f6 100644 --- a/cmd/contributors.go +++ b/cmd/contributors.go @@ -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 } diff --git a/cmd/generate.go b/cmd/generate.go index 71c2424..94d264f 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -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 } diff --git a/main.go b/main.go index 1faf199..dab4a04 100644 --- a/main.go +++ b/main.go @@ -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"}, diff --git a/service/gitea.go b/service/gitea.go index c7c03fd..874f858 100644 --- a/service/gitea.go +++ b/service/gitea.go @@ -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 { diff --git a/service/github.go b/service/github.go index aef7737..38654ac 100644 --- a/service/github.go +++ b/service/github.go @@ -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() diff --git a/service/service.go b/service/service.go index 0fc43f0..de7e76a 100644 --- a/service/service.go +++ b/service/service.go @@ -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 + } + 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],