From 09c69c76713e0bbb52ccb9cdd95b26dca4878757 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 7 Aug 2020 13:37:14 +0200 Subject: [PATCH 01/42] Update google/go-github to v32.1.0 --- go.mod | 4 ++-- go.sum | 16 ++++++++++++++-- service/github.go | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 83881e0..a0baf6a 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.13 require ( code.gitea.io/sdk/gitea v0.12.0 github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect - github.com/google/go-github v17.0.0+incompatible - github.com/google/go-querystring v1.0.0 // indirect + github.com/google/go-github/v32 v32.1.0 github.com/urfave/cli/v2 v2.1.1 + golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect gopkg.in/yaml.v2 v2.2.7 ) diff --git a/go.sum b/go.sum index 6831cf7..29f7496 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,9 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= -github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II= +github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E= @@ -23,6 +24,17 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k= github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig= +golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/service/github.go b/service/github.go index 084e0e6..aef7737 100644 --- a/service/github.go +++ b/service/github.go @@ -9,7 +9,7 @@ import ( "fmt" "time" - "github.com/google/go-github/github" + "github.com/google/go-github/v32/github" ) // GitHub defines a GitHub service -- 2.43.5 From cc58d758be7557fbc38d49e2a154bbcd35b77614 Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Fri, 7 Aug 2020 11:55:11 +0000 Subject: [PATCH 02/42] Update google/go-github to v32.1.0 (#45) Update google/go-github to v32.1.0 Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/changelog/pulls/45 Reviewed-by: Lunny Xiao Reviewed-by: John Olheiser --- go.mod | 4 ++-- go.sum | 16 ++++++++++++++-- service/github.go | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 83881e0..a0baf6a 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.13 require ( code.gitea.io/sdk/gitea v0.12.0 github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect - github.com/google/go-github v17.0.0+incompatible - github.com/google/go-querystring v1.0.0 // indirect + github.com/google/go-github/v32 v32.1.0 github.com/urfave/cli/v2 v2.1.1 + golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect gopkg.in/yaml.v2 v2.2.7 ) diff --git a/go.sum b/go.sum index 6831cf7..29f7496 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,9 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= -github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II= +github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E= @@ -23,6 +24,17 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k= github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig= +golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/service/github.go b/service/github.go index 084e0e6..aef7737 100644 --- a/service/github.go +++ b/service/github.go @@ -9,7 +9,7 @@ import ( "fmt" "time" - "github.com/google/go-github/github" + "github.com/google/go-github/v32/github" ) // GitHub defines a GitHub service -- 2.43.5 From b3574b331bc63ba99408c41a6df4734b5392d8be Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Fri, 7 Aug 2020 13:41:58 +0000 Subject: [PATCH 03/42] Gitea Service: Use single release page (>= 1.12) (#47) code format: "...happy path at the end..." try to fix lint gitea >= 1.12 has single release page Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/changelog/pulls/47 Reviewed-by: jaqra Reviewed-by: John Olheiser --- service/gitea.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/service/gitea.go b/service/gitea.go index 72e2e58..ba2035e 100644 --- a/service/gitea.go +++ b/service/gitea.go @@ -37,7 +37,7 @@ func (ge *Gitea) Generate() (string, []Entry, error) { from = "issues" } - tagURL := fmt.Sprintf("## [%s](%s/%s/%s/%s?q=&type=all&state=closed&milestone=%d) - %s", ge.Milestone, ge.BaseURL, ge.Owner, ge.Repo, from, milestoneID, time.Now().Format("2006-01-02")) + tagURL := getGiteaTagURL(client, ge.BaseURL, ge.Owner, ge.Repo, ge.Milestone, from, milestoneID) p := 1 // https://github.com/go-gitea/gitea/blob/d92781bf941972761177ac9e07441f8893758fd3/models/repo.go#L63 @@ -84,6 +84,13 @@ 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 { + 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")) +} + func convertToEntry(issue gitea.Issue) Entry { entry := Entry{ Index: issue.Index, -- 2.43.5 From ec4e62ff9d90a79411417a837af61140e9d5f993 Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Fri, 7 Aug 2020 13:48:37 +0000 Subject: [PATCH 04/42] Update Vendors (#46) Update Vendors: * code.gitea.io/sdk/gitea v0.12.1 * github.com/urfave/cli/v2 v2.2.0 * gopkg.in/yaml.v2 v2.3.0 Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/changelog/pulls/46 Reviewed-by: Lunny Xiao Reviewed-by: John Olheiser --- go.mod | 7 ++++--- go.sum | 14 ++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index a0baf6a..54a9597 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,11 @@ module code.gitea.io/changelog go 1.13 require ( - code.gitea.io/sdk/gitea v0.12.0 + code.gitea.io/sdk/gitea v0.12.1 github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/google/go-github/v32 v32.1.0 - github.com/urfave/cli/v2 v2.1.1 + github.com/hashicorp/go-version v1.2.1 // indirect + github.com/urfave/cli/v2 v2.2.0 golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect - gopkg.in/yaml.v2 v2.2.7 + gopkg.in/yaml.v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 29f7496..8ae3565 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -code.gitea.io/sdk/gitea v0.12.0 h1:hvDCz4wtFvo7rf5Ebj8tGd4aJ4wLPKX3BKFX9Dk1Pgs= -code.gitea.io/sdk/gitea v0.12.0/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY= +code.gitea.io/sdk/gitea v0.12.1 h1:bMgjEqPnNX/i6TpVwXwpjJtFOnUSuC9P6yy/jjy8sjY= +code.gitea.io/sdk/gitea v0.12.1/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= @@ -13,6 +13,8 @@ github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASu github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E= github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= +github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= @@ -22,8 +24,8 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k= -github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= +github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig= @@ -38,5 +40,5 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= -gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -- 2.43.5 From c48910002de82ac9ea5cff3572e3898b9260885f Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Fri, 7 Aug 2020 13:57:07 +0000 Subject: [PATCH 05/42] Changelog v0.2.0 (#48) use new release page links Changelog v0.2.0 Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/changelog/pulls/48 Reviewed-by: jaqra Reviewed-by: John Olheiser --- CHANGELOG.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dab398..86e0557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,24 @@ # Changelog -## [0.1.1](https://gitea.com/gitea/changelog/pulls?q=&type=all&state=closed&milestone=1236) - 2020-02-02 +## [v0.2.0](https://gitea.com/gitea/changelog/releases/tag/v0.2.0) - 2020-08-07 + +* FEATURES + * Add generate from issues argument (#44) +* BUGFIXES + * Fix bug only list first page when get prs from gitea (#41) + * Add newline after title (#39) +* ENHANCEMENTS + * Gitea Service: Use single release page (>= 1.12) (#47) + * Set default service as github when service type empty (#40) + +## [v0.1.1](https://gitea.com/gitea/changelog/releases/tag/v0.1.1) - 2020-02-02 + * BUGFIXES * Use .changelog.yml config if in working dir (#37) * Fix Gitea get closed milestone too (#35) -## [0.1.0](https://gitea.com/gitea/changelog/pulls?q=&type=all&state=closed&milestone=1231) - 2020-01-25 +## [v0.1.0](https://gitea.com/gitea/changelog/releases/tag/v0.1.0) - 2020-01-25 + * FEATURES * Add init command (#33) * Add subcommand to display contributors of milestone (#10) -- 2.43.5 From 18ff9e6a0d62b189fc209a18c3965a412cbc34e7 Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Tue, 22 Sep 2020 21:38:11 +0000 Subject: [PATCH 06/42] Update Gitea SDK to v0.13.0 (#49) adapt new functions update sdk to v0.13.0 Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/changelog/pulls/49 Reviewed-by: Lunny Xiao Reviewed-by: jaqra --- go.mod | 2 +- go.sum | 4 +-- service/gitea.go | 64 +++++++++++++++++++++++------------------------- 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/go.mod b/go.mod index 54a9597..4d04054 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module code.gitea.io/changelog go 1.13 require ( - code.gitea.io/sdk/gitea v0.12.1 + code.gitea.io/sdk/gitea v0.13.0 github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/google/go-github/v32 v32.1.0 github.com/hashicorp/go-version v1.2.1 // indirect diff --git a/go.sum b/go.sum index 8ae3565..42ff048 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -code.gitea.io/sdk/gitea v0.12.1 h1:bMgjEqPnNX/i6TpVwXwpjJtFOnUSuC9P6yy/jjy8sjY= -code.gitea.io/sdk/gitea v0.12.1/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY= +code.gitea.io/sdk/gitea v0.13.0 h1:iHognp8ZMhMFLooUUNZFpm8IHaC9qoHJDvAE5vTm5aw= +code.gitea.io/sdk/gitea v0.13.0/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= diff --git a/service/gitea.go b/service/gitea.go index ba2035e..c7c03fd 100644 --- a/service/gitea.go +++ b/service/gitea.go @@ -23,11 +23,14 @@ type Gitea struct { // Generate returns a Gitea changelog func (ge *Gitea) Generate() (string, []Entry, error) { - client := gitea.NewClient(ge.BaseURL, ge.Token) + client, err := gitea.NewClient(ge.BaseURL, gitea.SetToken(ge.Token)) + if err != nil { + return "", nil, err + } entries := make([]Entry, 0) - milestoneID, err := ge.milestoneID(client) + milestone, _, err := client.GetMilestoneByName(ge.Owner, ge.Repo, ge.Milestone) if err != nil { return "", nil, err } @@ -37,14 +40,10 @@ func (ge *Gitea) Generate() (string, []Entry, error) { from = "issues" } - tagURL := getGiteaTagURL(client, ge.BaseURL, ge.Owner, ge.Repo, ge.Milestone, from, milestoneID) + tagURL := getGiteaTagURL(client, ge.BaseURL, ge.Owner, ge.Repo, ge.Milestone, from, milestone.ID) - p := 1 - // https://github.com/go-gitea/gitea/blob/d92781bf941972761177ac9e07441f8893758fd3/models/repo.go#L63 - // https://github.com/go-gitea/gitea/blob/e3c3b33ea7a5a223e22688c3f0eb2d3dab9f991c/models/pull_list.go#L104 - // FIXME Gitea has this hard-coded at 40 - perPage := 40 - for { + perPage := ge.perPage(client) + for p := 1; ; p++ { options := gitea.ListIssueOption{ ListOptions: gitea.ListOptions{ Page: p, @@ -58,7 +57,7 @@ func (ge *Gitea) Generate() (string, []Entry, error) { options.Type = gitea.IssueTypeIssue } - issues, err := client.ListRepoIssues(ge.Owner, ge.Repo, options) + issues, _, err := client.ListRepoIssues(ge.Owner, ge.Repo, options) if err != nil { return "", nil, err } @@ -77,8 +76,6 @@ func (ge *Gitea) Generate() (string, []Entry, error) { if len(issues) != perPage { break } - - p++ } return tagURL, entries, nil @@ -111,30 +108,31 @@ func convertToEntry(issue gitea.Issue) Entry { // Contributors returns a list of contributors from Gitea func (ge *Gitea) Contributors() (ContributorList, error) { - client := gitea.NewClient(ge.BaseURL, ge.Token) - - contributorsMap := make(map[string]bool) - - milestoneID, err := ge.milestoneID(client) + client, err := gitea.NewClient(ge.BaseURL, gitea.SetToken(ge.Token)) if err != nil { return nil, err } - p := 1 - perPage := 100 - for { - results, err := client.ListRepoPullRequests(ge.Owner, ge.Repo, gitea.ListPullRequestsOptions{ + contributorsMap := make(map[string]bool) + + milestone, _, err := client.GetMilestoneByName(ge.Owner, ge.Repo, ge.Milestone) + if err != nil { + return nil, err + } + + perPage := ge.perPage(client) + for p := 1; ; p++ { + results, _, err := client.ListRepoPullRequests(ge.Owner, ge.Repo, gitea.ListPullRequestsOptions{ ListOptions: gitea.ListOptions{ Page: p, PageSize: perPage, }, State: "closed", - Milestone: milestoneID, + Milestone: milestone.ID, }) if err != nil { return nil, err } - p++ for _, pr := range results { if pr != nil && pr.HasMerged { @@ -158,17 +156,15 @@ func (ge *Gitea) Contributors() (ContributorList, error) { return contributors, nil } -func (ge *Gitea) milestoneID(client *gitea.Client) (int64, error) { - milestones, err := client.ListRepoMilestones(ge.Owner, ge.Repo, gitea.ListMilestoneOption{State: gitea.StateAll}) - if err != nil { - return 0, err - } - - for _, ms := range milestones { - if ms.Title == ge.Milestone { - return ms.ID, nil +func (ge *Gitea) perPage(client *gitea.Client) int { + // set low value so it will work in most cases + perPage := 10 + if client.CheckServerVersionConstraint(">=1.13.0") == nil { + conf, _, err := client.GetGlobalAPISettings() + if err != nil { + return perPage } + return conf.MaxResponseItems } - - return 0, fmt.Errorf("no milestone found for %s", ge.Milestone) + return perPage } -- 2.43.5 From c38cabc3dcca3202d025e8546b8214d541d820b8 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 17 May 2021 18:39:53 +0800 Subject: [PATCH 07/42] Upgrade gitea sdk to v0.14.0 (#53) As title. Reviewed-on: https://gitea.com/gitea/changelog/pulls/53 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton Co-authored-by: Lunny Xiao Co-committed-by: Lunny Xiao --- cmd/contributors.go | 1 - cmd/generate.go | 2 +- go.mod | 3 +-- go.sum | 7 ++----- main.go | 2 +- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/cmd/contributors.go b/cmd/contributors.go index c84456f..fa04b9f 100644 --- a/cmd/contributors.go +++ b/cmd/contributors.go @@ -21,7 +21,6 @@ var Contributors = &cli.Command{ } func runContributors(cmd *cli.Context) error { - if ConfigPathFlag == "" { ConfigPathFlag = getDefaultConfigFile() } diff --git a/cmd/generate.go b/cmd/generate.go index 0f176b2..71c2424 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -17,7 +17,7 @@ import ( var ( Generate = &cli.Command{ Name: "generate", - Usage: "Generates a changelog", + Usage: "Generates a changelog for a special milestone", Action: runGenerate, } labels = make(map[string]string) diff --git a/go.mod b/go.mod index 4d04054..a85f863 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,9 @@ module code.gitea.io/changelog go 1.13 require ( - code.gitea.io/sdk/gitea v0.13.0 + code.gitea.io/sdk/gitea v0.14.0 github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/google/go-github/v32 v32.1.0 - github.com/hashicorp/go-version v1.2.1 // indirect github.com/urfave/cli/v2 v2.2.0 golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect gopkg.in/yaml.v2 v2.3.0 diff --git a/go.sum b/go.sum index 42ff048..83e07fd 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -code.gitea.io/sdk/gitea v0.13.0 h1:iHognp8ZMhMFLooUUNZFpm8IHaC9qoHJDvAE5vTm5aw= -code.gitea.io/sdk/gitea v0.13.0/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY= +code.gitea.io/sdk/gitea v0.14.0 h1:m4J352I3p9+bmJUfS+g0odeQzBY/5OXP91Gv6D4fnJ0= +code.gitea.io/sdk/gitea v0.14.0/go.mod h1:89WiyOX1KEcvjP66sRHdu0RafojGo60bT9UqW17VbWs= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= @@ -11,8 +11,6 @@ github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoP github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= -github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E= -github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -26,7 +24,6 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/main.go b/main.go index d7829e2..1faf199 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,7 @@ var ( func main() { app := &cli.App{ Name: "changelog", - Usage: "Changelog generator for Gitea", + Usage: "Changelog tools for Gitea", Version: Version, Flags: []cli.Flag{ &cli.StringFlag{ -- 2.43.5 From ea56b8af5a81fc1cffb0fc25ce09b978a92a9526 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 9 Oct 2021 02:57:05 +0800 Subject: [PATCH 08/42] build with go1.17 & use supported s3 plugin (#56) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this will build with arm64 for darwin because it has been added to xgo plugin Co-authored-by: Matti R Reviewed-on: https://gitea.com/gitea/changelog/pulls/56 Reviewed-by: Andrew Thornton Reviewed-by: Alexey 〒erentyev Co-authored-by: techknowlogick Co-committed-by: techknowlogick --- .drone.yml | 12 ++++++------ Makefile | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.drone.yml b/.drone.yml index bb03f48..bb245d8 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,7 +13,7 @@ trigger: steps: - name: build pull: always - image: golang:1.13 + image: golang:1.17 environment: GOPROXY: https://goproxy.cn,direct commands: @@ -22,7 +22,7 @@ steps: - name: check pull: always - image: golang:1.13 + image: golang:1.17 environment: GOPROXY: https://goproxy.cn,direct commands: @@ -77,10 +77,10 @@ steps: - name: bucket-master pull: always - image: plugins/s3:1 + image: woodpeckerci/plugin-s3:latest settings: acl: public-read - bucket: releases + bucket: gitea-artifacts endpoint: https://storage.gitea.io path_style: true source: "dist/release/*" @@ -97,10 +97,10 @@ steps: - name: bucket-tag pull: always - image: plugins/s3:1 + image: woodpeckerci/plugin-s3:latest settings: acl: public-read - bucket: releases + bucket: gitea-artifacts endpoint: https://storage.gitea.io path_style: true source: "dist/release/*" diff --git a/Makefile b/Makefile index 4f584b1..a97118f 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ generate: lint: @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ export BINARY="golangci-lint"; \ - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.1; \ + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.37.0; \ fi golangci-lint run --timeout 5m -- 2.43.5 From 0ec4342863b5d8c9be02786de40fc3f9f54ee9f4 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Fri, 11 Mar 2022 05:02:27 +0800 Subject: [PATCH 09/42] use direct s3 endpoint (#59) Reviewed-on: https://gitea.com/gitea/changelog/pulls/59 --- .drone.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index bb245d8..a7fc43a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -81,8 +81,7 @@ steps: settings: acl: public-read bucket: gitea-artifacts - endpoint: https://storage.gitea.io - path_style: true + endpoint: https://ams3.digitaloceanspaces.com source: "dist/release/*" strip_prefix: dist/release/ target: /changelog-tool/master @@ -101,8 +100,7 @@ steps: settings: acl: public-read bucket: gitea-artifacts - endpoint: https://storage.gitea.io - path_style: true + endpoint: https://ams3.digitaloceanspaces.com source: "dist/release/*" strip_prefix: dist/release/ target: "/changelog-tool/${DRONE_TAG##v}" -- 2.43.5 From f3ee0e5726ac56b84c5b1e4f62f3e10b73e80b15 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 13 Mar 2022 10:33:03 +0800 Subject: [PATCH 10/42] Add flag to specify git tag (#58) close #57 Reviewed-on: https://gitea.com/gitea/changelog/pulls/58 Reviewed-by: Andrew Thornton Reviewed-by: Norwin --- changelog.example.go | 1 + cmd/cmd.go | 1 + cmd/contributors.go | 2 +- cmd/generate.go | 2 +- main.go | 6 ++++++ service/gitea.go | 7 ++++--- service/github.go | 3 ++- service/service.go | 8 +++++++- 8 files changed, 23 insertions(+), 7 deletions(-) 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], -- 2.43.5 From 57e620da5b886e4e0f8d1083976bb9b4930be64d Mon Sep 17 00:00:00 2001 From: John Olheiser Date: Wed, 22 Jun 2022 09:27:24 +0800 Subject: [PATCH 11/42] Updates and priority changes (#62) Reviewed-on: https://gitea.com/gitea/changelog/pulls/62 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Lunny Xiao Co-authored-by: John Olheiser Co-committed-by: John Olheiser --- .drone.yml | 10 +-- .golangci.yml | 3 +- Makefile | 20 ++--- README.md | 3 +- changelog.example.go | 44 ---------- cmd/cmd.go | 80 ++++++++++++++++-- cmd/contributors.go | 10 +-- cmd/generate.go | 84 ++++++++----------- cmd/init.go | 2 +- .../changelog.example.yml | 0 config/config.go | 35 +++++++- config/config_default.go | 65 -------------- go.mod | 13 ++- main.go | 66 +-------------- 14 files changed, 169 insertions(+), 266 deletions(-) delete mode 100644 changelog.example.go rename changelog.example.yml => config/changelog.example.yml (100%) delete mode 100644 config/config_default.go diff --git a/.drone.yml b/.drone.yml index a7fc43a..99b6073 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,18 +13,18 @@ trigger: steps: - name: build pull: always - image: golang:1.17 + image: golang:1.18 environment: - GOPROXY: https://goproxy.cn,direct + GOPROXY: https://goproxy.io,direct commands: - go test -race ./... - go build - name: check pull: always - image: golang:1.17 + image: golang:1.18 environment: - GOPROXY: https://goproxy.cn,direct + GOPROXY: https://goproxy.io,direct commands: - make lint @@ -70,7 +70,7 @@ steps: pull: always image: techknowlogick/xgo:latest environment: - GOPROXY: https://goproxy.cn,direct + GOPROXY: https://goproxy.io,direct commands: - export PATH=$PATH:$GOPATH/bin - make release diff --git a/.golangci.yml b/.golangci.yml index 6561c3f..2b6a8ba 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,12 +10,11 @@ linters: - gocritic - gocyclo - gofmt - - golint - gosimple - govet - - maligned - misspell - prealloc + - revive - staticcheck - structcheck - typecheck diff --git a/Makefile b/Makefile index a97118f..113dbf1 100644 --- a/Makefile +++ b/Makefile @@ -15,27 +15,23 @@ else LONG_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//') endif -LDFLAGS := $(LDFLAGS) -X "main.Version=$(LONG_VERSION)" +LDFLAGS := $(LDFLAGS) -X "code.gitea.io/changelog/cmd.Version=$(LONG_VERSION)" .PHONY: build -build: generate +build: $(GO) build -ldflags '-s -w $(LDFLAGS)' - -.PHONY: generate -generate: - $(GO) generate ./... + +.PHONY: test +test: + $(GO) test -race -v ./... .PHONY: lint lint: - @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ - export BINARY="golangci-lint"; \ - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.37.0; \ - fi - golangci-lint run --timeout 5m + $(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2 run --timeout 5m .PHONY: fmt fmt: - go fmt ./... + $(GO) fmt ./... .PHONY: release release: release-dirs check-xgo release-windows release-linux release-darwin release-copy release-compress release-check diff --git a/README.md b/README.md index faf8c97..cc94d7c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Download a pre-built binary from our [downloads page](https://dl.gitea.io/change ## Configuration -See the [changelog.example.yml](changelog.example.yml) example file. +See the [changelog.example.yml](config/changelog.example.yml) example file. ## Usage @@ -31,7 +31,6 @@ changelog -m=1.11.0 -c=/path/to/my_config_file contributors ## Building ``` -go generate ./... go build ``` diff --git a/changelog.example.go b/changelog.example.go deleted file mode 100644 index b370761..0000000 --- a/changelog.example.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2020 The Gitea Authors. All rights reserved. -// 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 - -import ( - "fmt" - "io/ioutil" - "os" -) - -const ( - exampleFile = "changelog.example.yml" - writeFile = "config/config_default.go" - tmpl = `// Copyright 2020 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package config - -func init() { - DefaultConfig = []byte(` + "`" + `%s` + "`" + `) -} -` -) - -func main() { - bytes, err := ioutil.ReadFile(exampleFile) - if err != nil { - fmt.Printf("Could not read from %s. Are you in the root directory of the project?", exampleFile) - os.Exit(1) - } - - data := fmt.Sprintf(tmpl, string(bytes)) - - if err := ioutil.WriteFile(writeFile, []byte(data), os.ModePerm); err != nil { - fmt.Printf("Could not write to %s.", writeFile) - os.Exit(1) - } -} diff --git a/cmd/cmd.go b/cmd/cmd.go index 434cb41..25284c8 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Gitea Authors. All rights reserved. +// Copyright 2018 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -7,18 +7,82 @@ package cmd import ( "os" "path/filepath" + + "github.com/urfave/cli/v2" ) var ( - MilestoneFlag string - TagFlag string - ConfigPathFlag string - TokenFlag string - DetailsFlag bool - AfterFlag int64 - IssuesFlag bool + // Version of changelog + Version = "development" + milestoneFlag string + tagFlag string + configPathFlag string + tokenFlag string + detailsFlag bool + afterFlag int64 + issuesFlag bool ) +// New returns a new changelog App +func New() *cli.App { + app := &cli.App{ + Name: "changelog", + Usage: "Changelog tools for Gitea", + Version: Version, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "milestone", + Aliases: []string{"m"}, + Usage: "Targeted milestone", + Destination: &milestoneFlag, + }, + &cli.StringFlag{ + Name: "tag", + Aliases: []string{"T"}, + Usage: "Git tag for milestone url, if not set milestone is used", + Destination: &tagFlag, + }, + &cli.StringFlag{ + Name: "config", + Aliases: []string{"c"}, + Usage: "Specify a config file", + Value: getDefaultConfigFile(), + Destination: &configPathFlag, + }, + &cli.StringFlag{ + Name: "token", + Aliases: []string{"t"}, + Usage: "Access token for private repositories/instances", + Destination: &tokenFlag, + }, + &cli.BoolFlag{ + Name: "details", + Aliases: []string{"d"}, + Usage: "Generate detail lists instead of long lists", + Destination: &detailsFlag, + }, + &cli.Int64Flag{ + Name: "after", + Aliases: []string{"a"}, + Usage: "Only select PRs after a given index (continuing a previous changelog)", + Destination: &afterFlag, + }, + &cli.BoolFlag{ + Name: "issues", + Aliases: []string{"i"}, + Usage: "Generate changelog from issues (otherwise from pulls)", + Destination: &issuesFlag, + }, + }, + Commands: []*cli.Command{ + Generate, + Contributors, + Init, + }, + } + return app +} + func getDefaultConfigFile() string { pwd, err := os.Getwd() if err != nil { diff --git a/cmd/contributors.go b/cmd/contributors.go index d0b09f6..fbed4d9 100644 --- a/cmd/contributors.go +++ b/cmd/contributors.go @@ -20,17 +20,13 @@ var Contributors = &cli.Command{ Action: runContributors, } -func runContributors(cmd *cli.Context) error { - if ConfigPathFlag == "" { - ConfigPathFlag = getDefaultConfigFile() - } - - cfg, err := config.New(ConfigPathFlag) +func runContributors(_ *cli.Context) error { + cfg, err := config.New(configPathFlag) if err != nil { return err } - s, err := service.New(cfg.Service, cfg.Repo, cfg.BaseURL, MilestoneFlag, TagFlag, 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 94d264f..ee77b63 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -7,6 +7,7 @@ package cmd import ( "fmt" "regexp" + "strings" "code.gitea.io/changelog/config" "code.gitea.io/changelog/service" @@ -14,30 +15,19 @@ import ( "github.com/urfave/cli/v2" ) -var ( - Generate = &cli.Command{ - Name: "generate", - Usage: "Generates a changelog for a special milestone", - Action: runGenerate, - } - labels = make(map[string]string) - entries = make(map[string][]service.Entry) - defaultGroup string -) +var Generate = &cli.Command{ + Name: "generate", + Usage: "Generates a changelog for a special milestone", + Action: runGenerate, +} -func runGenerate(cmd *cli.Context) error { - if ConfigPathFlag == "" { - ConfigPathFlag = getDefaultConfigFile() - } - - cfg, err := config.New(ConfigPathFlag) +func runGenerate(_ *cli.Context) error { + cfg, err := config.New(configPathFlag) if err != nil { return err } - processGroups(cfg.Groups) - - s, err := service.New(cfg.Service, cfg.Repo, cfg.BaseURL, MilestoneFlag, TagFlag, TokenFlag, IssuesFlag) + s, err := service.New(cfg.Service, cfg.Repo, cfg.BaseURL, milestoneFlag, tagFlag, tokenFlag, issuesFlag) if err != nil { return err } @@ -47,7 +37,17 @@ func runGenerate(cmd *cli.Context) error { return err } - processPRs(prs, cfg.SkipRegex) + var defaultGroup string + for _, g := range cfg.Groups { + if g.Default { + defaultGroup = g.Name + } + } + if defaultGroup == "" { + defaultGroup = cfg.Groups[len(cfg.Groups)-1].Name + } + + entries := processPRs(prs, cfg.NameLabels(), defaultGroup, cfg.SkipRegex) fmt.Println(title) fmt.Println() @@ -56,7 +56,7 @@ func runGenerate(cmd *cli.Context) error { continue } - if DetailsFlag { + if detailsFlag { fmt.Println("
" + g.Name + "") fmt.Println() for _, entry := range entries[g.Name] { @@ -74,44 +74,32 @@ func runGenerate(cmd *cli.Context) error { return nil } -func processGroups(groups []config.Group) { - for _, g := range groups { - entries[g.Name] = []service.Entry{} - for _, l := range g.Labels { - labels[l] = g.Name - } - if g.Default { - defaultGroup = g.Name - } - } - - if defaultGroup == "" { - defaultGroup = groups[len(groups)-1].Name - } -} - -func processPRs(prs []service.Entry, skip *regexp.Regexp) { +func processPRs(prs []service.Entry, order []config.NameLabel, defaultGroup string, skip *regexp.Regexp) map[string][]service.Entry { + entries := make(map[string][]service.Entry) PRLoop: // labels in Go, let's get old school for _, pr := range prs { - if pr.Index < AfterFlag { + if pr.Index < afterFlag { continue } - var label string for _, lb := range pr.Labels { if skip != nil && skip.MatchString(lb.Name) { continue PRLoop } + } + section := processSection(pr, order, defaultGroup) + entries[section] = append(entries[section], pr) + } + return entries +} - if g, ok := labels[lb.Name]; ok && len(label) == 0 { - label = g +func processSection(pr service.Entry, order []config.NameLabel, defaultGroup string) string { + for _, o := range order { + for _, lb := range pr.Labels { + if strings.EqualFold(o.Label, lb.Name) { + return o.Name } } - - if len(label) > 0 { - entries[label] = append(entries[label], pr) - } else { - entries[defaultGroup] = append(entries[defaultGroup], pr) - } } + return defaultGroup } diff --git a/cmd/init.go b/cmd/init.go index 0666cfc..629a155 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -32,7 +32,7 @@ var ( nameFlag string ) -func runInit(cmd *cli.Context) error { +func runInit(_ *cli.Context) error { if _, err := os.Stat(nameFlag); err == nil { return fmt.Errorf("file '%s' already exists", nameFlag) } diff --git a/changelog.example.yml b/config/changelog.example.yml similarity index 100% rename from changelog.example.yml rename to config/changelog.example.yml diff --git a/config/config.go b/config/config.go index cf040ed..08a32ae 100644 --- a/config/config.go +++ b/config/config.go @@ -5,12 +5,14 @@ package config import ( + _ "embed" "io/ioutil" "regexp" "gopkg.in/yaml.v2" ) +//go:embed changelog.example.yml var DefaultConfig []byte // Group is a grouping of PRs @@ -20,6 +22,24 @@ type Group struct { Default bool `yaml:"default"` } +// NameLabel is a Group mapping for a Label to a Name +type NameLabel struct { + Name string + Label string +} + +// NameLabels returns a slice of NameLabel +func (g Group) NameLabels() []NameLabel { + nl := make([]NameLabel, 0) + for _, l := range g.Labels { + nl = append(nl, NameLabel{ + Name: g.Name, + Label: l, + }) + } + return nl +} + // Config is the changelog settings type Config struct { Repo string `yaml:"repo"` @@ -30,13 +50,20 @@ type Config struct { SkipRegex *regexp.Regexp `yaml:"-"` } +// NameLabels returns a slice of NameLabel for each Group, keeping them in order (priority) +func (c Config) NameLabels() []NameLabel { + nl := make([]NameLabel, 0) + for _, g := range c.Groups { + nl = append(nl, g.NameLabels()...) + } + return nl +} + // New Load a config from a path, defaulting to changelog.example.yml func New(configPath string) (*Config, error) { var err error - var configContent []byte - if len(configPath) == 0 { - configContent = DefaultConfig - } else { + configContent := DefaultConfig + if len(configPath) != 0 { configContent, err = ioutil.ReadFile(configPath) if err != nil { return nil, err diff --git a/config/config_default.go b/config/config_default.go deleted file mode 100644 index b224d64..0000000 --- a/config/config_default.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2020 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package config - -func init() { - DefaultConfig = []byte(`# The full repository name -repo: go-gitea/gitea - -# Service type (gitea or github) -service: github - -# Base URL for Gitea instance if using gitea service type (optional) -# Default: https://gitea.com -base-url: - -# Changelog groups and which labeled PRs to add to each group -groups: - - - name: BREAKING - labels: - - kind/breaking - - - name: FEATURES - labels: - - kind/feature - - - name: BUGFIXES - labels: - - kind/bug - - - name: ENHANCEMENTS - labels: - - kind/enhancement - - kind/refactor - - kind/ui - - - name: SECURITY - labels: - - kind/security - - - name: TESTING - labels: - - kind/testing - - - name: TRANSLATION - labels: - - kind/translation - - - name: BUILD - labels: - - kind/build - - kind/lint - - - name: DOCS - labels: - - kind/docs - - - name: MISC - default: true - -# regex indicating which labels to skip for the changelog -skip-labels: skip-changelog|backport\/.+`) -} diff --git a/go.mod b/go.mod index a85f863..2705659 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,19 @@ module code.gitea.io/changelog -go 1.13 +go 1.18 require ( code.gitea.io/sdk/gitea v0.14.0 - github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/google/go-github/v32 v32.1.0 github.com/urfave/cli/v2 v2.2.0 - golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect gopkg.in/yaml.v2 v2.3.0 ) + +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect + github.com/google/go-querystring v1.0.0 // indirect + github.com/hashicorp/go-version v1.2.1 // indirect + github.com/russross/blackfriday/v2 v2.0.1 // indirect + github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect +) diff --git a/main.go b/main.go index dab4a04..2f5326e 100644 --- a/main.go +++ b/main.go @@ -4,79 +4,15 @@ package main -//go:generate go run changelog.example.go -//go:generate go fmt ./... - import ( "fmt" "os" "code.gitea.io/changelog/cmd" - - "github.com/urfave/cli/v2" -) - -var ( - // Version of changelog - Version = "development" ) func main() { - app := &cli.App{ - Name: "changelog", - Usage: "Changelog tools for Gitea", - Version: Version, - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "milestone", - Aliases: []string{"m"}, - 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"}, - Usage: "Specify a config file", - Destination: &cmd.ConfigPathFlag, - }, - &cli.StringFlag{ - Name: "token", - Aliases: []string{"t"}, - Usage: "Access token for private repositories/instances", - Destination: &cmd.TokenFlag, - }, - &cli.BoolFlag{ - Name: "details", - Aliases: []string{"d"}, - Usage: "Generate detail lists instead of long lists", - Destination: &cmd.DetailsFlag, - }, - &cli.Int64Flag{ - Name: "after", - Aliases: []string{"a"}, - Usage: "Only select PRs after a given index (continuing a previous changelog)", - Destination: &cmd.AfterFlag, - }, - &cli.BoolFlag{ - Name: "issues", - Aliases: []string{"i"}, - Usage: "Generate changelog from issues (otherwise from pulls)", - Destination: &cmd.IssuesFlag, - }, - }, - Commands: []*cli.Command{ - cmd.Generate, - cmd.Contributors, - cmd.Init, - }, - } - + app := cmd.New() if err := app.Run(os.Args); err != nil { fmt.Printf("Failed to run app with %s: %v\n", os.Args[1:], err) } -- 2.43.5 From 05a5366d7f9a73b5c5376abeee2ece7ae7c09d8c Mon Sep 17 00:00:00 2001 From: John Olheiser Date: Wed, 22 Jun 2022 17:16:56 +0800 Subject: [PATCH 12/42] Skip un-grouped PRs if no default is set (#64) Reviewed-on: https://gitea.com/gitea/changelog/pulls/64 Reviewed-by: Lunny Xiao Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: John Olheiser Co-committed-by: John Olheiser --- cmd/generate.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/generate.go b/cmd/generate.go index ee77b63..9da8178 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -44,7 +44,7 @@ func runGenerate(_ *cli.Context) error { } } if defaultGroup == "" { - defaultGroup = cfg.Groups[len(cfg.Groups)-1].Name + fmt.Println("") } entries := processPRs(prs, cfg.NameLabels(), defaultGroup, cfg.SkipRegex) @@ -88,6 +88,9 @@ PRLoop: // labels in Go, let's get old school } } section := processSection(pr, order, defaultGroup) + if section == "" { + continue + } entries[section] = append(entries[section], pr) } return entries -- 2.43.5 From e8f6cebd8b7fac53c0b9d7c66e2ffd74ee12a341 Mon Sep 17 00:00:00 2001 From: John Olheiser Date: Thu, 23 Jun 2022 20:23:37 +0800 Subject: [PATCH 13/42] New install method for gxz (#65) Reviewed-on: https://gitea.com/gitea/changelog/pulls/65 Reviewed-by: Norwin Reviewed-by: Lunny Xiao Co-authored-by: John Olheiser Co-committed-by: John Olheiser --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 113dbf1..aeb1467 100644 --- a/Makefile +++ b/Makefile @@ -78,6 +78,6 @@ release-check: .PHONY: release-compress release-compress: @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ - $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \ + $(GO) install github.com/ulikunitz/xz/cmd/gxz@latest; \ fi cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done; -- 2.43.5 From 37ed264d72d33dc5fc2d1ec934fb1da7f39c0198 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 22 Aug 2022 23:53:51 +0800 Subject: [PATCH 14/42] rename primary branch (#67) Reviewed-on: https://gitea.com/gitea/changelog/pulls/67 --- .drone.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index 99b6073..5db5151 100644 --- a/.drone.yml +++ b/.drone.yml @@ -54,7 +54,7 @@ platform: trigger: branch: - - master + - main event: - push - tag @@ -75,7 +75,7 @@ steps: - export PATH=$PATH:$GOPATH/bin - make release - - name: bucket-master + - name: bucket-main pull: always image: woodpeckerci/plugin-s3:latest settings: @@ -84,7 +84,7 @@ steps: endpoint: https://ams3.digitaloceanspaces.com source: "dist/release/*" strip_prefix: dist/release/ - target: /changelog-tool/master + target: /changelog-tool/main environment: AWS_ACCESS_KEY_ID: from_secret: aws_access_key_id -- 2.43.5 From 3b83ddcefbe02a9a56d841f8adc7bccbfaa77683 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Fri, 16 Sep 2022 17:31:37 +0800 Subject: [PATCH 15/42] Pass global flags down to subcommands (#54) Fix #51 Signed-off-by: Andrew Thornton Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/changelog/pulls/54 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Norwin Co-authored-by: Andrew Thornton Co-committed-by: Andrew Thornton --- .gitignore | 5 ++++- README.md | 18 +++++++++++------- cmd/cmd.go | 26 ++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 11b7250..dfbe66a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ # Binaries /changelog -/changelog.exe \ No newline at end of file +/changelog.exe + +# Go +/vendor/ diff --git a/README.md b/README.md index cc94d7c..1e9ad83 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Changelog + A changelog generator for Gitea [![Build Status](https://drone.gitea.com/api/badges/gitea/changelog/status.svg)](https://drone.gitea.com/gitea/changelog) @@ -19,18 +20,21 @@ See the [changelog.example.yml](config/changelog.example.yml) example file. ## Usage -#### Changelog Entries -``` -changelog -m=1.11.0 -c=/path/to/my_config_file generate +### Changelog Entries + +```sh +changelog generate -m=1.11.0 -c=/path/to/my_config_file ``` -#### Contributors List -``` -changelog -m=1.11.0 -c=/path/to/my_config_file contributors +### Contributors List + +```sh +changelog contributors -m=1.11.0 -c=/path/to/my_config_file ``` ## Building -``` + +```sh go build ``` diff --git a/cmd/cmd.go b/cmd/cmd.go index 25284c8..77e869b 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -80,6 +80,7 @@ func New() *cli.App { Init, }, } + copyGlobalFlags(app) return app } @@ -95,3 +96,28 @@ func getDefaultConfigFile() string { } return "" } + +func copyGlobalFlags(app *cli.App) { + for _, command := range app.Commands { + originalFlagNames := make([]string, 0, len(command.Flags)) + for _, flag := range command.Flags { + originalFlagNames = append(originalFlagNames, flag.Names()...) + } + + for _, flag := range app.Flags { + found := false + flagNameLoop: + for _, name := range flag.Names() { + for _, originalName := range originalFlagNames { + if name == originalName { + found = true + break flagNameLoop + } + } + } + if !found { + command.Flags = append(command.Flags, flag) + } + } + } +} -- 2.43.5 From 5f171f4c5e57cdbba73a1e86258c96ce5a4ccd44 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Wed, 8 Feb 2023 06:05:57 +0800 Subject: [PATCH 16/42] use drone secrets for s3 info (#69) Reviewed-on: https://gitea.com/gitea/changelog/pulls/69 --- .drone.yml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.drone.yml b/.drone.yml index 5db5151..21cfd9e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -79,9 +79,16 @@ steps: pull: always image: woodpeckerci/plugin-s3:latest settings: - acl: public-read - bucket: gitea-artifacts - endpoint: https://ams3.digitaloceanspaces.com + acl: + from_secret: aws_s3_acl + region: + from_secret: aws_s3_region + bucket: + from_secret: aws_s3_bucket + endpoint: + from_secret: aws_s3_endpoint + path_style: + from_secret: aws_s3_path_style source: "dist/release/*" strip_prefix: dist/release/ target: /changelog-tool/main @@ -98,9 +105,16 @@ steps: pull: always image: woodpeckerci/plugin-s3:latest settings: - acl: public-read - bucket: gitea-artifacts - endpoint: https://ams3.digitaloceanspaces.com + acl: + from_secret: aws_s3_acl + region: + from_secret: aws_s3_region + bucket: + from_secret: aws_s3_bucket + endpoint: + from_secret: aws_s3_endpoint + path_style: + from_secret: aws_s3_path_style source: "dist/release/*" strip_prefix: dist/release/ target: "/changelog-tool/${DRONE_TAG##v}" -- 2.43.5 From e05ef3c2548976be07c730c956ac9d38df62d4c4 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 28 Feb 2023 05:59:03 +0800 Subject: [PATCH 17/42] use go 1.20 (#68) Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/changelog/pulls/68 Reviewed-by: Lunny Xiao Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: appleboy --- .drone.yml | 4 ++-- Makefile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index 21cfd9e..481fcfd 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,7 +13,7 @@ trigger: steps: - name: build pull: always - image: golang:1.18 + image: golang:1.20 environment: GOPROXY: https://goproxy.io,direct commands: @@ -22,7 +22,7 @@ steps: - name: check pull: always - image: golang:1.18 + image: golang:1.20 environment: GOPROXY: https://goproxy.io,direct commands: diff --git a/Makefile b/Makefile index aeb1467..8cc2b3a 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ test: .PHONY: lint lint: - $(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2 run --timeout 5m + $(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 run --timeout 5m .PHONY: fmt fmt: -- 2.43.5 From 8fc84c6a2de14c03ffbf945bd907278440dde542 Mon Sep 17 00:00:00 2001 From: John Olheiser Date: Tue, 28 Feb 2023 06:21:21 +0800 Subject: [PATCH 18/42] Allow for GH token (#70) After running a few times this morning I started hitting rate limits, so this was a quick way to set an optional GH token. Co-authored-by: jolheiser Co-authored-by: techknowlogick Reviewed-on: https://gitea.com/gitea/changelog/pulls/70 Reviewed-by: Lunny Xiao Reviewed-by: techknowlogick Reviewed-by: appleboy Co-authored-by: John Olheiser Co-committed-by: John Olheiser --- go.mod | 10 +++++++--- go.sum | 32 ++++++++++++++++++++++---------- service/github.go | 21 ++++++++++++++++++--- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 2705659..15b0fbc 100644 --- a/go.mod +++ b/go.mod @@ -4,16 +4,20 @@ go 1.18 require ( code.gitea.io/sdk/gitea v0.14.0 - github.com/google/go-github/v32 v32.1.0 + github.com/google/go-github/v50 v50.0.0 github.com/urfave/cli/v2 v2.2.0 + golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be gopkg.in/yaml.v2 v2.3.0 ) require ( github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect - github.com/google/go-querystring v1.0.0 // indirect + github.com/golang/protobuf v1.3.2 // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/hashicorp/go-version v1.2.1 // indirect github.com/russross/blackfriday/v2 v2.0.1 // indirect github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect - golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect + golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect + golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect + google.golang.org/appengine v1.6.7 // indirect ) diff --git a/go.sum b/go.sum index 83e07fd..09a7632 100644 --- a/go.sum +++ b/go.sum @@ -6,11 +6,15 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II= -github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI= -github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= -github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-github/v50 v50.0.0 h1:gdO1AeuSZZK4iYWwVbjni7zg8PIQhp7QfmPunr016Jk= +github.com/google/go-github/v50 v50.0.0/go.mod h1:Ev4Tre8QoKiolvbpOSG3FIi4Mlon3S2Nt9W5JYqKiwA= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -25,15 +29,23 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig= -golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= +golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/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-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/service/github.go b/service/github.go index 38654ac..5a0193d 100644 --- a/service/github.go +++ b/service/github.go @@ -7,9 +7,12 @@ package service import ( "context" "fmt" + "net/http" + "os" "time" - "github.com/google/go-github/v32/github" + "github.com/google/go-github/v50/github" + "golang.org/x/oauth2" ) // GitHub defines a GitHub service @@ -25,7 +28,7 @@ type GitHub struct { func (gh *GitHub) Generate() (string, []Entry, error) { 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) + client := github.NewClient(httpClient()) ctx := context.Background() prs := make([]Entry, 0) @@ -81,7 +84,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { // Contributors returns a list of contributors from GitHub func (gh *GitHub) Contributors() (ContributorList, error) { - client := github.NewClient(nil) + client := github.NewClient(httpClient()) ctx := context.Background() contributorsMap := make(map[string]bool) @@ -119,3 +122,15 @@ func (gh *GitHub) Contributors() (ContributorList, error) { return contributors, nil } + +func httpClient() *http.Client { + cl := http.DefaultClient + if token, ok := os.LookupEnv("CHANGELOG_GITHUB_TOKEN"); ok { + ctx := context.Background() + ts := oauth2.StaticTokenSource( + &oauth2.Token{AccessToken: token}, + ) + cl = oauth2.NewClient(ctx, ts) + } + return cl +} -- 2.43.5 From f18b0110320a880a9dfa1d6a66c01172b43ef859 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Fri, 17 Mar 2023 04:36:25 +0800 Subject: [PATCH 19/42] build and release nightly (#71) Reviewed-on: https://gitea.com/gitea/changelog/pulls/71 Co-authored-by: techknowlogick Co-committed-by: techknowlogick --- .gitea/workflows/release-nightly.yml | 30 +++++++++ .gitignore | 4 ++ .goreleaser.yaml | 93 ++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 .gitea/workflows/release-nightly.yml create mode 100644 .goreleaser.yaml diff --git a/.gitea/workflows/release-nightly.yml b/.gitea/workflows/release-nightly.yml new file mode 100644 index 0000000..9304808 --- /dev/null +++ b/.gitea/workflows/release-nightly.yml @@ -0,0 +1,30 @@ +name: goreleaser + +on: + push: + branches: [ main ] + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: git fetch --force --tags + - uses: actions/setup-go@v3 + with: + go-version: '>=1.20.1' + - name: goreleaser + uses: https://github.com/goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser-pro + version: latest + args: release --nightly + env: + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} + AWS_REGION: ${{ secrets.AWS_REGION }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + S3_REGION: ${{ secrets.AWS_REGION }} + S3_BUCKET: ${{ secrets.AWS_BUCKET }} diff --git a/.gitignore b/.gitignore index dfbe66a..8c854ab 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,7 @@ # Go /vendor/ + +dist/ + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..94c4f7c --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,93 @@ +before: + hooks: + - go mod tidy + +builds: +- env: + - CGO_ENABLED=0 + goos: + - darwin + - linux + - windows + - freebsd + goarch: + - amd64 + - arm + - arm64 +# - s390x +# - ppc64le + goarm: + - "5" + - "6" + - "7" + ignore: + - goos: darwin + goarch: arm + - goos: darwin + goarch: ppc64le + - goos: darwin + goarch: s390x + - goos: windows + goarch: ppc64le + - goos: windows + goarch: s390x + - goos: windows + goarch: arm + goarm: "5" + - goos: windows + goarch: arm + goarm: "6" + - goos: windows + goarch: arm + goarm: "7" + - goos: freebsd + goarch: ppc64le + - goos: freebsd + goarch: s390x + - goos: freebsd + goarch: arm + goarm: "5" + - goos: freebsd + goarch: arm + goarm: "6" + - goos: freebsd + goarch: arm + goarm: "7" + flags: + - -trimpath + ldflags: + - -s -w -X code.gitea.io/changelog/cmd.Version={{ .Version }} + binary: >- + {{ .ProjectName }}- + {{- .Version }}- + {{- .Os }}- + {{- if eq .Arch "amd64" }}amd64 + {{- else if eq .Arch "amd64_v1" }}amd64 + {{- else if eq .Arch "386" }}386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}-{{ .Arm }}{{ end }} + no_unique_dist_dir: true + +blobs: + - + provider: s3 + bucket: "{{ .Env.S3_BUCKET }}" + region: "{{ .Env.S3_REGION }}" + folder: "changelog-tool/{{.Version}}" + +archives: + - format: binary + name_template: "{{ .Binary }}" + allow_different_binary_count: true + +checksum: + name_template: 'checksums.txt' + +snapshot: + name_template: "{{ .Branch }}-devel" + +nightly: + name_template: "{{ .Branch }}" + +# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj -- 2.43.5 From a63229683128ee029bf115d9059f63088406941a Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Fri, 17 Mar 2023 04:50:35 +0800 Subject: [PATCH 20/42] actions: test pull requests (#72) Reviewed-on: https://gitea.com/gitea/changelog/pulls/72 Co-authored-by: techknowlogick Co-committed-by: techknowlogick --- .drone.yml | 141 ----------------------------------- .gitea/workflows/test-pr.yml | 19 +++++ .gitignore | 2 - 3 files changed, 19 insertions(+), 143 deletions(-) delete mode 100644 .drone.yml create mode 100644 .gitea/workflows/test-pr.yml diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 481fcfd..0000000 --- a/.drone.yml +++ /dev/null @@ -1,141 +0,0 @@ ---- -kind: pipeline -name: compliance - -platform: - os: linux - arch: arm64 - -trigger: - event: - - pull_request - -steps: -- name: build - pull: always - image: golang:1.20 - environment: - GOPROXY: https://goproxy.io,direct - commands: - - go test -race ./... - - go build - -- name: check - pull: always - image: golang:1.20 - environment: - GOPROXY: https://goproxy.io,direct - commands: - - make lint - -- name: discord - pull: always - image: appleboy/drone-discord:1 - environment: - DISCORD_WEBHOOK_ID: - from_secret: discord_webhook_id - DISCORD_WEBHOOK_TOKEN: - from_secret: discord_webhook_token - when: - event: - - push - - tag - status: - - changed - - failure - ---- -kind: pipeline -name: release - -platform: - os: linux - arch: amd64 - -trigger: - branch: - - main - event: - - push - - tag - -steps: - - name: fetch-tags - pull: always - image: docker:git - commands: - - git fetch --tags --force - - - name: release - pull: always - image: techknowlogick/xgo:latest - environment: - GOPROXY: https://goproxy.io,direct - commands: - - export PATH=$PATH:$GOPATH/bin - - make release - - - name: bucket-main - pull: always - image: woodpeckerci/plugin-s3:latest - settings: - acl: - from_secret: aws_s3_acl - region: - from_secret: aws_s3_region - bucket: - from_secret: aws_s3_bucket - endpoint: - from_secret: aws_s3_endpoint - path_style: - from_secret: aws_s3_path_style - source: "dist/release/*" - strip_prefix: dist/release/ - target: /changelog-tool/main - environment: - AWS_ACCESS_KEY_ID: - from_secret: aws_access_key_id - AWS_SECRET_ACCESS_KEY: - from_secret: aws_secret_access_key - when: - event: - - push - - - name: bucket-tag - pull: always - image: woodpeckerci/plugin-s3:latest - settings: - acl: - from_secret: aws_s3_acl - region: - from_secret: aws_s3_region - bucket: - from_secret: aws_s3_bucket - endpoint: - from_secret: aws_s3_endpoint - path_style: - from_secret: aws_s3_path_style - source: "dist/release/*" - strip_prefix: dist/release/ - target: "/changelog-tool/${DRONE_TAG##v}" - environment: - AWS_ACCESS_KEY_ID: - from_secret: aws_access_key_id - AWS_SECRET_ACCESS_KEY: - from_secret: aws_secret_access_key - when: - event: - - tag - - - name: gitea - pull: always - image: plugins/gitea-release:1 - settings: - api_key: - from_secret: gitea_token - base_url: https://gitea.com - files: - - "dist/release/*" - when: - event: - - tag \ No newline at end of file diff --git a/.gitea/workflows/test-pr.yml b/.gitea/workflows/test-pr.yml new file mode 100644 index 0000000..cda25df --- /dev/null +++ b/.gitea/workflows/test-pr.yml @@ -0,0 +1,19 @@ +name: check-and-test + +on: [pull_request] + +jobs: + check-and-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: '>=1.20.1' + - name: check-and-test + run: | + go test -race ./... + go build + make lint + env: + GOPROXY: https://goproxy.io,direct diff --git a/.gitignore b/.gitignore index 8c854ab..6bea5b4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,3 @@ /vendor/ dist/ - -dist/ -- 2.43.5 From 583ac7def28e30cda6f730f0e7af1085d3857e9e Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 00:45:40 -0400 Subject: [PATCH 21/42] xz binaries --- .goreleaser.yaml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 94c4f7c..a5cb989 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -2,6 +2,31 @@ before: hooks: - go mod tidy +after: + hooks: + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-amd64.xz {{ .ProjectName }}-{{ .Version }}-darwin-amd64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-arm64.xz {{ .ProjectName }}-{{ .Version }}-darwin-arm64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-7.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-7 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-amd64.xz {{ .ProjectName }}-{{ .Version }}-linux-amd64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-6.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-6 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm64.xz {{ .ProjectName }}-{{ .Version }}-linux-arm64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-5.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-5 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-arm64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-arm64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-amd64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-amd64 + dir: dist + builds: - env: - CGO_ENABLED=0 -- 2.43.5 From f2b3d8d60f588e04620135f4318910d2e4438954 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 00:53:02 -0400 Subject: [PATCH 22/42] run post build --- .goreleaser.yaml | 51 +++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a5cb989..292f84a 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -2,31 +2,6 @@ before: hooks: - go mod tidy -after: - hooks: - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-amd64.xz {{ .ProjectName }}-{{ .Version }}-darwin-amd64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-arm64.xz {{ .ProjectName }}-{{ .Version }}-darwin-arm64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-7.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-7 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-amd64.xz {{ .ProjectName }}-{{ .Version }}-linux-amd64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-6.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-6 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm64.xz {{ .ProjectName }}-{{ .Version }}-linux-arm64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-5.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-5 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-arm64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-arm64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-amd64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-amd64 - dir: dist - builds: - env: - CGO_ENABLED=0 @@ -39,8 +14,6 @@ builds: - amd64 - arm - arm64 -# - s390x -# - ppc64le goarm: - "5" - "6" @@ -92,6 +65,30 @@ builds: {{- else }}{{ .Arch }}{{ end }} {{- if .Arm }}-{{ .Arm }}{{ end }} no_unique_dist_dir: true + hooks: + post: + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-amd64.xz {{ .ProjectName }}-{{ .Version }}-darwin-amd64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-arm64.xz {{ .ProjectName }}-{{ .Version }}-darwin-arm64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-7.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-7 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-amd64.xz {{ .ProjectName }}-{{ .Version }}-linux-amd64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-6.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-6 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm64.xz {{ .ProjectName }}-{{ .Version }}-linux-arm64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-5.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-5 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-arm64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-arm64 + dir: dist + - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-amd64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-amd64 + dir: dist blobs: - -- 2.43.5 From d55f6646fbc6c2067e792919eb6e8941dd218347 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 00:59:17 -0400 Subject: [PATCH 23/42] simplify hooks --- .goreleaser.yaml | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 292f84a..d6bdc14 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -67,28 +67,7 @@ builds: no_unique_dist_dir: true hooks: post: - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-amd64.xz {{ .ProjectName }}-{{ .Version }}-darwin-amd64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-darwin-arm64.xz {{ .ProjectName }}-{{ .Version }}-darwin-arm64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-7.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-7 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-amd64.xz {{ .ProjectName }}-{{ .Version }}-linux-amd64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-6.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-6 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-amd64.exe - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm64.xz {{ .ProjectName }}-{{ .Version }}-linux-arm64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-linux-arm-5.xz {{ .ProjectName }}-{{ .Version }}-linux-arm-5 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe.xz {{ .ProjectName }}-{{ .Version }}-windows-arm64.exe - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-arm64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-arm64 - dir: dist - - cmd: tar -cJf {{ .ProjectName }}-{{ .Version }}-freebsd-amd64.xz {{ .ProjectName }}-{{ .Version }}-freebsd-amd64 - dir: dist + - cmd: tar -cJf {{ .Path }}.xz {{ .Path }} blobs: - -- 2.43.5 From 88538267db88a55d49ba28578a1f35ff1e290522 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:09:05 -0400 Subject: [PATCH 24/42] individual checksums --- .goreleaser.checksum.sh | 10 ++++++++++ .goreleaser.yaml | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 .goreleaser.checksum.sh diff --git a/.goreleaser.checksum.sh b/.goreleaser.checksum.sh new file mode 100644 index 0000000..042f0a2 --- /dev/null +++ b/.goreleaser.checksum.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +if [ -z "$1" ]; then + echo "usage: $0 " + exit 1 +fi + +shasum -a 256 "$1" | cut -d' ' -f1 > "$1".sha256 \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d6bdc14..8519b15 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -68,6 +68,10 @@ builds: hooks: post: - cmd: tar -cJf {{ .Path }}.xz {{ .Path }} + env: + - XZ_OPT=-9 + - cmd: .goreleaser.checksum.sh {{ .Path }} + - cmd: .goreleaser.checksum.sh {{ .Path }}.xz blobs: - -- 2.43.5 From b3eaafbefe006b61f556c917930f7fb6cb2c1f2b Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:16:18 -0400 Subject: [PATCH 25/42] add executable bit --- .goreleaser.checksum.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .goreleaser.checksum.sh diff --git a/.goreleaser.checksum.sh b/.goreleaser.checksum.sh old mode 100644 new mode 100755 -- 2.43.5 From bda1f380e209c70898d6f992a5d996468868b332 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:20:34 -0400 Subject: [PATCH 26/42] execute with shell --- .goreleaser.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 8519b15..ffb6786 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -70,8 +70,8 @@ builds: - cmd: tar -cJf {{ .Path }}.xz {{ .Path }} env: - XZ_OPT=-9 - - cmd: .goreleaser.checksum.sh {{ .Path }} - - cmd: .goreleaser.checksum.sh {{ .Path }}.xz + - cmd: sh .goreleaser.checksum.sh {{ .Path }} + - cmd: sh .goreleaser.checksum.sh {{ .Path }}.xz blobs: - -- 2.43.5 From 0650d7c623e8330254cb67ca3a686b9027eaa00a Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:27:14 -0400 Subject: [PATCH 27/42] generate full checksum --- .goreleaser.checksum.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.goreleaser.checksum.sh b/.goreleaser.checksum.sh index 042f0a2..ed205df 100755 --- a/.goreleaser.checksum.sh +++ b/.goreleaser.checksum.sh @@ -7,4 +7,6 @@ if [ -z "$1" ]; then exit 1 fi -shasum -a 256 "$1" | cut -d' ' -f1 > "$1".sha256 \ No newline at end of file +SUM=$(shasum -a 256 "$1" | cut -d' ' -f1) +BASENAME=$(basename "$1") +echo -n "${SUM} ${BASENAME}" > "$1".sha256 \ No newline at end of file -- 2.43.5 From 66f3e382a16cf3f429bd246fb807e4b628a06633 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:32:19 -0400 Subject: [PATCH 28/42] upload custom files --- .goreleaser.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index ffb6786..141f5cf 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -79,6 +79,9 @@ blobs: bucket: "{{ .Env.S3_BUCKET }}" region: "{{ .Env.S3_REGION }}" folder: "changelog-tool/{{.Version}}" + extra_files: + - glob: ./**.xz + - glob: ./**.sha256 archives: - format: binary -- 2.43.5 From d17e881692c6cf083061321d2435618d461ab033 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:49:03 -0400 Subject: [PATCH 29/42] properly format checksum file --- .goreleaser.checksum.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.checksum.sh b/.goreleaser.checksum.sh index ed205df..a11b71d 100755 --- a/.goreleaser.checksum.sh +++ b/.goreleaser.checksum.sh @@ -9,4 +9,4 @@ fi SUM=$(shasum -a 256 "$1" | cut -d' ' -f1) BASENAME=$(basename "$1") -echo -n "${SUM} ${BASENAME}" > "$1".sha256 \ No newline at end of file +echo -n "${SUM} ${BASENAME}" > "$1".sha256 \ No newline at end of file -- 2.43.5 From 374ea1ab46c9f01afebbdcc7f0f151a2d126ea7a Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 18 Mar 2023 01:58:55 -0400 Subject: [PATCH 30/42] checksum compressed files too --- .goreleaser.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 141f5cf..86c179e 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -90,6 +90,8 @@ archives: checksum: name_template: 'checksums.txt' + extra_files: + - glob: ./**.xz snapshot: name_template: "{{ .Branch }}-devel" -- 2.43.5 From cbd80881bcb7e5e7674f748edb7f629e3203783f Mon Sep 17 00:00:00 2001 From: jolheiser Date: Tue, 21 Mar 2023 09:54:34 +0800 Subject: [PATCH 31/42] Trim space on title (#75) Resolves #74 Reviewed-on: https://gitea.com/gitea/changelog/pulls/75 Reviewed-by: Lunny Xiao Reviewed-by: silverwind Co-authored-by: jolheiser Co-committed-by: jolheiser --- service/gitea.go | 3 ++- service/github.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/service/gitea.go b/service/gitea.go index 874f858..a932f1a 100644 --- a/service/gitea.go +++ b/service/gitea.go @@ -6,6 +6,7 @@ package service import ( "fmt" + "strings" "time" "code.gitea.io/sdk/gitea" @@ -92,7 +93,7 @@ func getGiteaTagURL(c *gitea.Client, baseURL, owner, repo, mileName, gitTag, fro func convertToEntry(issue gitea.Issue) Entry { entry := Entry{ Index: issue.Index, - Title: issue.Title, + Title: strings.TrimSpace(issue.Title), } labels := make([]Label, len(issue.Labels)) diff --git a/service/github.go b/service/github.go index 5a0193d..93119ea 100644 --- a/service/github.go +++ b/service/github.go @@ -9,6 +9,7 @@ import ( "fmt" "net/http" "os" + "strings" "time" "github.com/google/go-github/v50/github" @@ -58,7 +59,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { for _, pr := range result.Issues { if pr.IsPullRequest() == isPull { p := Entry{ - Title: pr.GetTitle(), + Title: strings.TrimSpace(pr.GetTitle()), Index: int64(pr.GetNumber()), } -- 2.43.5 From 70c955ae17967a7dfddb770cb8e7748fe0f4d8a6 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Wed, 22 Mar 2023 04:35:58 +0800 Subject: [PATCH 32/42] Title-case PR title (#76) Resolves #60 Extracts the previous trim into a new func as well to keep any title munging consistent. Reviewed-on: https://gitea.com/gitea/changelog/pulls/76 Reviewed-by: Lunny Xiao Reviewed-by: techknowlogick Co-authored-by: jolheiser Co-committed-by: jolheiser --- service/gitea.go | 3 +-- service/github.go | 3 +-- service/service.go | 13 +++++++++++++ service/service_test.go | 24 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/service/gitea.go b/service/gitea.go index a932f1a..2c85808 100644 --- a/service/gitea.go +++ b/service/gitea.go @@ -6,7 +6,6 @@ package service import ( "fmt" - "strings" "time" "code.gitea.io/sdk/gitea" @@ -93,7 +92,7 @@ func getGiteaTagURL(c *gitea.Client, baseURL, owner, repo, mileName, gitTag, fro func convertToEntry(issue gitea.Issue) Entry { entry := Entry{ Index: issue.Index, - Title: strings.TrimSpace(issue.Title), + Title: CleanTitle(issue.Title), } labels := make([]Label, len(issue.Labels)) diff --git a/service/github.go b/service/github.go index 93119ea..00894b6 100644 --- a/service/github.go +++ b/service/github.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "os" - "strings" "time" "github.com/google/go-github/v50/github" @@ -59,7 +58,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { for _, pr := range result.Issues { if pr.IsPullRequest() == isPull { p := Entry{ - Title: strings.TrimSpace(pr.GetTitle()), + Title: CleanTitle(pr.GetTitle()), Index: int64(pr.GetNumber()), } diff --git a/service/service.go b/service/service.go index de7e76a..685d5b9 100644 --- a/service/service.go +++ b/service/service.go @@ -7,6 +7,7 @@ package service import ( "fmt" "strings" + "unicode" ) const defaultGitea = "https://gitea.com" @@ -86,3 +87,15 @@ func (cl ContributorList) Less(i, j int) bool { func (cl ContributorList) Swap(i, j int) { cl[i], cl[j] = cl[j], cl[i] } + +// CleanTitle returns the string with spaces trimmed and the first rune title-cased +func CleanTitle(s string) string { + + s = strings.TrimSpace(s) + + r := []rune(s) + r[0] = unicode.ToUpper(r[0]) + s = string(r) + + return s +} diff --git a/service/service_test.go b/service/service_test.go index 045e70f..47c57cb 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -12,3 +12,27 @@ import ( func TestMain(m *testing.M) { os.Exit(m.Run()) } + +func TestCleanTitle(t *testing.T) { + tt := []struct { + Title string + Expected string + }{ + {Title: "foo", Expected: "Foo"}, + {Title: " foo", Expected: "Foo"}, + {Title: "foo bar", Expected: "Foo bar"}, + {Title: "Foo bar", Expected: "Foo bar"}, + {Title: " Foo bar ", Expected: "Foo bar"}, + {Title: "1234", Expected: "1234"}, + } + + for _, tc := range tt { + t.Run(tc.Title, func(t *testing.T) { + s := CleanTitle(tc.Title) + if s != tc.Expected { + t.Logf("got %q | expected %q", s, tc.Expected) + t.Fail() + } + }) + } +} -- 2.43.5 From 8156d742f5932199634bd7b6405b68387abec6a2 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Mon, 3 Apr 2023 11:51:25 +0800 Subject: [PATCH 33/42] Update to urfave/cli/v3 (#77) This allows for persistent flags, such that `changelog -m v0.4.0 generate` and `changelog generate -m v0.4.0` are equivalent. Reviewed-on: https://gitea.com/gitea/changelog/pulls/77 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Lunny Xiao Co-authored-by: jolheiser Co-committed-by: jolheiser --- cmd/cmd.go | 37 ++++++++++--------------------------- cmd/contributors.go | 2 +- cmd/generate.go | 2 +- cmd/init.go | 2 +- go.mod | 8 ++++---- go.sum | 18 ++++++++---------- 6 files changed, 25 insertions(+), 44 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 77e869b..3ddaf64 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -8,7 +8,7 @@ import ( "os" "path/filepath" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) var ( @@ -24,6 +24,8 @@ var ( ) // New returns a new changelog App +// +//nolint:funlen func New() *cli.App { app := &cli.App{ Name: "changelog", @@ -35,12 +37,14 @@ func New() *cli.App { Aliases: []string{"m"}, Usage: "Targeted milestone", Destination: &milestoneFlag, + Persistent: true, }, &cli.StringFlag{ Name: "tag", Aliases: []string{"T"}, Usage: "Git tag for milestone url, if not set milestone is used", Destination: &tagFlag, + Persistent: true, }, &cli.StringFlag{ Name: "config", @@ -48,30 +52,35 @@ func New() *cli.App { Usage: "Specify a config file", Value: getDefaultConfigFile(), Destination: &configPathFlag, + Persistent: true, }, &cli.StringFlag{ Name: "token", Aliases: []string{"t"}, Usage: "Access token for private repositories/instances", Destination: &tokenFlag, + Persistent: true, }, &cli.BoolFlag{ Name: "details", Aliases: []string{"d"}, Usage: "Generate detail lists instead of long lists", Destination: &detailsFlag, + Persistent: true, }, &cli.Int64Flag{ Name: "after", Aliases: []string{"a"}, Usage: "Only select PRs after a given index (continuing a previous changelog)", Destination: &afterFlag, + Persistent: true, }, &cli.BoolFlag{ Name: "issues", Aliases: []string{"i"}, Usage: "Generate changelog from issues (otherwise from pulls)", Destination: &issuesFlag, + Persistent: true, }, }, Commands: []*cli.Command{ @@ -80,7 +89,6 @@ func New() *cli.App { Init, }, } - copyGlobalFlags(app) return app } @@ -96,28 +104,3 @@ func getDefaultConfigFile() string { } return "" } - -func copyGlobalFlags(app *cli.App) { - for _, command := range app.Commands { - originalFlagNames := make([]string, 0, len(command.Flags)) - for _, flag := range command.Flags { - originalFlagNames = append(originalFlagNames, flag.Names()...) - } - - for _, flag := range app.Flags { - found := false - flagNameLoop: - for _, name := range flag.Names() { - for _, originalName := range originalFlagNames { - if name == originalName { - found = true - break flagNameLoop - } - } - } - if !found { - command.Flags = append(command.Flags, flag) - } - } - } -} diff --git a/cmd/contributors.go b/cmd/contributors.go index fbed4d9..2a06001 100644 --- a/cmd/contributors.go +++ b/cmd/contributors.go @@ -11,7 +11,7 @@ import ( "code.gitea.io/changelog/config" "code.gitea.io/changelog/service" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) var Contributors = &cli.Command{ diff --git a/cmd/generate.go b/cmd/generate.go index 9da8178..39aff8e 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -12,7 +12,7 @@ import ( "code.gitea.io/changelog/config" "code.gitea.io/changelog/service" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) var Generate = &cli.Command{ diff --git a/cmd/init.go b/cmd/init.go index 629a155..9aaa3a5 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -11,7 +11,7 @@ import ( "code.gitea.io/changelog/config" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) var ( diff --git a/go.mod b/go.mod index 15b0fbc..689515b 100644 --- a/go.mod +++ b/go.mod @@ -5,18 +5,18 @@ go 1.18 require ( code.gitea.io/sdk/gitea v0.14.0 github.com/google/go-github/v50 v50.0.0 - github.com/urfave/cli/v2 v2.2.0 + github.com/urfave/cli/v3 v3.0.0-alpha2 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be gopkg.in/yaml.v2 v2.3.0 ) require ( - github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/golang/protobuf v1.3.2 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/hashicorp/go-version v1.2.1 // indirect - github.com/russross/blackfriday/v2 v2.0.1 // indirect - github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/go.sum b/go.sum index 09a7632..58d0610 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,7 @@ code.gitea.io/sdk/gitea v0.14.0 h1:m4J352I3p9+bmJUfS+g0odeQzBY/5OXP91Gv6D4fnJ0= code.gitea.io/sdk/gitea v0.14.0/go.mod h1:89WiyOX1KEcvjP66sRHdu0RafojGo60bT9UqW17VbWs= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= -github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -19,15 +17,15 @@ github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pB github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= -github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +github.com/urfave/cli/v3 v3.0.0-alpha2 h1:JKkuTewMlS2leTQeAcsPGL7WmBVa2uoBLy89As4Jauc= +github.com/urfave/cli/v3 v3.0.0-alpha2/go.mod h1:gHI/xEYplFhOa3Y90xJleh3kqqsSanBj/19hVFxiVZ4= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -- 2.43.5 From 07c0fc1414e7b3b7f508aacdb16b5d238628a769 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Fri, 14 Apr 2023 15:17:23 -0400 Subject: [PATCH 34/42] release tag pipeline --- .gitea/workflows/release-tag.yml | 41 ++++++++++++++++++++++++++++++++ .goreleaser.yaml | 6 ++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/release-tag.yml diff --git a/.gitea/workflows/release-tag.yml b/.gitea/workflows/release-tag.yml new file mode 100644 index 0000000..4ae629b --- /dev/null +++ b/.gitea/workflows/release-tag.yml @@ -0,0 +1,41 @@ +name: goreleaser + +on: + push: + tags: + - '*' + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: git fetch --force --tags + - uses: actions/setup-go@v3 + with: + go-version: '>=1.20.1' + - name: Import GPG key + id: import_gpg + uses: https://github.com/crazy-max/ghaction-import-gpg@v5 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.PASSPHRASE }} + fingerprint: CC64B1DB67ABBEECAB24B6455FC346329753F4B0 + - name: goreleaser + uses: https://github.com/goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser-pro + version: latest + args: release + env: + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} + AWS_REGION: ${{ secrets.AWS_REGION }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + S3_REGION: ${{ secrets.AWS_REGION }} + S3_BUCKET: ${{ secrets.AWS_BUCKET }} + GORELEASER_FORCE_TOKEN: 'gitea' + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 86c179e..5509356 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -54,7 +54,7 @@ builds: flags: - -trimpath ldflags: - - -s -w -X code.gitea.io/changelog/cmd.Version={{ .Version }} + - -s -w -X code.gitea.io/changelog/cmd.Version={{ .Summary }} binary: >- {{ .ProjectName }}- {{- .Version }}- @@ -99,5 +99,9 @@ snapshot: nightly: name_template: "{{ .Branch }}" +gitea_urls: + api: https://gitea.com/api/v1 + download: https://gitea.com + # yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json # vim: set ts=2 sw=2 tw=0 fo=cnqoj -- 2.43.5 From 482c085290212f6e2be5abddfe6798a955d6b940 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 23 Jun 2023 17:20:48 +0000 Subject: [PATCH 35/42] Respect --token argument on github too (#79) Reviewed-on: https://gitea.com/gitea/changelog/pulls/79 Reviewed-by: John Olheiser Reviewed-by: delvh --- service/github.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/service/github.go b/service/github.go index 00894b6..dd145b2 100644 --- a/service/github.go +++ b/service/github.go @@ -22,14 +22,15 @@ type GitHub struct { Token string Repo string Issues bool + client *github.Client } // Generate returns a GitHub changelog func (gh *GitHub) Generate() (string, []Entry, error) { - 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(httpClient()) ctx := context.Background() + gh.initClient(ctx) + + tagURL := fmt.Sprintf("## [%s](https://github.com/%s/releases/tag/%s) - %s", gh.Milestone, gh.Repo, gh.GitTag, time.Now().Format("2006-01-02")) prs := make([]Entry, 0) @@ -42,7 +43,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { p := 1 perPage := 100 for { - result, _, err := client.Search.Issues(ctx, query, &github.SearchOptions{ + result, _, err := gh.client.Search.Issues(ctx, query, &github.SearchOptions{ ListOptions: github.ListOptions{ Page: p, PerPage: perPage, @@ -84,15 +85,15 @@ func (gh *GitHub) Generate() (string, []Entry, error) { // Contributors returns a list of contributors from GitHub func (gh *GitHub) Contributors() (ContributorList, error) { - client := github.NewClient(httpClient()) ctx := context.Background() + gh.initClient(ctx) contributorsMap := make(map[string]bool) query := fmt.Sprintf(`repo:%s is:merged milestone:"%s"`, gh.Repo, gh.Milestone) p := 1 perPage := 100 for { - result, _, err := client.Search.Issues(ctx, query, &github.SearchOptions{ + result, _, err := gh.client.Search.Issues(ctx, query, &github.SearchOptions{ ListOptions: github.ListOptions{ Page: p, PerPage: perPage, @@ -123,14 +124,19 @@ func (gh *GitHub) Contributors() (ContributorList, error) { return contributors, nil } -func httpClient() *http.Client { +func (gh *GitHub) initClient(ctx context.Context) { + token := gh.Token + if envToken, ok := os.LookupEnv("CHANGELOG_GITHUB_TOKEN"); ok && token == "" { + token = envToken + } + cl := http.DefaultClient - if token, ok := os.LookupEnv("CHANGELOG_GITHUB_TOKEN"); ok { - ctx := context.Background() + if token != "" { ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: token}, ) cl = oauth2.NewClient(ctx, ts) } - return cl + + gh.client = github.NewClient(cl) } -- 2.43.5 From 3d93c3a0cdc92eff027f47c19b96efd3092c186d Mon Sep 17 00:00:00 2001 From: jolheiser Date: Thu, 20 Jul 2023 10:08:48 +0000 Subject: [PATCH 36/42] Use issue list API instead of search (#78) This PR changes to using the GH issue list API rather than search, as for some reason the search results started missing several PRs... Reviewed-on: https://gitea.com/gitea/changelog/pulls/78 Co-authored-by: jolheiser Co-committed-by: jolheiser --- service/github.go | 76 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/service/github.go b/service/github.go index dd145b2..c079619 100644 --- a/service/github.go +++ b/service/github.go @@ -6,9 +6,12 @@ package service import ( "context" + "errors" "fmt" "net/http" "os" + "strconv" + "strings" "time" "github.com/google/go-github/v50/github" @@ -25,8 +28,18 @@ type GitHub struct { client *github.Client } +// OwnerRepo splits owner/repo +func (gh *GitHub) OwnerRepo() (string, string) { + parts := strings.Split(gh.Repo, "/") + if len(parts) < 2 { + return parts[0], "" + } + return parts[0], parts[1] +} + // Generate returns a GitHub changelog func (gh *GitHub) Generate() (string, []Entry, error) { + owner, repo := gh.OwnerRepo() ctx := context.Background() gh.initClient(ctx) @@ -34,16 +47,17 @@ func (gh *GitHub) Generate() (string, []Entry, error) { prs := make([]Entry, 0) - state := "merged" - if gh.Issues { - state = "closed" + milestoneNum, err := gh.milestoneNum(ctx) + if err != nil { + return "", nil, err } - query := fmt.Sprintf(`repo:%s is:%s milestone:"%s"`, gh.Repo, state, gh.Milestone) p := 1 perPage := 100 for { - result, _, err := gh.client.Search.Issues(ctx, query, &github.SearchOptions{ + result, _, err := gh.client.Issues.ListByRepo(ctx, owner, repo, &github.IssueListByRepoOptions{ + Milestone: strconv.Itoa(milestoneNum), + State: "closed", ListOptions: github.ListOptions{ Page: p, PerPage: perPage, @@ -56,7 +70,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { isPull := !(gh.Issues) - for _, pr := range result.Issues { + for _, pr := range result { if pr.IsPullRequest() == isPull { p := Entry{ Title: CleanTitle(pr.GetTitle()), @@ -75,7 +89,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { } } - if len(result.Issues) != perPage { + if len(result) != perPage { break } } @@ -86,14 +100,20 @@ func (gh *GitHub) Generate() (string, []Entry, error) { // Contributors returns a list of contributors from GitHub func (gh *GitHub) Contributors() (ContributorList, error) { ctx := context.Background() + owner, repo := gh.OwnerRepo() gh.initClient(ctx) contributorsMap := make(map[string]bool) - query := fmt.Sprintf(`repo:%s is:merged milestone:"%s"`, gh.Repo, gh.Milestone) + milestoneNum, err := gh.milestoneNum(ctx) + if err != nil { + return nil, err + } p := 1 perPage := 100 for { - result, _, err := gh.client.Search.Issues(ctx, query, &github.SearchOptions{ + result, _, err := gh.client.Issues.ListByRepo(ctx, owner, repo, &github.IssueListByRepoOptions{ + Milestone: strconv.Itoa(milestoneNum), + State: "closed", ListOptions: github.ListOptions{ Page: p, PerPage: perPage, @@ -104,11 +124,11 @@ func (gh *GitHub) Contributors() (ContributorList, error) { } p++ - for _, pr := range result.Issues { + for _, pr := range result { contributorsMap[pr.GetUser().GetLogin()] = true } - if len(result.Issues) != perPage { + if len(result) != perPage { break } } @@ -129,7 +149,6 @@ func (gh *GitHub) initClient(ctx context.Context) { if envToken, ok := os.LookupEnv("CHANGELOG_GITHUB_TOKEN"); ok && token == "" { token = envToken } - cl := http.DefaultClient if token != "" { ts := oauth2.StaticTokenSource( @@ -140,3 +159,36 @@ func (gh *GitHub) initClient(ctx context.Context) { gh.client = github.NewClient(cl) } + +func (gh *GitHub) milestoneNum(ctx context.Context) (int, error) { + owner, repo := gh.OwnerRepo() + p := 1 + perPage := 100 + for { + milestones, _, err := gh.client.Issues.ListMilestones(ctx, owner, repo, &github.MilestoneListOptions{ + State: "all", + ListOptions: github.ListOptions{ + Page: p, + PerPage: perPage, + }, + Sort: "due_on", + Direction: "desc", + }) + if err != nil { + return 0, err + } + p++ + + for _, milestone := range milestones { + if strings.EqualFold(milestone.GetTitle(), gh.Milestone) { + return milestone.GetNumber(), nil + } + } + + if len(milestones) != perPage { + break + } + } + + return 0, errors.New("no milestone found") +} -- 2.43.5 From 769323fbd7c2fdd00b74607aabdf2fe10177d224 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 5 Sep 2023 14:35:42 +0000 Subject: [PATCH 37/42] minor updates to readme --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1e9ad83..e0f2cb7 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ A changelog generator for Gitea -[![Build Status](https://drone.gitea.com/api/badges/gitea/changelog/status.svg)](https://drone.gitea.com/gitea/changelog) - ## Purpose This repo is currently part of Gitea. The purpose of it is to generate a changelog when writing release notes. @@ -12,7 +10,7 @@ This tool generates a changelog from PRs based on their milestone and labels. ## Installation -Download a pre-built binary from our [downloads page](https://dl.gitea.io/changelog-tool/) or clone the source and follow the [building instructions](#building). +Download a pre-built binary from our [downloads page](https://dl.gitea.com/changelog-tool/) or clone the source and follow the [building instructions](#building). ## Configuration @@ -45,7 +43,7 @@ Fork -> Patch -> Push -> Pull Request ## Authors * [Maintainers](https://gitea.com/org/gitea/members) -* [Contributors](https://gitea.com/gitea/changelog/commits/branch/master) +* [Contributors](https://gitea.com/gitea/changelog/commits/branch/main) ## License -- 2.43.5 From 91a081912c1d93e8dfa142e0d90671f2b478fa42 Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Tue, 14 Nov 2023 02:08:19 +0000 Subject: [PATCH 38/42] Switch to new label style (#83) Reviewed-on: https://gitea.com/gitea/changelog/pulls/83 Reviewed-by: John Olheiser Reviewed-by: delvh Co-authored-by: Denys Konovalov Co-committed-by: Denys Konovalov --- config/changelog.example.yml | 121 ++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 57 deletions(-) diff --git a/config/changelog.example.yml b/config/changelog.example.yml index d092155..d8b460b 100644 --- a/config/changelog.example.yml +++ b/config/changelog.example.yml @@ -1,57 +1,64 @@ -# The full repository name -repo: go-gitea/gitea - -# Service type (gitea or github) -service: github - -# Base URL for Gitea instance if using gitea service type (optional) -# Default: https://gitea.com -base-url: - -# Changelog groups and which labeled PRs to add to each group -groups: - - - name: BREAKING - labels: - - kind/breaking - - - name: FEATURES - labels: - - kind/feature - - - name: BUGFIXES - labels: - - kind/bug - - - name: ENHANCEMENTS - labels: - - kind/enhancement - - kind/refactor - - kind/ui - - - name: SECURITY - labels: - - kind/security - - - name: TESTING - labels: - - kind/testing - - - name: TRANSLATION - labels: - - kind/translation - - - name: BUILD - labels: - - kind/build - - kind/lint - - - name: DOCS - labels: - - kind/docs - - - name: MISC - default: true - -# regex indicating which labels to skip for the changelog -skip-labels: skip-changelog|backport\/.+ \ No newline at end of file +# The full repository name +repo: go-gitea/gitea + +# Service type (gitea or github) +service: github + +# Base URL for Gitea instance if using gitea service type (optional) +# Default: https://gitea.com +base-url: + +# Changelog groups and which labeled PRs to add to each group +groups: + - + name: BREAKING + labels: + - pr/breaking + - + name: FEATURES + labels: + - type/feature + - + name: API + labels: + - modifies/api + - + name: BUGFIXES + labels: + - type/bug + - + name: ENHANCEMENTS + labels: + - type/enhancement + - type/refactoring + - topic/ui + - topic/ui-interaction + - performance/speed + - + name: SECURITY + labels: + - topic/security + - + name: TESTING + labels: + - type/testing + - + name: TRANSLATION + labels: + - modifies/translation + - + name: BUILD + labels: + - topic/build + - topic/code-linting + - + name: DOCS + labels: + - type/docs + - modifies/docs + - + name: MISC + default: true + +# regex indicating which labels to skip for the changelog +skip-labels: skip-changelog|backport\/.+|type\/dependency-update \ No newline at end of file -- 2.43.5 From 9d720a45a2295f9aa30c649cd788917e31d33d8f Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 27 Mar 2024 20:08:27 +0000 Subject: [PATCH 39/42] Remove `type/dependency-update` (#84) This only removes the `type/dependency-update` label which I recently deleted on GitHub. The file was CRLF and the web editor converted it to LF. I'd say LF is preferred anyways. Reviewed-on: https://gitea.com/gitea/changelog/pulls/84 Reviewed-by: Lunny Xiao Reviewed-by: Denys Konovalov --- config/changelog.example.yml | 128 +++++++++++++++++------------------ 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/config/changelog.example.yml b/config/changelog.example.yml index d8b460b..e4eef9e 100644 --- a/config/changelog.example.yml +++ b/config/changelog.example.yml @@ -1,64 +1,64 @@ -# The full repository name -repo: go-gitea/gitea - -# Service type (gitea or github) -service: github - -# Base URL for Gitea instance if using gitea service type (optional) -# Default: https://gitea.com -base-url: - -# Changelog groups and which labeled PRs to add to each group -groups: - - - name: BREAKING - labels: - - pr/breaking - - - name: FEATURES - labels: - - type/feature - - - name: API - labels: - - modifies/api - - - name: BUGFIXES - labels: - - type/bug - - - name: ENHANCEMENTS - labels: - - type/enhancement - - type/refactoring - - topic/ui - - topic/ui-interaction - - performance/speed - - - name: SECURITY - labels: - - topic/security - - - name: TESTING - labels: - - type/testing - - - name: TRANSLATION - labels: - - modifies/translation - - - name: BUILD - labels: - - topic/build - - topic/code-linting - - - name: DOCS - labels: - - type/docs - - modifies/docs - - - name: MISC - default: true - -# regex indicating which labels to skip for the changelog -skip-labels: skip-changelog|backport\/.+|type\/dependency-update \ No newline at end of file +# The full repository name +repo: go-gitea/gitea + +# Service type (gitea or github) +service: github + +# Base URL for Gitea instance if using gitea service type (optional) +# Default: https://gitea.com +base-url: + +# Changelog groups and which labeled PRs to add to each group +groups: + - + name: BREAKING + labels: + - pr/breaking + - + name: FEATURES + labels: + - type/feature + - + name: API + labels: + - modifies/api + - + name: BUGFIXES + labels: + - type/bug + - + name: ENHANCEMENTS + labels: + - type/enhancement + - type/refactoring + - topic/ui + - topic/ui-interaction + - performance/speed + - + name: SECURITY + labels: + - topic/security + - + name: TESTING + labels: + - type/testing + - + name: TRANSLATION + labels: + - modifies/translation + - + name: BUILD + labels: + - topic/build + - topic/code-linting + - + name: DOCS + labels: + - type/docs + - modifies/docs + - + name: MISC + default: true + +# regex indicating which labels to skip for the changelog +skip-labels: skip-changelog|backport\/.+ \ No newline at end of file -- 2.43.5 From ee1b5532aaf234aeb19fe74e889df1c1aea9c120 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 24 May 2024 05:59:15 +0000 Subject: [PATCH 40/42] Github support rate limit (#85) Reviewed-on: https://gitea.com/gitea/changelog/pulls/85 --- .gitea/workflows/release-nightly.yml | 6 +-- .gitea/workflows/release-tag.yml | 6 +-- .gitea/workflows/test-pr.yml | 6 +-- cmd/generate.go | 4 +- cmd/init.go | 3 +- config/config.go | 4 +- go.mod | 5 +-- go.sum | 9 ++--- service/gitea.go | 3 +- service/github.go | 59 ++++++++++++++++++++++++---- service/github_test.go | 7 +++- service/service.go | 4 +- 12 files changed, 81 insertions(+), 35 deletions(-) diff --git a/.gitea/workflows/release-nightly.yml b/.gitea/workflows/release-nightly.yml index 9304808..3cbb7a8 100644 --- a/.gitea/workflows/release-nightly.yml +++ b/.gitea/workflows/release-nightly.yml @@ -8,13 +8,13 @@ jobs: goreleaser: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - run: git fetch --force --tags - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: - go-version: '>=1.20.1' + go-version-file: 'go.mod' - name: goreleaser uses: https://github.com/goreleaser/goreleaser-action@v4 with: diff --git a/.gitea/workflows/release-tag.yml b/.gitea/workflows/release-tag.yml index 4ae629b..f20d132 100644 --- a/.gitea/workflows/release-tag.yml +++ b/.gitea/workflows/release-tag.yml @@ -9,13 +9,13 @@ jobs: goreleaser: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - run: git fetch --force --tags - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: - go-version: '>=1.20.1' + go-version-file: 'go.mod' - name: Import GPG key id: import_gpg uses: https://github.com/crazy-max/ghaction-import-gpg@v5 diff --git a/.gitea/workflows/test-pr.yml b/.gitea/workflows/test-pr.yml index cda25df..00e7e1b 100644 --- a/.gitea/workflows/test-pr.yml +++ b/.gitea/workflows/test-pr.yml @@ -6,10 +6,10 @@ jobs: check-and-test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: - go-version: '>=1.20.1' + go-version-file: 'go.mod' - name: check-and-test run: | go test -race ./... diff --git a/cmd/generate.go b/cmd/generate.go index 39aff8e..bb4ebbe 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -21,7 +21,7 @@ var Generate = &cli.Command{ Action: runGenerate, } -func runGenerate(_ *cli.Context) error { +func runGenerate(ctx *cli.Context) error { cfg, err := config.New(configPathFlag) if err != nil { return err @@ -32,7 +32,7 @@ func runGenerate(_ *cli.Context) error { return err } - title, prs, err := s.Generate() + title, prs, err := s.Generate(ctx.Context) if err != nil { return err } diff --git a/cmd/init.go b/cmd/init.go index 9aaa3a5..5ecca0b 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -6,7 +6,6 @@ package cmd import ( "fmt" - "io/ioutil" "os" "code.gitea.io/changelog/config" @@ -37,7 +36,7 @@ func runInit(_ *cli.Context) error { return fmt.Errorf("file '%s' already exists", nameFlag) } - if err := ioutil.WriteFile(nameFlag, config.DefaultConfig, os.ModePerm); err != nil { + if err := os.WriteFile(nameFlag, config.DefaultConfig, os.ModePerm); err != nil { return err } diff --git a/config/config.go b/config/config.go index 08a32ae..506cfb8 100644 --- a/config/config.go +++ b/config/config.go @@ -6,7 +6,7 @@ package config import ( _ "embed" - "io/ioutil" + "os" "regexp" "gopkg.in/yaml.v2" @@ -64,7 +64,7 @@ func New(configPath string) (*Config, error) { var err error configContent := DefaultConfig if len(configPath) != 0 { - configContent, err = ioutil.ReadFile(configPath) + configContent, err = os.ReadFile(configPath) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index 689515b..00e3457 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module code.gitea.io/changelog -go 1.18 +go 1.22 require ( code.gitea.io/sdk/gitea v0.14.0 - github.com/google/go-github/v50 v50.0.0 + github.com/google/go-github/v61 v61.0.0 github.com/urfave/cli/v3 v3.0.0-alpha2 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be gopkg.in/yaml.v2 v2.3.0 @@ -17,7 +17,6 @@ require ( github.com/hashicorp/go-version v1.2.1 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect - golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect google.golang.org/appengine v1.6.7 // indirect ) diff --git a/go.sum b/go.sum index 58d0610..931fd86 100644 --- a/go.sum +++ b/go.sum @@ -8,9 +8,10 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-github/v50 v50.0.0 h1:gdO1AeuSZZK4iYWwVbjni7zg8PIQhp7QfmPunr016Jk= -github.com/google/go-github/v50 v50.0.0/go.mod h1:Ev4Tre8QoKiolvbpOSG3FIi4Mlon3S2Nt9W5JYqKiwA= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-github/v61 v61.0.0 h1:VwQCBwhyE9JclCI+22/7mLB1PuU9eowCXKY5pNlu1go= +github.com/google/go-github/v61 v61.0.0/go.mod h1:0WR+KmsWX75G2EbpyGsGmradjo3IiciuI4BmdVCobQY= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= @@ -27,8 +28,6 @@ github.com/urfave/cli/v3 v3.0.0-alpha2/go.mod h1:gHI/xEYplFhOa3Y90xJleh3kqqsSanB github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= diff --git a/service/gitea.go b/service/gitea.go index 2c85808..e8160ea 100644 --- a/service/gitea.go +++ b/service/gitea.go @@ -5,6 +5,7 @@ package service import ( + "context" "fmt" "time" @@ -23,7 +24,7 @@ type Gitea struct { } // Generate returns a Gitea changelog -func (ge *Gitea) Generate() (string, []Entry, error) { +func (ge *Gitea) Generate(_ context.Context) (string, []Entry, error) { client, err := gitea.NewClient(ge.BaseURL, gitea.SetToken(ge.Token)) if err != nil { return "", nil, err diff --git a/service/github.go b/service/github.go index c079619..4f943c5 100644 --- a/service/github.go +++ b/service/github.go @@ -8,13 +8,14 @@ import ( "context" "errors" "fmt" + log "log/slog" "net/http" "os" "strconv" "strings" "time" - "github.com/google/go-github/v50/github" + "github.com/google/go-github/v61/github" "golang.org/x/oauth2" ) @@ -25,7 +26,45 @@ type GitHub struct { Token string Repo string Issues bool + ctx context.Context client *github.Client + rate *github.Rate +} + +func (gh *GitHub) setRate(rate *github.Rate) { + gh.rate = rate +} + +func (gh *GitHub) RefreshRate() error { + rates, _, err := gh.client.RateLimit.Get(gh.ctx) + if err != nil { + // if rate limit is not enabled, ignore it + if strings.Contains(err.Error(), "404") { + gh.setRate(nil) + return nil + } + return err + } + + gh.setRate(rates.GetCore()) + return nil +} + +func (gh *GitHub) waitAndPickClient() { + for gh.rate != nil && gh.rate.Remaining <= 0 { + timer := time.NewTimer(time.Until(gh.rate.Reset.Time)) + select { + case <-gh.ctx.Done(): + timer.Stop() + return + case <-timer.C: + } + + err := gh.RefreshRate() + if err != nil { + log.Error("g.getClient().RateLimit.Get: %s", err) + } + } } // OwnerRepo splits owner/repo @@ -38,12 +77,11 @@ func (gh *GitHub) OwnerRepo() (string, string) { } // Generate returns a GitHub changelog -func (gh *GitHub) Generate() (string, []Entry, error) { +func (gh *GitHub) Generate(ctx context.Context) (string, []Entry, error) { owner, repo := gh.OwnerRepo() - ctx := context.Background() gh.initClient(ctx) - tagURL := fmt.Sprintf("## [%s](https://github.com/%s/releases/tag/%s) - %s", gh.Milestone, gh.Repo, gh.GitTag, time.Now().Format("2006-01-02")) + tagURL := fmt.Sprintf("## [%s](https://github.com/%s/releases/tag/v%s) - %s", gh.Milestone, gh.Repo, gh.GitTag, time.Now().Format("2006-01-02")) prs := make([]Entry, 0) @@ -55,7 +93,8 @@ func (gh *GitHub) Generate() (string, []Entry, error) { p := 1 perPage := 100 for { - result, _, err := gh.client.Issues.ListByRepo(ctx, owner, repo, &github.IssueListByRepoOptions{ + gh.waitAndPickClient() + result, resp, err := gh.client.Issues.ListByRepo(ctx, owner, repo, &github.IssueListByRepoOptions{ Milestone: strconv.Itoa(milestoneNum), State: "closed", ListOptions: github.ListOptions{ @@ -66,6 +105,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) { if err != nil { return "", nil, err } + gh.setRate(&resp.Rate) p++ isPull := !(gh.Issues) @@ -111,7 +151,8 @@ func (gh *GitHub) Contributors() (ContributorList, error) { p := 1 perPage := 100 for { - result, _, err := gh.client.Issues.ListByRepo(ctx, owner, repo, &github.IssueListByRepoOptions{ + gh.waitAndPickClient() + result, resp, err := gh.client.Issues.ListByRepo(ctx, owner, repo, &github.IssueListByRepoOptions{ Milestone: strconv.Itoa(milestoneNum), State: "closed", ListOptions: github.ListOptions{ @@ -122,6 +163,7 @@ func (gh *GitHub) Contributors() (ContributorList, error) { if err != nil { return nil, err } + gh.setRate(&resp.Rate) p++ for _, pr := range result { @@ -158,6 +200,7 @@ func (gh *GitHub) initClient(ctx context.Context) { } gh.client = github.NewClient(cl) + gh.ctx = ctx } func (gh *GitHub) milestoneNum(ctx context.Context) (int, error) { @@ -165,7 +208,8 @@ func (gh *GitHub) milestoneNum(ctx context.Context) (int, error) { p := 1 perPage := 100 for { - milestones, _, err := gh.client.Issues.ListMilestones(ctx, owner, repo, &github.MilestoneListOptions{ + gh.waitAndPickClient() + milestones, resp, err := gh.client.Issues.ListMilestones(ctx, owner, repo, &github.MilestoneListOptions{ State: "all", ListOptions: github.ListOptions{ Page: p, @@ -177,6 +221,7 @@ func (gh *GitHub) milestoneNum(ctx context.Context) (int, error) { if err != nil { return 0, err } + gh.setRate(&resp.Rate) p++ for _, milestone := range milestones { diff --git a/service/github_test.go b/service/github_test.go index 562216d..2cc4f17 100644 --- a/service/github_test.go +++ b/service/github_test.go @@ -4,7 +4,10 @@ package service -import "testing" +import ( + "context" + "testing" +) var gh = &GitHub{ Milestone: "1.1.0", // https://github.com/go-gitea/test_repo/milestone/2?closed=1 @@ -12,7 +15,7 @@ var gh = &GitHub{ } func TestGitHubGenerate(t *testing.T) { - _, entries, err := gh.Generate() + _, entries, err := gh.Generate(context.Background()) if err != nil { t.Log(err) t.FailNow() diff --git a/service/service.go b/service/service.go index 685d5b9..58f29d7 100644 --- a/service/service.go +++ b/service/service.go @@ -5,6 +5,7 @@ package service import ( + "context" "fmt" "strings" "unicode" @@ -48,7 +49,7 @@ func New(serviceType, repo, baseURL, milestone, tag, token string, issues bool) // Service defines how a struct can be a Changelog Service type Service interface { - Generate() (string, []Entry, error) + Generate(ctx context.Context) (string, []Entry, error) Contributors() (ContributorList, error) } @@ -90,7 +91,6 @@ func (cl ContributorList) Swap(i, j int) { // CleanTitle returns the string with spaces trimmed and the first rune title-cased func CleanTitle(s string) string { - s = strings.TrimSpace(s) r := []rune(s) -- 2.43.5 From c71343729044ba7d46c79db5dcb0b5874d2d26ff Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sun, 26 May 2024 21:39:37 +0000 Subject: [PATCH 41/42] Update .goreleaser.yaml --- .goreleaser.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5509356..908be06 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -99,6 +99,8 @@ snapshot: nightly: name_template: "{{ .Branch }}" +force_token: gitea + gitea_urls: api: https://gitea.com/api/v1 download: https://gitea.com -- 2.43.5 From e5f22910df3a577d2de34a312a70809494e0b18a Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sun, 26 May 2024 21:40:53 +0000 Subject: [PATCH 42/42] Update .gitea/workflows/release-nightly.yml --- .gitea/workflows/release-nightly.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/release-nightly.yml b/.gitea/workflows/release-nightly.yml index 3cbb7a8..f521dcc 100644 --- a/.gitea/workflows/release-nightly.yml +++ b/.gitea/workflows/release-nightly.yml @@ -16,7 +16,7 @@ jobs: with: go-version-file: 'go.mod' - name: goreleaser - uses: https://github.com/goreleaser/goreleaser-action@v4 + uses: goreleaser/goreleaser-action@v4 with: distribution: goreleaser-pro version: latest @@ -28,3 +28,4 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} S3_REGION: ${{ secrets.AWS_REGION }} S3_BUCKET: ${{ secrets.AWS_BUCKET }} + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} -- 2.43.5