Proof of concept #1

Merged
prskr merged 8 commits from feature/proof-of-concept into main 2023-03-10 10:17:07 +00:00
7 changed files with 68 additions and 11 deletions
Showing only changes of commit 1707692170 - Show all commits

View file

@ -22,7 +22,30 @@ steps:
- name: go-cache - name: go-cache
path: /go path: /go
- name: Lint - name: Lint PR
image: docker.io/golangci/golangci-lint:latest
network_mode: host
environment:
CGO_ENABLED: "0"
GOMEMLIMIT: "1150MiB"
NITTER_BASE_ADDRESS: https://code.icb4dc0.de
NITTER_TOKEN:
from_secret: gitea_token
when:
event:
- pull_request
commands:
- apt-get update && apt-get install -y jq
- mkdir out
- golangci-lint run --out-format json --issues-exit-code 0 --new-from-rev "$(curl https://code.icb4dc0.de/api/v1/repos/prskr/nitter/pulls/1 | jq -r '.base.sha')" > out/results.json
- go run main.go gitea pr --namespace "$${DRONE_REPO_NAMESPACE}" --repo "$${DRONE_REPO_NAME}" --result-file out/results.json --pull-index "$${DRONE_PULL_REQUEST}"
depends_on:
- Setup
volumes:
- name: go-cache
path: /go
- name: Lint repo
image: docker.io/golangci/golangci-lint:latest image: docker.io/golangci/golangci-lint:latest
environment: environment:
CGO_ENABLED: "0" CGO_ENABLED: "0"
@ -30,10 +53,13 @@ steps:
NITTER_BASE_ADDRESS: https://code.icb4dc0.de NITTER_BASE_ADDRESS: https://code.icb4dc0.de
NITTER_TOKEN: NITTER_TOKEN:
from_secret: gitea_token from_secret: gitea_token
when:
event:
- push
- tag
commands: commands:
- mkdir out - mkdir out
- golangci-lint run --out-format json --issues-exit-code 0 > out/results.json - golangci-lint run -v
- if [ -n "$DRONE_PULL_REQUEST}" ]; then go run main.go gitea pr --namespace "$${DRONE_REPO_NAMESPACE}" --repo "$${DRONE_REPO_NAME}" --result-file out/results.json --pull-index "$${DRONE_PULL_REQUEST}"; fi
depends_on: depends_on:
- Setup - Setup
volumes: volumes:

1
.gitignore vendored
View file

@ -12,6 +12,7 @@
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test
mock_*_test.go mock_*_test.go
*.mock.go
# Output of the go coverage tool, specifically when used with LiteIDE # Output of the go coverage tool, specifically when used with LiteIDE
*.out *.out

View file

@ -1,4 +1,4 @@
inpackage: true inpackage: false
with-expecter: true with-expecter: true
testonly: true testonly: false
keeptree: false keeptree: true

2
go.mod
View file

@ -8,6 +8,7 @@ require (
github.com/spf13/cobra v1.6.1 github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.12.0 github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.8.2
) )
require ( require (
@ -30,7 +31,6 @@ require (
github.com/spf13/cast v1.5.0 // indirect github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/subosito/gotenv v1.4.1 // indirect github.com/subosito/gotenv v1.4.1 // indirect
golang.org/x/mod v0.8.0 // indirect golang.org/x/mod v0.8.0 // indirect
golang.org/x/sys v0.5.0 // indirect golang.org/x/sys v0.5.0 // indirect

4
go.sum
View file

@ -191,8 +191,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs= github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

View file

@ -35,7 +35,7 @@ func NewPRNitter(cli PullReviewCreator, cfg *GiteaPRConfig) *prNitter {
} }
} }
//go:generate mockery --name PullReviewCreator //go:generate mockery --name PullReviewCreator --filename pull_review_creator.mock.go
type PullReviewCreator interface { type PullReviewCreator interface {
CreatePullReview(owner, repo string, index int64, opt gitea.CreatePullReviewOptions) (*gitea.PullReview, *gitea.Response, error) CreatePullReview(owner, repo string, index int64, opt gitea.CreatePullReviewOptions) (*gitea.PullReview, *gitea.Response, error)
} }
@ -58,7 +58,7 @@ func (p prNitter) Report(report *report.Data, issues []result.Issue) error {
} }
pullReviewOptions := gitea.CreatePullReviewOptions{ pullReviewOptions := gitea.CreatePullReviewOptions{
State: "comment", State: gitea.ReviewStateComment,
Body: templateBuf.String(), Body: templateBuf.String(),
Comments: make([]gitea.CreatePullReviewComment, 0, len(issues)), Comments: make([]gitea.CreatePullReviewComment, 0, len(issues)),
} }

View file

@ -0,0 +1,30 @@
package gitea_test
import (
"errors"
"testing"
"github.com/golangci/golangci-lint/pkg/report"
"github.com/stretchr/testify/mock"
"code.icb4dc0.de/prskr/nitter/nitters/gitea"
"code.icb4dc0.de/prskr/nitter/nitters/gitea/mocks"
)
func Test_PRNitter_Report_MockCreatorError_Error(t *testing.T) {
expectedError := errors.New("error")
creator := mocks.NewPullReviewCreator(t)
creator.
EXPECT().
CreatePullReview(mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil, nil, expectedError).
Times(1)
p := gitea.NewPRNitter(creator, &gitea.GiteaPRConfig{})
if err := p.Report(new(report.Data), nil); err == nil {
t.Error("expected error bot got none")
} else if !errors.Is(err, expectedError) {
t.Errorf("Error %v was not expected", err)
}
}