Changelog Overhaul 2 #19

Merged
zeripath merged 25 commits from jolheiser/changelog:gitea-sdk into master 2020-01-24 16:30:19 +00:00
3 changed files with 28 additions and 84 deletions
Showing only changes of commit 9797e1495d - Show all commits

6
go.mod
View File

@ -3,14 +3,10 @@ module code.gitea.io/changelog
go 1.13
require (
gitea.com/jolheiser/gitea-sdk v0.0.1
github.com/antihax/optional v1.0.0
code.gitea.io/sdk/gitea v0.0.0-20200116035226-b24cfd841cda
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-querystring v1.0.0 // indirect
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
)

36
go.sum
View File

@ -1,17 +1,11 @@
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
gitea.com/jolheiser/gitea-sdk v0.0.1 h1:pOUXKgvM4HIoVp6YbZ/jgF4094h70AoLBT6oaSiTRKk=
gitea.com/jolheiser/gitea-sdk v0.0.1/go.mod h1:c+DLe4/JxFQw5j1/7g0r2P5ehFwcALONUA/gXy/kBU0=
code.gitea.io/sdk/gitea v0.0.0-20200116035226-b24cfd841cda h1:J+qDCjmjcewNcPNfHIex5z726cgv/URXK0MnXHTIo1U=
code.gitea.io/sdk/gitea v0.0.0-20200116035226-b24cfd841cda/go.mod h1:SXOCD/+QP5txLJQ2bPkgHGSQs1YQ4s1ep1ZpI6ItO4A=
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 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
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/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
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/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/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/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/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=
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/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -5,17 +5,13 @@
package service
import (
"context"
"fmt"
"sort"
"strings"
"time"
"code.gitea.io/changelog/config"
"github.com/antihax/optional"
"gitea.com/jolheiser/gitea-sdk"
"code.gitea.io/sdk/gitea"
)
// Gitea defines a Gitea service
@ -25,18 +21,7 @@ type Gitea struct{}
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"))
client := gitea.NewAPIClient(&gitea.Configuration{
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()
}
client := gitea.NewClient(config.Cfg.BaseURL, Token)
prs := make([]PullRequest, 0)
@ -44,7 +29,7 @@ func (ge Gitea) Generate() (string, []PullRequest, error) {
owner := repoOwner[0]
repo := repoOwner[1]
milestoneID, err := getMilestoneID(client, ctx, owner, repo)
milestoneID, err := getMilestoneID(client, owner, repo)
if err != nil {
return "", nil, err
}
@ -52,10 +37,10 @@ func (ge Gitea) Generate() (string, []PullRequest, error) {
p := 1
perPage := 100
Review

can you write the reason instead of linking to source code?

can you write the reason instead of linking to source code?
Review

Done.

Done.
for {
results, _, err := client.RepositoryApi.RepoListPullRequests(ctx, owner, repo, &gitea.RepoListPullRequestsOpts{
Page: optional.NewInt32(int32(p)),
State: optional.NewString("closed"),
Milestone: optional.NewInt64(milestoneID),
results, err := client.ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
Page: p,
State: "closed",
Milestone: milestoneID,
})
if err != nil {
return "", nil, err
@ -63,10 +48,10 @@ func (ge Gitea) Generate() (string, []PullRequest, error) {
p++
for _, pr := range results {
if pr.Merged {
if pr != nil && pr.HasMerged {
p := PullRequest{
Title: pr.Title,
Index: pr.Number,
Index: pr.Index,
}
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
func (ge Gitea) Contributors() ([]string, error) {
client := gitea.NewAPIClient(&gitea.Configuration{
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()
}
client := gitea.NewClient(config.Cfg.BaseURL, Token)
contributorsMap := make(map[string]bool)
repoOwner := strings.Split(config.Cfg.Repo, "/")
owner := repoOwner[0]
repo := repoOwner[1]
milestoneID, err := getMilestoneID(client, ctx, owner, repo)
milestoneID, err := getMilestoneID(client, owner, repo)
if err != nil {
return nil, err
}
@ -117,10 +91,10 @@ func (ge Gitea) Contributors() ([]string, error) {
p := 1
perPage := 100
for {
results, _, err := client.RepositoryApi.RepoListPullRequests(ctx, owner, repo, &gitea.RepoListPullRequestsOpts{
Page: optional.NewInt32(int32(p)),
State: optional.NewString("closed"),
Milestone: optional.NewInt64(milestoneID),
results, err := client.ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
Page: p,
State: "closed",
Milestone: milestoneID,
})
if err != nil {
return nil, err
@ -128,11 +102,9 @@ func (ge Gitea) Contributors() ([]string, error) {
p++
for _, pr := range results {
if !pr.Merged {
continue
if pr != nil && pr.HasMerged {
contributorsMap[pr.Poster.UserName] = true
}
contributorsMap[pr.User.Login] = true
}
if len(results) != perPage {
@ -154,17 +126,15 @@ func (ge Gitea) BaseURL() string {
return config.Cfg.BaseURL
}
func getMilestoneID(client *gitea.APIClient, ctx context.Context, owner, repo string) (int64, error) {
milestones, _, err := client.IssueApi.IssueGetMilestonesList(ctx, owner, repo, &gitea.IssueGetMilestonesListOpts{
State: optional.NewString("all"),
})
func getMilestoneID(client *gitea.Client, owner, repo string) (int64, error) {
milestones, err := client.ListRepoMilestones(owner, repo)
if err != nil {
return 0, err
}
for _, ms := range milestones {
if ms.Title == Milestone {
return ms.Id, nil
return ms.ID, nil
}
}