@@ -24,8 +24,10 @@ import (
2424 "path/filepath"
2525 "regexp"
2626 "sort"
27+ "strings"
2728 "text/tabwriter"
2829 "text/template"
30+ "unicode"
2931
3032 "github.com/pkg/errors"
3133 "github.com/sirupsen/logrus"
@@ -84,6 +86,7 @@ type release struct {
8486 Changes []projectChange
8587 Contributors []string
8688 Dependencies []dependency
89+ Tag string
8790 Version string
8891 Downloads []download
8992}
@@ -105,16 +108,29 @@ This tool should be ran from the root of the project repository for a new releas
105108 Usage : "show debug output" ,
106109 },
107110 cli.StringFlag {
108- Name : "template,t" ,
111+ Name : "tag,t" ,
112+ Usage : "tag name for the release, defaults to release file name" ,
113+ },
114+ cli.StringFlag {
115+ Name : "template" ,
109116 Usage : "template filepath to use in place of the default" ,
110117 Value : defaultTemplateFile ,
111118 },
119+ cli.BoolFlag {
120+ Name : "linkify,l" ,
121+ Usage : "add links to changelog" ,
122+ },
112123 }
113124 app .Action = func (context * cli.Context ) error {
114125 var (
115126 releasePath = context .Args ().First ()
116- tag = parseTag (releasePath )
127+ tag = context .String ("tag" )
128+ linkify = context .Bool ("linkify" )
117129 )
130+ if tag == "" {
131+ tag = parseTag (releasePath )
132+ }
133+ version := strings .TrimLeft (tag , "v" )
118134 if context .Bool ("debug" ) {
119135 logrus .SetLevel (logrus .DebugLevel )
120136 }
@@ -139,6 +155,11 @@ This tool should be ran from the root of the project repository for a new releas
139155 if err != nil {
140156 return err
141157 }
158+ if linkify {
159+ if err := linkifyChanges (changes , githubCommitLink (r .GithubRepo ), githubPRLink (r .GithubRepo )); err != nil {
160+ return err
161+ }
162+ }
142163 if err := addContributors (r .Previous , r .Commit , contributors ); err != nil {
143164 return err
144165 }
@@ -210,6 +231,16 @@ This tool should be ran from the root of the project repository for a new releas
210231 if err := addContributors (dep .Previous , dep .Commit , contributors ); err != nil {
211232 return errors .Wrapf (err , "failed to get authors for %s" , name )
212233 }
234+ if linkify {
235+ if ! strings .HasPrefix (dep .Name , "github.com/" ) {
236+ logrus .Debugf ("linkify only supported for Github, skipping %s" , dep .Name )
237+ } else {
238+ ghname := dep .Name [11 :]
239+ if err := linkifyChanges (changes , githubCommitLink (ghname ), githubPRLink (ghname )); err != nil {
240+ return err
241+ }
242+ }
243+ }
213244
214245 projectChanges = append (projectChanges , projectChange {
215246 Name : name ,
@@ -226,7 +257,11 @@ This tool should be ran from the root of the project repository for a new releas
226257 r .Contributors = orderContributors (contributors )
227258 r .Dependencies = updatedDeps
228259 r .Changes = projectChanges
229- r .Version = tag
260+ r .Tag = tag
261+ r .Version = version
262+
263+ // Remove trailing new lines
264+ r .Preface = strings .TrimRightFunc (r .Preface , unicode .IsSpace )
230265
231266 tmpl , err := getTemplate (context )
232267 if err != nil {
0 commit comments