From 8fc63a021da091453d361ecce5de2cd96d0c2648 Mon Sep 17 00:00:00 2001 From: TP Honey Date: Wed, 15 Sep 2021 18:23:27 +0100 Subject: [PATCH] (DRON-124) add Incomplete V2 --- .golangci.yml | 128 +++++++++++++++++++++++++++++++++++++++++++ drone/client.go | 9 +++ drone/client_test.go | 3 +- drone/interface.go | 3 + drone/types.go | 29 ++++++++++ 5 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..f5d788d --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,128 @@ +linters-settings: + dupl: + threshold: 100 + funlen: + lines: 100 + statements: 50 + gci: + local-prefixes: github.com/golangci/golangci-lint + goconst: + min-len: 3 + min-occurrences: 3 + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + disabled-checks: + - dupImport # https://github.com/go-critic/go-critic/issues/845 + - ifElseChain + - octalLiteral + - whyNoLint + - wrapperFunc + gocyclo: + min-complexity: 15 + goimports: + local-prefixes: github.com/golangci/golangci-lint + gomnd: + settings: + mnd: + # don't include the "operation" and "assign" + checks: argument,case,condition,return + govet: + check-shadowing: true + settings: + printf: + funcs: + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + lll: + line-length: 200 + maligned: + suggest-new: true + misspell: + locale: US + nolintlint: + allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) + allow-unused: false # report any unused nolint directives + require-explanation: false # don't require an explanation for nolint directives + require-specific: false # don't require nolint directives to be specific about which linter is being skipped + +linters: + # please, do not use `enable-all`: it's deprecated and will be removed soon. + # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint + disable-all: true + enable: + - bodyclose + - deadcode + - depguard + - dogsled + - errcheck + - exportloopref + - exhaustive + - funlen + - gochecknoinits + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - gomnd + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - noctx + - nolintlint + - revive + - rowserrcheck + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - varcheck + - whitespace + + # don't enable: + # - asciicheck + # - dupl + # - scopelint + # - gochecknoglobals + # - gocognit + # - godot + # - godox + # - goerr113 + # - interfacer + # - maligned + # - nestif + # - prealloc + # - testpackage + # - revive + # - wsl + +issues: + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + - path: _test\.go + linters: + - gomnd + + # https://github.com/go-critic/go-critic/issues/926 + - linters: + - gocritic + text: "unnecessaryDefer:" + +run: + skip-files: + - _gen\.go diff --git a/drone/client.go b/drone/client.go index 6cf0667..22df311 100644 --- a/drone/client.go +++ b/drone/client.go @@ -31,6 +31,7 @@ const ( pathFeed = "%s/api/user/feed" pathRepos = "%s/api/user/repos" pathIncomplete = "%s/api/builds/incomplete" + pathIncompleteV2 = "%s/api/builds/incomplete/v2" pathReposAll = "%s/api/repos" pathRepo = "%s/api/repos/%s/%s" pathRepoMove = "%s/api/repos/%s/%s/move?to=%s" @@ -168,6 +169,14 @@ func (c *client) Incomplete() ([]*Repo, error) { return out, err } +// IncompleteV2 returns a list of builds repos and any stages that are running/pending. +func (c *client) IncompleteV2() ([]*RepoBuildStage, error) { + var out []*RepoBuildStage + uri := fmt.Sprintf(pathIncompleteV2, c.addr) + err := c.get(uri, &out) + return out, err +} + // Repo returns a repository by name. func (c *client) Repo(owner string, name string) (*Repo, error) { out := new(Repo) diff --git a/drone/client_test.go b/drone/client_test.go index b060740..d931e38 100644 --- a/drone/client_test.go +++ b/drone/client_test.go @@ -684,7 +684,6 @@ func TestLogsPurge(t *testing.T) { // // mock server and testdata. // - func mockHandler(w http.ResponseWriter, r *http.Request) { routes := []struct { verb string @@ -886,7 +885,7 @@ func mockHandler(w http.ResponseWriter, r *http.Request) { break } w.WriteHeader(route.code) - w.Write(body) + _, _ = w.Write(body) return } w.WriteHeader(404) diff --git a/drone/interface.go b/drone/interface.go index 461b3dd..d84ae6f 100644 --- a/drone/interface.go +++ b/drone/interface.go @@ -52,6 +52,9 @@ type Client interface { // Incomplete returns a list of incomplete builds. Incomplete() ([]*Repo, error) + // IncompleteV2 returns a list of builds/repos/stages that are running/pending. + IncompleteV2() ([]*RepoBuildStage, error) + // Repo returns a repository by name. Repo(namespace, name string) (*Repo, error) diff --git a/drone/types.go b/drone/types.go index 7f420f7..8da3228 100644 --- a/drone/types.go +++ b/drone/types.go @@ -76,6 +76,35 @@ type ( Build Build `json:"build,omitempty"` } + RepoBuildStage struct { + RepoNamespace string `json:"repo_namespace"` + RepoName string `json:"repo_name"` + RepoSlug string `json:"repo_slug"` + BuildNumber int64 `json:"build_number"` + BuildAuthor string `json:"build_author"` + BuildAuthorName string `json:"build_author_name"` + BuildAuthorEmail string `json:"build_author_email"` + BuildAuthorAvatar string `json:"build_author_avatar"` + BuildSender string `json:"build_sender"` + BuildStarted int64 `json:"build_started"` + BuildFinished int64 `json:"build_finished"` + BuildCreated int64 `json:"build_created"` + BuildUpdated int64 `json:"build_updated"` + StageName string `json:"stage_name"` + StageKind string `json:"stage_kind"` + StageType string `json:"stage_type"` + StageStatus string `json:"stage_status"` + StageMachine string `json:"stage_machine"` + StageOS string `json:"stage_os"` + StageArch string `json:"stage_arch"` + StageVariant string `json:"stage_variant"` + StageKernel string `json:"stage_kernel"` + StageLimit string `json:"stage_limit"` + StageLimitRepo string `json:"stage_limit_repo"` + StageStarted int64 `json:"stage_started"` + StageStopped int64 `json:"stage_stopped"` + } + // RepoPatch defines a repository patch request. RepoPatch struct { Config *string `json:"config_path,omitempty"`