diff --git a/changelog.go b/changelog.go deleted file mode 100644 index 1853dd8..0000000 --- a/changelog.go +++ /dev/null @@ -1,65 +0,0 @@ -package tagpr - -import ( - "bufio" - "bytes" - "fmt" - "regexp" - "strings" - "time" -) - -var ( - versionLinkReg = regexp.MustCompile(`\n\*\*Full Changelog\*\*: (https://.*)$`) - semverFromLinkReg = regexp.MustCompile(`.*[./](v?[0-9]+\.[0-9]+\.[0-9]+)`) - newContribReg = regexp.MustCompile(`(?ms)## New Contributors.*\z`) - genCommentReg = regexp.MustCompile(``) -) - -func convertKeepAChangelogFormat(md string, d time.Time) string { - md = strings.TrimSpace(genCommentReg.ReplaceAllString(md, "")) - - var link string - md = versionLinkReg.ReplaceAllStringFunc(md, func(match string) string { - m := versionLinkReg.FindStringSubmatch(match) - link = m[1] - return "" - }) - var semvStr string - if m := semverFromLinkReg.FindStringSubmatch(link); len(m) > 1 { - semvStr = m[1] - } - - heading := fmt.Sprintf("## [%s](%s) - %s", semvStr, link, d.UTC().Format("2006-01-02")) - md = strings.Replace(md, "## What's Changed", heading, 1) - md = strings.ReplaceAll(md, "\n* ", "\n- ") - md = newContribReg.ReplaceAllString(md, "") - - return strings.TrimSpace(md) + "\n" -} - -var changelogReg = regexp.MustCompile(`(?i)^# Change\s?log`) - -func insertNewChangelog(orig string, section string) string { - orig = strings.TrimSpace(orig) + "\n" - section = strings.TrimSpace(section) + "\n" - - var bf bytes.Buffer - lineSnr := bufio.NewScanner(strings.NewReader(orig)) - inserted := false - for lineSnr.Scan() { - line := lineSnr.Text() - if !inserted && strings.HasPrefix(line, "## ") { - bf.WriteString(section) - bf.WriteString("\n") - inserted = true - } - bf.WriteString(line) - bf.WriteString("\n") - } - if !inserted { - bf.WriteString("\n") - bf.WriteString(section) - } - return bf.String() -} diff --git a/changelog_test.go b/changelog_test.go deleted file mode 100644 index 4eff77c..0000000 --- a/changelog_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package tagpr - -import ( - "testing" - "time" -) - -func TestConvertKeepAChangelogFormat(t *testing.T) { - - input := ` - -## What's Changed -* add github.go for github client by @Songmu in https://github.com/Songmu/tagpr/pull/1 -* create rc pull request when the default branch proceeded by @Songmu in https://github.com/Songmu/tagpr/pull/2 -* dogfooding by @Songmu in https://github.com/Songmu/tagpr/pull/3 -* set label to the pull request by @Songmu in https://github.com/Songmu/tagpr/pull/5 -* change rc branch naming convention by @Songmu in https://github.com/Songmu/tagpr/pull/6 -* adjust auto commit message by @Songmu in https://github.com/Songmu/tagpr/pull/8 -* apply the commits added on the RC branch with cherry-pick by @Songmu in https://github.com/Songmu/tagpr/pull/9 -* unshallow if a shallow repository by @Songmu in https://github.com/Songmu/tagpr/pull/10 -* fix git log by @Songmu in https://github.com/Songmu/tagpr/pull/11 -* parse git URL more precise by @Songmu in https://github.com/Songmu/tagpr/pull/12 -* fix parseGitURL by @Songmu in https://github.com/Songmu/tagpr/pull/13 -* refactor git.go by @Songmu in https://github.com/Songmu/tagpr/pull/14 -* set user.email and user.name only if they aren't set by @Songmu in https://github.com/Songmu/tagpr/pull/15 -* fix api base handling by @Songmu in https://github.com/Songmu/tagpr/pull/16 -* take care of v-prefix or not in tags by @Songmu in https://github.com/Songmu/tagpr/pull/17 -* Detect version file and update by @Songmu in https://github.com/Songmu/tagpr/pull/18 -* tagging semver to merged tagpr by @Songmu in https://github.com/Songmu/tagpr/pull/19 - -## New Contributors -* @Songmu made their first contribution in https://github.com/Songmu/tagpr/pull/1 - -**Full Changelog**: https://github.com/Songmu/tagpr/commits/v0.0.1 -` - - expect := `## [v0.0.1](https://github.com/Songmu/tagpr/commits/v0.0.1) - 2022-08-16 -- add github.go for github client by @Songmu in https://github.com/Songmu/tagpr/pull/1 -- create rc pull request when the default branch proceeded by @Songmu in https://github.com/Songmu/tagpr/pull/2 -- dogfooding by @Songmu in https://github.com/Songmu/tagpr/pull/3 -- set label to the pull request by @Songmu in https://github.com/Songmu/tagpr/pull/5 -- change rc branch naming convention by @Songmu in https://github.com/Songmu/tagpr/pull/6 -- adjust auto commit message by @Songmu in https://github.com/Songmu/tagpr/pull/8 -- apply the commits added on the RC branch with cherry-pick by @Songmu in https://github.com/Songmu/tagpr/pull/9 -- unshallow if a shallow repository by @Songmu in https://github.com/Songmu/tagpr/pull/10 -- fix git log by @Songmu in https://github.com/Songmu/tagpr/pull/11 -- parse git URL more precise by @Songmu in https://github.com/Songmu/tagpr/pull/12 -- fix parseGitURL by @Songmu in https://github.com/Songmu/tagpr/pull/13 -- refactor git.go by @Songmu in https://github.com/Songmu/tagpr/pull/14 -- set user.email and user.name only if they aren't set by @Songmu in https://github.com/Songmu/tagpr/pull/15 -- fix api base handling by @Songmu in https://github.com/Songmu/tagpr/pull/16 -- take care of v-prefix or not in tags by @Songmu in https://github.com/Songmu/tagpr/pull/17 -- Detect version file and update by @Songmu in https://github.com/Songmu/tagpr/pull/18 -- tagging semver to merged tagpr by @Songmu in https://github.com/Songmu/tagpr/pull/19 -` - - got := convertKeepAChangelogFormat(input, time.Date(2022, time.August, 16, 18, 10, 10, 0, time.UTC)) - if got != expect { - t.Errorf("error:\n %s", got) - } -} diff --git a/go.mod b/go.mod index 20ffe32..2d485c1 100644 --- a/go.mod +++ b/go.mod @@ -4,11 +4,12 @@ go 1.19 require ( github.com/Masterminds/semver/v3 v3.1.1 + github.com/Songmu/gh2changelog v0.0.1 github.com/Songmu/gitconfig v0.1.1 - github.com/Songmu/gitsemvers v0.0.2 + github.com/Songmu/gitsemvers v0.0.3 github.com/google/go-github/v45 v45.2.0 github.com/saracen/walker v0.1.3 - golang.org/x/oauth2 v0.0.0-20220808172628-8227340efae7 + golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094 ) require ( diff --git a/go.sum b/go.sum index bf804ae..d468986 100644 --- a/go.sum +++ b/go.sum @@ -1,16 +1,13 @@ github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/Songmu/gitconfig v0.1.0 h1:JsaQ6rh3Lnig0Xvo4t4nj7Xu6pXrMfyCOPJ6iRriuKY= -github.com/Songmu/gitconfig v0.1.0/go.mod h1:kVksEBYKkMQuZ5BumlnW7KBDBreiySMbf50dseHYOpQ= +github.com/Songmu/gh2changelog v0.0.1 h1:vz3Jj2v7w5u4zz++eXanBaJwomDFvmpKlegzOERHv9I= +github.com/Songmu/gh2changelog v0.0.1/go.mod h1:Due79qGb+NqStQMAuALEQf1yn/PGvbk2lJtTHnSdft8= github.com/Songmu/gitconfig v0.1.1 h1:f7mYZFsaQxA2d2cmpTMh0cnaKcMyipCHLz9VFGpOp7o= github.com/Songmu/gitconfig v0.1.1/go.mod h1:0tMxtjBDE48LN61CQuzpnC72V8ICWtk+6938EyIpGGA= github.com/Songmu/gitmock v0.0.2 h1:KF5GTll60LxGskZbt58QDd29y/GYLgdxqvkvnSU6RlY= -github.com/Songmu/gitsemvers v0.0.2 h1:Qr76LMQCA/in0H8ufK69/cjd5nUkTZeY9IUiP1ZO/1s= -github.com/Songmu/gitsemvers v0.0.2/go.mod h1:WdKXiC8zjNK1N7CoZ9cM9vrw/Bg6/W4AwGrfTkkUPdM= +github.com/Songmu/gitsemvers v0.0.3 h1:pyNgp4+G0Y65zP+4ANybm/fFUyThaMl3SrUzmh50ogk= +github.com/Songmu/gitsemvers v0.0.3/go.mod h1:WdKXiC8zjNK1N7CoZ9cM9vrw/Bg6/W4AwGrfTkkUPdM= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= -github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= @@ -19,9 +16,8 @@ github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8c github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= -github.com/goccy/go-yaml v1.8.0 h1:WCe9sBiI0oZb6EC6f3kq3dv0+aEiNdstT7b4xxq4MJQ= -github.com/goccy/go-yaml v1.8.0/go.mod h1:wS4gNoLalDSJxo/SpngzPQ2BN4uuZVLCmbM4S3vd4+Y= github.com/goccy/go-yaml v1.9.5 h1:Eh/+3uk9kLxG4koCX6lRMAPS1OaMSAi+FJcya0INdB0= github.com/goccy/go-yaml v1.9.5/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -39,17 +35,10 @@ github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LF github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw= -github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= -github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= @@ -69,31 +58,22 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e h1:TsQ7F31D3bUCLeqPT0u+yjp1guoArKaNKmCr22PYgTQ= golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/oauth2 v0.0.0-20220808172628-8227340efae7 h1:dtndE8FcEta75/4kHF3AbpuWzV6f1LjnLrM4pe2SZrw= -golang.org/x/oauth2 v0.0.0-20220808172628-8227340efae7/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= +golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094 h1:2o1E+E8TpNLklK9nHiPiK1uzIYrIHt+cQx3ynCwq9V8= +golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f h1:Ax0t5p6N38Ga0dThY21weqDEyz2oklo4IvDkpigvkD8= golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200722175500-76b94024e4b6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 h1:Sx/u41w+OwrInGdEckYmEuU5gHoGSL4QbDz3S9s6j4U= golang.org/x/sys v0.0.0-20220818161305-2296e01440c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f h1:uF6paiQQebLeSXkrTqHqz0MXhXXS1KgF41eUdBNvxK0= @@ -105,7 +85,4 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= -gopkg.in/go-playground/validator.v9 v9.30.0 h1:Wk0Z37oBmKj9/n+tPyBHZmeL19LaCoK3Qq48VwYENss= -gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/tagpr.go b/tagpr.go index 340140b..49e1277 100644 --- a/tagpr.go +++ b/tagpr.go @@ -11,8 +11,8 @@ import ( "regexp" "strings" "text/template" - "time" + "github.com/Songmu/gh2changelog" "github.com/Songmu/gitsemvers" "github.com/google/go-github/v45/github" ) @@ -288,56 +288,33 @@ func (tp *tagpr) Run(ctx context.Context) error { nextVer = nVer } } - previousTag := &latestSemverTag - if *previousTag == "" { - previousTag = nil - } - releases, _, err := tp.gh.Repositories.GenerateReleaseNotes( - ctx, tp.owner, tp.repo, &github.GenerateNotesOptions{ - TagName: nextVer.Tag(), - PreviousTagName: previousTag, - TargetCommitish: &releaseBranch, - }) + + gch, err := gh2changelog.New(ctx, + gh2changelog.GitPath(tp.gitPath), + gh2changelog.SetOutputs(tp.c.outStream, tp.c.errStream), + gh2changelog.GitHubClient(tp.gh), + ) if err != nil { return err } - changelog := convertKeepAChangelogFormat(releases.Body, time.Now()) changelogMd := "CHANGELOG.md" - - var content string - if exists(changelogMd) { - byt, err := os.ReadFile(changelogMd) + changelog, orig, err := gch.Draft(ctx, nextVer.Tag()) + if err != nil { + return err + } + if !exists(changelogMd) { + logs, _, err := gch.Changelogs(ctx, 20) if err != nil { return err } - content = strings.TrimSpace(string(byt)) + "\n" + changelog = strings.Join( + append([]string{changelog}, logs...), "\n") } - - // If the changelog is not in "keep a changelog" format, or if the file does not exist, re-create everything. Is it rough...? - if !changelogReg.MatchString(content) { - // We are concerned that depending on the release history, API requests may become more frequent. - vers := (&gitsemvers.Semvers{GitPath: tp.gitPath}).VersionStrings() - logs := []string{"# Changelog\n"} - for i, ver := range vers { - if i > 10 { - break - } - date, _, _ := tp.c.GitE("log", "-1", "--format=%ai", "--date=iso", ver) - d, _ := time.Parse("2006-01-02 15:04:05 -0700", date) - releases, _, _ := tp.gh.Repositories.GenerateReleaseNotes( - ctx, tp.owner, tp.repo, &github.GenerateNotesOptions{ - TagName: ver, - }) - logs = append(logs, strings.TrimSpace(convertKeepAChangelogFormat(releases.Body, d))+"\n") - } - content = strings.Join(logs, "\n") - } - - content = insertNewChangelog(content, changelog) - if err := os.WriteFile(changelogMd, []byte(content), 0644); err != nil { + if _, err := gch.Update(changelog, 0); err != nil { return err } + tp.c.GitE("add", changelogMd) tp.c.GitE("commit", "-m", autoChangelogMessage) @@ -358,7 +335,7 @@ func (tp *tagpr) Run(ctx context.Context) error { prText, err := pt.Render(&tmplArg{ NextVersion: nextVer.Tag(), Branch: rcBranch, - Changelog: releases.Body, + Changelog: orig, }) if err != nil { return err