Changelog Overhaul 2 #19
6
go.mod
6
go.mod
@ -3,14 +3,10 @@ module code.gitea.io/changelog
|
|||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.com/jolheiser/gitea-sdk v0.0.1
|
code.gitea.io/sdk/gitea v0.0.0-20200116035226-b24cfd841cda
|
||||||
github.com/antihax/optional v1.0.0
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||||
github.com/golang/protobuf v1.3.2 // indirect
|
|
||||||
github.com/google/go-github v17.0.0+incompatible
|
github.com/google/go-github v17.0.0+incompatible
|
||||||
github.com/google/go-querystring v1.0.0 // indirect
|
github.com/google/go-querystring v1.0.0 // indirect
|
||||||
github.com/urfave/cli/v2 v2.1.1
|
github.com/urfave/cli/v2 v2.1.1
|
||||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
|
|
||||||
google.golang.org/appengine v1.6.5 // indirect
|
|
||||||
gopkg.in/yaml.v2 v2.2.7
|
gopkg.in/yaml.v2 v2.2.7
|
||||||
)
|
)
|
||||||
|
36
go.sum
36
go.sum
@ -1,17 +1,11 @@
|
|||||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
code.gitea.io/sdk/gitea v0.0.0-20200116035226-b24cfd841cda h1:J+qDCjmjcewNcPNfHIex5z726cgv/URXK0MnXHTIo1U=
|
||||||
gitea.com/jolheiser/gitea-sdk v0.0.1 h1:pOUXKgvM4HIoVp6YbZ/jgF4094h70AoLBT6oaSiTRKk=
|
code.gitea.io/sdk/gitea v0.0.0-20200116035226-b24cfd841cda/go.mod h1:SXOCD/+QP5txLJQ2bPkgHGSQs1YQ4s1ep1ZpI6ItO4A=
|
||||||
gitea.com/jolheiser/gitea-sdk v0.0.1/go.mod h1:c+DLe4/JxFQw5j1/7g0r2P5ehFwcALONUA/gXy/kBU0=
|
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg=
|
|
||||||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
|
||||||
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-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 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.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
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 v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
|
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/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
||||||
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
|
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
|
||||||
@ -22,27 +16,11 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0
|
|||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
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 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
|
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 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k=
|
||||||
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg=
|
|
||||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
|
||||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8=
|
|
||||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
|
||||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
|
|
||||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
|
|
||||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
|
||||||
google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM=
|
|
||||||
google.golang.org/appengine v1.6.5/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 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
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.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
@ -5,17 +5,13 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/changelog/config"
|
"code.gitea.io/changelog/config"
|
||||||
|
"code.gitea.io/sdk/gitea"
|
||||||
"github.com/antihax/optional"
|
|
||||||
|
|
||||||
"gitea.com/jolheiser/gitea-sdk"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Gitea defines a Gitea service
|
// Gitea defines a Gitea service
|
||||||
@ -25,18 +21,7 @@ type Gitea struct{}
|
|||||||
func (ge Gitea) Generate() (string, []PullRequest, error) {
|
func (ge Gitea) Generate() (string, []PullRequest, error) {
|
||||||
tagURL := fmt.Sprintf("## [%s](%s/%s/src/tag/v%s) - %s", Milestone, config.Cfg.BaseURL, config.Cfg.Repo, Milestone, time.Now().Format("2006-01-02"))
|
tagURL := fmt.Sprintf("## [%s](%s/%s/src/tag/v%s) - %s", Milestone, config.Cfg.BaseURL, config.Cfg.Repo, Milestone, time.Now().Format("2006-01-02"))
|
||||||
|
|
||||||
client := gitea.NewAPIClient(&gitea.Configuration{
|
client := gitea.NewClient(config.Cfg.BaseURL, Token)
|
||||||
BasePath: config.Cfg.BaseURL + "/api/v1",
|
|
||||||
DefaultHeader: make(map[string]string),
|
|
||||||
UserAgent: "Gitea-Changelog/1.0.0/go",
|
|
||||||
})
|
|
||||||
|
|
||||||
var ctx context.Context
|
|
||||||
if len(Token) > 0 {
|
|
||||||
ctx = context.WithValue(context.Background(), gitea.ContextAccessToken, Token)
|
|
||||||
} else {
|
|
||||||
ctx = context.Background()
|
|
||||||
}
|
|
||||||
|
|
||||||
prs := make([]PullRequest, 0)
|
prs := make([]PullRequest, 0)
|
||||||
|
|
||||||
@ -44,7 +29,7 @@ func (ge Gitea) Generate() (string, []PullRequest, error) {
|
|||||||
owner := repoOwner[0]
|
owner := repoOwner[0]
|
||||||
repo := repoOwner[1]
|
repo := repoOwner[1]
|
||||||
|
|
||||||
milestoneID, err := getMilestoneID(client, ctx, owner, repo)
|
milestoneID, err := getMilestoneID(client, owner, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
@ -52,10 +37,10 @@ func (ge Gitea) Generate() (string, []PullRequest, error) {
|
|||||||
p := 1
|
p := 1
|
||||||
perPage := 100
|
perPage := 100
|
||||||
|
|||||||
for {
|
for {
|
||||||
results, _, err := client.RepositoryApi.RepoListPullRequests(ctx, owner, repo, &gitea.RepoListPullRequestsOpts{
|
results, err := client.ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
|
||||||
Page: optional.NewInt32(int32(p)),
|
Page: p,
|
||||||
State: optional.NewString("closed"),
|
State: "closed",
|
||||||
Milestone: optional.NewInt64(milestoneID),
|
Milestone: milestoneID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
@ -63,10 +48,10 @@ func (ge Gitea) Generate() (string, []PullRequest, error) {
|
|||||||
p++
|
p++
|
||||||
|
|
||||||
for _, pr := range results {
|
for _, pr := range results {
|
||||||
if pr.Merged {
|
if pr != nil && pr.HasMerged {
|
||||||
p := PullRequest{
|
p := PullRequest{
|
||||||
Title: pr.Title,
|
Title: pr.Title,
|
||||||
Index: pr.Number,
|
Index: pr.Index,
|
||||||
}
|
}
|
||||||
|
|
||||||
labels := make([]Label, len(pr.Labels))
|
labels := make([]Label, len(pr.Labels))
|
||||||
@ -91,25 +76,14 @@ func (ge Gitea) Generate() (string, []PullRequest, error) {
|
|||||||
|
|
||||||
// Contributors returns a list of contributors from Gitea
|
// Contributors returns a list of contributors from Gitea
|
||||||
func (ge Gitea) Contributors() ([]string, error) {
|
func (ge Gitea) Contributors() ([]string, error) {
|
||||||
client := gitea.NewAPIClient(&gitea.Configuration{
|
client := gitea.NewClient(config.Cfg.BaseURL, Token)
|
||||||
BasePath: config.Cfg.BaseURL + "/api/v1",
|
|
||||||
DefaultHeader: make(map[string]string),
|
|
||||||
UserAgent: "Gitea-Changelog/1.0.0/go",
|
|
||||||
})
|
|
||||||
|
|
||||||
var ctx context.Context
|
|
||||||
if len(Token) > 0 {
|
|
||||||
ctx = context.WithValue(context.Background(), gitea.ContextAccessToken, Token)
|
|
||||||
} else {
|
|
||||||
ctx = context.Background()
|
|
||||||
}
|
|
||||||
|
|
||||||
contributorsMap := make(map[string]bool)
|
contributorsMap := make(map[string]bool)
|
||||||
repoOwner := strings.Split(config.Cfg.Repo, "/")
|
repoOwner := strings.Split(config.Cfg.Repo, "/")
|
||||||
owner := repoOwner[0]
|
owner := repoOwner[0]
|
||||||
repo := repoOwner[1]
|
repo := repoOwner[1]
|
||||||
|
|
||||||
milestoneID, err := getMilestoneID(client, ctx, owner, repo)
|
milestoneID, err := getMilestoneID(client, owner, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -117,10 +91,10 @@ func (ge Gitea) Contributors() ([]string, error) {
|
|||||||
p := 1
|
p := 1
|
||||||
perPage := 100
|
perPage := 100
|
||||||
for {
|
for {
|
||||||
results, _, err := client.RepositoryApi.RepoListPullRequests(ctx, owner, repo, &gitea.RepoListPullRequestsOpts{
|
results, err := client.ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
|
||||||
Page: optional.NewInt32(int32(p)),
|
Page: p,
|
||||||
State: optional.NewString("closed"),
|
State: "closed",
|
||||||
Milestone: optional.NewInt64(milestoneID),
|
Milestone: milestoneID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -128,11 +102,9 @@ func (ge Gitea) Contributors() ([]string, error) {
|
|||||||
p++
|
p++
|
||||||
|
|
||||||
for _, pr := range results {
|
for _, pr := range results {
|
||||||
if !pr.Merged {
|
if pr != nil && pr.HasMerged {
|
||||||
continue
|
contributorsMap[pr.Poster.UserName] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
contributorsMap[pr.User.Login] = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(results) != perPage {
|
if len(results) != perPage {
|
||||||
@ -154,17 +126,15 @@ func (ge Gitea) BaseURL() string {
|
|||||||
return config.Cfg.BaseURL
|
return config.Cfg.BaseURL
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMilestoneID(client *gitea.APIClient, ctx context.Context, owner, repo string) (int64, error) {
|
func getMilestoneID(client *gitea.Client, owner, repo string) (int64, error) {
|
||||||
milestones, _, err := client.IssueApi.IssueGetMilestonesList(ctx, owner, repo, &gitea.IssueGetMilestonesListOpts{
|
milestones, err := client.ListRepoMilestones(owner, repo)
|
||||||
State: optional.NewString("all"),
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ms := range milestones {
|
for _, ms := range milestones {
|
||||||
if ms.Title == Milestone {
|
if ms.Title == Milestone {
|
||||||
return ms.Id, nil
|
return ms.ID, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user
can you write the reason instead of linking to source code?
Done.