Skip to content

Commit

Permalink
Merge pull request #799 from Trane9991/master
Browse files Browse the repository at this point in the history
replace local `bitbucket/openapi` package with external `reviewdog/go-bitbucket`
  • Loading branch information
haya14busa committed Oct 24, 2020
2 parents 1b98aeb + 019a67b commit a615313
Show file tree
Hide file tree
Showing 22 changed files with 37 additions and 5,478 deletions.
2 changes: 1 addition & 1 deletion .reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runner:
- "%f:%l:%c:%m"
level: warning
staticcheck:
cmd: staticcheck $(go list ./... | grep -v /vendor/ | grep -v /bitbucket/openapi)
cmd: staticcheck $(go list ./... | grep -v /vendor/)
errorformat:
- "%f:%l:%c: %m"
misspell:
Expand Down
2 changes: 1 addition & 1 deletion cmd/reviewdog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (
"github.com/reviewdog/errorformat/fmts"
"github.com/xanzy/go-gitlab"

"github.com/reviewdog/go-bitbucket"
"github.com/reviewdog/reviewdog"
"github.com/reviewdog/reviewdog/cienv"
"github.com/reviewdog/reviewdog/commands"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/parser"
"github.com/reviewdog/reviewdog/project"
bbservice "github.com/reviewdog/reviewdog/service/bitbucket"
bitbucket "github.com/reviewdog/reviewdog/service/bitbucket/openapi"
gerritservice "github.com/reviewdog/reviewdog/service/gerrit"
githubservice "github.com/reviewdog/reviewdog/service/github"
"github.com/reviewdog/reviewdog/service/github/githubutils"
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ require (
github.com/mattn/go-shellwords v1.0.10
github.com/rakyll/statik v0.1.7
github.com/reviewdog/errorformat v0.0.0-20201020160743-a656ed371170
github.com/reviewdog/go-bitbucket v0.0.0-20201024094602-708c3f6a7de0
github.com/vvakame/sdlog v0.0.0-20200409072131-7c0d359efddc
github.com/xanzy/go-gitlab v0.38.2
go.opencensus.io v0.22.5
golang.org/x/build v0.0.0-20200616162219-07bebbe343e9
golang.org/x/net v0.0.0-20201020065357-d65d470038a5 // indirect
golang.org/x/net v0.0.0-20201024042810-be3efd7ff127 // indirect
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
google.golang.org/protobuf v1.25.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ=
github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc=
github.com/reviewdog/errorformat v0.0.0-20201020160743-a656ed371170 h1:mXnYP0Ar2dpAorxqoIERETwelsF8jkOR3BWPU4ByTH4=
github.com/reviewdog/errorformat v0.0.0-20201020160743-a656ed371170/go.mod h1:Akd5vemrJaAHgnEOFrC4yMbEKaOsddwF1LKkfovSFI8=
github.com/reviewdog/go-bitbucket v0.0.0-20201024094602-708c3f6a7de0 h1:XZ60Bp2UqwaJ6fDQExoFVrgs4nIzwBCy9ct6GCj9hH8=
github.com/reviewdog/go-bitbucket v0.0.0-20201024094602-708c3f6a7de0/go.mod h1:5JbWAMFyq9hbISZawRyIe7QTcLaptvCIvmZnYo+1VvA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down Expand Up @@ -322,8 +324,8 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb h1:mUVeFHoDKis5nxCAzoAi7E8Ghb86EXh/RK6wtvJIqRY=
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201020065357-d65d470038a5 h1:KrxvpY64uUzANd9wKWr6ZAsufiii93XnvXaeikyCJ2g=
golang.org/x/net v0.0.0-20201020065357-d65d470038a5/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201024042810-be3efd7ff127 h1:pZPp9+iYUqwYKLjht0SDBbRCRK/9gAXDy7pz5fRDpjo=
golang.org/x/net v0.0.0-20201024042810-be3efd7ff127/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
18 changes: 9 additions & 9 deletions service/bitbucket/annotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"strings"
"sync"

bbapi "github.com/reviewdog/go-bitbucket"
"github.com/reviewdog/reviewdog"
"github.com/reviewdog/reviewdog/proto/rdf"
"github.com/reviewdog/reviewdog/service/bitbucket/openapi"
"google.golang.org/protobuf/proto"
)

Expand All @@ -31,14 +31,14 @@ const (
// https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/commit/%7Bcommit%7D/reports/%7BreportId%7D/annotations#post
// POST /2.0/repositories/{username}/{repo_slug}/commit/{commit}/reports/{reportId}/annotations
type ReportAnnotator struct {
cli *openapi.APIClient
cli *bbapi.APIClient
sha string
owner, repo string

muAnnotations sync.Mutex
// store annotations in map per tool name
// so we can create report per tool
annotations map[string][]openapi.ReportAnnotation
annotations map[string][]bbapi.ReportAnnotation
severityMap map[rdf.Severity]string

// wd is working directory relative to root of repository.
Expand All @@ -47,13 +47,13 @@ type ReportAnnotator struct {
}

// NewReportAnnotator creates new Bitbucket Report Annotator
func NewReportAnnotator(cli *openapi.APIClient, owner, repo, sha string, runners []string) *ReportAnnotator {
func NewReportAnnotator(cli *bbapi.APIClient, owner, repo, sha string, runners []string) *ReportAnnotator {
r := &ReportAnnotator{
cli: cli,
sha: sha,
owner: owner,
repo: repo,
annotations: make(map[string][]openapi.ReportAnnotation, len(runners)),
annotations: make(map[string][]bbapi.ReportAnnotation, len(runners)),
severityMap: map[rdf.Severity]string{
rdf.Severity_INFO: annotationSeverityLow,
rdf.Severity_WARNING: annotationSeverityMedium,
Expand All @@ -68,7 +68,7 @@ func NewReportAnnotator(cli *openapi.APIClient, owner, repo, sha string, runners
if len(runner) == 0 {
continue
}
r.annotations[runner] = []openapi.ReportAnnotation{}
r.annotations[runner] = []bbapi.ReportAnnotation{}
// create Pending report for each tool
_ = r.createOrUpdateReport(context.Background(), reportID(runner, reporter), reportTitle(runner, reporter), reportResultPending)
}
Expand Down Expand Up @@ -142,8 +142,8 @@ func (r *ReportAnnotator) Flush(ctx context.Context) error {
return nil
}

func (r *ReportAnnotator) annotationFromReviewDogComment(c reviewdog.Comment) openapi.ReportAnnotation {
a := openapi.NewReportAnnotation()
func (r *ReportAnnotator) annotationFromReviewDogComment(c reviewdog.Comment) bbapi.ReportAnnotation {
a := bbapi.NewReportAnnotation()

// TODO: allow providing different annotation types in future
a.SetAnnotationType(annotationTypeCodeSmell)
Expand All @@ -164,7 +164,7 @@ func (r *ReportAnnotator) annotationFromReviewDogComment(c reviewdog.Comment) op
}

func (r *ReportAnnotator) createOrUpdateReport(ctx context.Context, id, title, reportStatus string) error {
var report = openapi.NewReport()
var report = bbapi.NewReport()
report.SetTitle(title)
// TODO: different report types?
report.SetReportType(reportTypeBug)
Expand Down
8 changes: 4 additions & 4 deletions service/bitbucket/annotator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"testing"
"time"

bbapi "github.com/reviewdog/go-bitbucket"
"github.com/reviewdog/reviewdog"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/proto/rdf"
"github.com/reviewdog/reviewdog/service/bitbucket/openapi"
)

func TestAnnotator(t *testing.T) {
Expand Down Expand Up @@ -127,15 +127,15 @@ func TestAnnotator(t *testing.T) {
}

if isPostAnnotationsCall {
var req []openapi.ReportAnnotation
var req []bbapi.ReportAnnotation
if err := json.Unmarshal(body, &req); err != nil {
t.Error(err)
w.WriteHeader(http.StatusInternalServerError)
}
// count how many annotations we created
annotations[reportID] += len(req)
} else {
var req openapi.Report
var req bbapi.Report
if err := json.Unmarshal(body, &req); err != nil {
t.Error(err)
w.WriteHeader(http.StatusInternalServerError)
Expand All @@ -147,7 +147,7 @@ func TestAnnotator(t *testing.T) {
}))
defer ts.Close()

client := NewAPIClientWithConfigurations(&http.Client{Timeout: 1 * time.Second}, openapi.ServerConfiguration{URL: ts.URL})
client := NewAPIClientWithConfigurations(&http.Client{Timeout: 1 * time.Second}, bbapi.ServerConfiguration{URL: ts.URL})
bb := NewReportAnnotator(client, username, repo, commit, test.runnersList)
ctx := context.Background()

Expand Down
28 changes: 14 additions & 14 deletions service/bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/url"
"time"

"github.com/reviewdog/reviewdog/service/bitbucket/openapi"
bbapi "github.com/reviewdog/go-bitbucket"
"golang.org/x/oauth2"
)

Expand All @@ -22,7 +22,7 @@ const (
)

// NewAPIClient creates Bitbucket API client
func NewAPIClient(isInPipeline bool) *openapi.APIClient {
func NewAPIClient(isInPipeline bool) *bbapi.APIClient {
httpClient := &http.Client{
Timeout: httpTimeout,
}
Expand All @@ -42,48 +42,48 @@ func NewAPIClient(isInPipeline bool) *openapi.APIClient {

// NewAPIClientWithConfigurations allows to create new Bitbucket API client with
// custom http client or server configurations
func NewAPIClientWithConfigurations(client *http.Client, server openapi.ServerConfiguration) *openapi.APIClient {
config := openapi.NewConfiguration()
func NewAPIClientWithConfigurations(client *http.Client, server bbapi.ServerConfiguration) *bbapi.APIClient {
config := bbapi.NewConfiguration()
if client != nil {
config.HTTPClient = client
} else {
config.HTTPClient = &http.Client{
Timeout: httpTimeout,
}
}
config.Servers = openapi.ServerConfigurations{server}
return openapi.NewAPIClient(config)
config.Servers = bbapi.ServerConfigurations{server}
return bbapi.NewAPIClient(config)

}

// WithBasicAuth adds basic auth credentials to context
func WithBasicAuth(ctx context.Context, username, password string) context.Context {
return context.WithValue(ctx, openapi.ContextBasicAuth,
openapi.BasicAuth{
return context.WithValue(ctx, bbapi.ContextBasicAuth,
bbapi.BasicAuth{
UserName: username,
Password: password,
})
}

// WithAccessToken adds basic auth credentials to context
func WithAccessToken(ctx context.Context, accessToken string) context.Context {
return context.WithValue(ctx, openapi.ContextAccessToken, accessToken)
return context.WithValue(ctx, bbapi.ContextAccessToken, accessToken)
}

// WithOAuth2 adds basic auth credentials to context
func WithOAuth2(ctx context.Context, tokenSource oauth2.TokenSource) context.Context {
return context.WithValue(ctx, openapi.ContextOAuth2, tokenSource)
return context.WithValue(ctx, bbapi.ContextOAuth2, tokenSource)
}

func httpServer() openapi.ServerConfiguration {
return openapi.ServerConfiguration{
func httpServer() bbapi.ServerConfiguration {
return bbapi.ServerConfiguration{
URL: "http://api.bitbucket.org/2.0",
Description: `If if called from Bitbucket Pipelines,
using HTTP API endpoint and AuthProxy`,
}
}
func httpsServer() openapi.ServerConfiguration {
return openapi.ServerConfiguration{
func httpsServer() bbapi.ServerConfiguration {
return bbapi.ServerConfiguration{
URL: "https://api.bitbucket.org/2.0",
Description: `HTTPS API endpoint`,
}
Expand Down
4 changes: 2 additions & 2 deletions service/bitbucket/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"io/ioutil"
"net/http"

"github.com/reviewdog/reviewdog/service/bitbucket/openapi"
bbapi "github.com/reviewdog/go-bitbucket"
)

func checkAPIError(err error, resp *http.Response, expectedCode int) error {
if err != nil {
e, ok := err.(openapi.GenericOpenAPIError)
e, ok := err.(bbapi.GenericOpenAPIError)
if ok {
return fmt.Errorf(`bitbucket API error:
Response error: %s
Expand Down
45 changes: 0 additions & 45 deletions service/bitbucket/openapi/README.md

This file was deleted.

0 comments on commit a615313

Please sign in to comment.