Skip to content

Commit

Permalink
Use .gometalinter.json file for config (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps authored Apr 11, 2018
1 parent 8c40b7d commit 33e9f62
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
24 changes: 24 additions & 0 deletions .gometalinter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"Enable": [
"deadcode",
"errcheck",
"goconst",
"gofmt",
"goimports",
"ineffassign",
"interfacer",
"maligned",
"megacheck",
"misspell",
"structcheck",
"testify",
"unparam",
"varcheck",
"vet"
],
"Exclude": [
"vendor"
],
"Deadline": "10m",
"WarnUnmatchedDirective": true
}
12 changes: 1 addition & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,7 @@ fmt: ## goimports all go files

.PHONY: lint
lint: ## Run all the linters
gometalinter --exclude=vendor --exclude=/go/src --disable-all \
--enable=deadcode \
--enable=ineffassign \
--enable=gofmt \
--enable=goimports \
--enable=misspell \
--enable=errcheck \
--enable=vet \
--enable=megacheck \
--deadline=10m \
$(GOPACKAGES)
gometalinter

.PHONY: ci
ci: lint ## Run all code checks and tests with coverage reporting
Expand Down
28 changes: 15 additions & 13 deletions codeship.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@ type Response struct {
Links
}

var (
urlRegex = regexp.MustCompile(`\s*<(.+)>`)
relRegex = regexp.MustCompile(`\s*rel="(\w+)"`)
)

func newResponse(r *http.Response) Response {
response := Response{Response: r}

urlRegex := regexp.MustCompile(`\s*<(.+)>`)
relRegex := regexp.MustCompile(`\s*rel="(\w+)"`)

if linkText := r.Header.Get("Link"); linkText != "" {
linkMap := make(map[string]string)

// one chunk: <url>; rel="foo"
for _, chunk := range strings.Split(linkText, ",") {

pieces := strings.Split(chunk, ";")
urlMatch := urlRegex.FindStringSubmatch(pieces[0])
relMatch := relRegex.FindStringSubmatch(pieces[1])
Expand Down Expand Up @@ -226,9 +227,12 @@ func (c *Client) do(req *http.Request) ([]byte, Response, error) {
return nil, response, errors.Wrap(err, "could not read response body")
}

switch resp.StatusCode {
case http.StatusOK, http.StatusCreated, http.StatusAccepted:
break
code := resp.StatusCode
if code < 400 {
return body, response, nil
}

switch code {
case http.StatusBadRequest:
var e ErrBadRequest
if err = json.Unmarshal(body, &e); err != nil {
Expand All @@ -245,14 +249,12 @@ func (c *Client) do(req *http.Request) ([]byte, Response, error) {
return nil, response, ErrUnauthorized("invalid credentials")
case http.StatusForbidden, http.StatusTooManyRequests:
return nil, response, ErrRateLimitExceeded
default:
if len(body) > 0 {
return nil, response, fmt.Errorf("HTTP status: %d; content %q", resp.StatusCode, string(body))
}
return nil, response, fmt.Errorf("HTTP status: %d", resp.StatusCode)
}

return body, response, nil
if len(body) > 0 {
return nil, response, fmt.Errorf("HTTP status: %d; content %q", resp.StatusCode, string(body))
}
return nil, response, fmt.Errorf("HTTP status: %d", resp.StatusCode)
}

// cloneHeader returns a shallow copy of the header.
Expand Down

0 comments on commit 33e9f62

Please sign in to comment.