-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from caarlos0/improvements
lots of improvements
- Loading branch information
Showing
11 changed files
with
201 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
language: go | ||
go: 1.7.4 | ||
install: | ||
- go get github.com/Masterminds/glide | ||
- glide install | ||
go: 1.8 | ||
install: make setup | ||
script: | ||
- go test -cover `glide nv` | ||
- go run main.go --org getantibody | ||
- make ci | ||
- go run ./cmd/main/main.go --org goreleaser | ||
after_success: | ||
- gem install fpm | ||
- test -n "$TRAVIS_TAG" && curl -sL https://git.io/goreleaser | bash | ||
- go get github.com/mattn/goveralls | ||
- goveralls -coverprofile=coverage.out -service=travis-ci -repotoken="$COVERALLS_TOKEN" | ||
- test -n "$TRAVIS_TAG" && gem install fpm && curl -sL http://git.io/goreleaser | bash | ||
notifications: | ||
email: false |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
[[dependencies]] | ||
name = "github.com/caarlos0/spin" | ||
version = "^1.0.0" | ||
|
||
[[dependencies]] | ||
branch = "master" | ||
name = "github.com/google/go-github" | ||
|
||
[[dependencies]] | ||
name = "github.com/urfave/cli" | ||
version = "^1.19.1" | ||
|
||
[[dependencies]] | ||
branch = "master" | ||
name = "golang.org/x/oauth2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
SOURCE_FILES?=$$(go list ./... | grep -v /vendor/) | ||
TEST_PATTERN?=. | ||
TEST_OPTIONS?= | ||
|
||
setup: ## Install all the build and lint dependencies | ||
go get -u github.com/alecthomas/gometalinter | ||
go get -u github.com/golang/dep/... | ||
go get -u github.com/pierrre/gotestcover | ||
go get -u golang.org/x/tools/cmd/cover | ||
dep ensure | ||
gometalinter --install --update | ||
|
||
test: ## Run all the tests | ||
gotestcover $(TEST_OPTIONS) -covermode=count -coverprofile=coverage.out $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=30s | ||
|
||
cover: test ## RUn all the tests and opens the coverage report | ||
go tool cover -html=coverage.out | ||
|
||
fmt: ## gofmt and goimports all go files | ||
find . -name '*.go' -not -wholename './vendor/*' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done | ||
|
||
lint: ## Run all the linters | ||
gometalinter --vendor --disable-all \ | ||
--enable=deadcode \ | ||
--enable=ineffassign \ | ||
--enable=gosimple \ | ||
--enable=staticcheck \ | ||
--enable=gofmt \ | ||
--enable=goimports \ | ||
--enable=dupl \ | ||
--enable=misspell \ | ||
--enable=errcheck \ | ||
--enable=vet \ | ||
--enable=vetshadow \ | ||
--deadline=10m \ | ||
./... | ||
|
||
ci: lint test ## Run all the tests and code checks | ||
|
||
build: ## Build a beta version | ||
go build -o org-stats ./cmd/main/main.go | ||
|
||
# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html | ||
help: | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
.DEFAULT_GOAL := build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,37 @@ | ||
package stats | ||
package orgstats | ||
|
||
import "sort" | ||
|
||
// Extract is a function that converts a multiple stat into a single stat | ||
type Extract func(st Stat) int | ||
|
||
// ExtractCommits extract the commit section of the given stat | ||
var ExtractCommits = func(st Stat) int { | ||
return st.Commits | ||
} | ||
|
||
// ExtractAdditions extract the adds section of the given stat | ||
var ExtractAdditions = func(st Stat) int { | ||
return st.Additions | ||
} | ||
|
||
// ExtractDeletions extract the rms section of the given stat | ||
var ExtractDeletions = func(st Stat) int { | ||
return st.Deletions | ||
} | ||
|
||
func Sort(s Stats, extract Extract) []StatPair { | ||
var result statPairList | ||
for key, value := range s.Stats { | ||
var result []StatPair | ||
for key, value := range s { | ||
result = append(result, StatPair{Key: key, Value: extract(value)}) | ||
} | ||
sort.Sort(sort.Reverse(result)) | ||
sort.Slice(result, func(i int, j int) bool { | ||
return result[i].Value > result[j].Value | ||
}) | ||
return result | ||
} | ||
|
||
type StatPair struct { | ||
Key string | ||
Value int | ||
} | ||
|
||
type statPairList []StatPair | ||
|
||
func (b statPairList) Len() int { | ||
return len(b) | ||
} | ||
|
||
func (b statPairList) Less(i, j int) bool { | ||
return b[i].Value < b[j].Value | ||
} | ||
|
||
func (b statPairList) Swap(i, j int) { | ||
b[i], b[j] = b[j], b[i] | ||
} |
Oops, something went wrong.