Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(DRON-124) add ReposRunningStatus #65

Merged
merged 1 commit into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions drone/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions drone/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions drone/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
29 changes: 29 additions & 0 deletions drone/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down