Skip to content

Commit

Permalink
Merge pull request #4 from caarlos0/improvements
Browse files Browse the repository at this point in the history
lots of improvements
  • Loading branch information
caarlos0 authored Apr 17, 2017
2 parents 4c462e8 + c2e2d27 commit 3010453
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 132 deletions.
15 changes: 7 additions & 8 deletions .travis.yml
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
49 changes: 49 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Gopkg.toml
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"
47 changes: 47 additions & 0 deletions Makefile
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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# org-stats [![Build Status](https://travis-ci.org/caarlos0/org-stats.svg?branch=master)](https://travis-ci.org/caarlos0/org-stats) [![Powered By: GoReleaser](https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=flat-square)](https://github.com/goreleaser) [![SayThanks.io](https://img.shields.io/badge/SayThanks.io-%E2%98%BC-1EAEDB.svg?style=flat-square)](https://saythanks.io/to/caarlos0)
# org-stats

[![Release](https://img.shields.io/github/release/caarlos0/org-stats.svg?style=flat-square)](https://github.com/caarlos0/org-stats/releases/latest)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Travis](https://img.shields.io/travis/caarlos0/org-stats.svg?style=flat-square)](https://travis-ci.org/caarlos0/org-stats)
[![Go Report Card](https://goreportcard.com/badge/github.com/caarlos0/org-stats?style=flat-square)](https://goreportcard.com/report/github.com/caarlos0/org-stats)
[![Godoc](https://godoc.org/github.com/caarlos0/org-stats?status.svg&style=flat-square)](http://godoc.org/github.com/caarlos0/org-stats)
[![SayThanks.io](https://img.shields.io/badge/SayThanks.io-%E2%98%BC-1EAEDB.svg?style=flat-square)](https://saythanks.io/to/caarlos0)
[![Powered By: GoReleaser](https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=flat-square)](https://github.com/goreleaser)


Get the contributor stats summary from all repos of any given organization

Expand Down
33 changes: 17 additions & 16 deletions main.go → cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/caarlos0/org-stats/internal/stats"
orgstats "github.com/caarlos0/org-stats"
"github.com/caarlos0/spin"
"github.com/urfave/cli"
)
Expand All @@ -29,44 +29,45 @@ func main() {
},
}
app.Action = func(c *cli.Context) error {
token := c.String("token")
var token = c.String("token")
var org = c.String("org")
if token == "" {
return cli.NewExitError("Missing GitHub API token", 1)
return cli.NewExitError("missing github api token", 1)
}
org := c.String("org")
if org == "" {
return cli.NewExitError("Missing organization name", 1)
return cli.NewExitError("missing organization name", 1)
}
s := spin.New(" \033[36m%s Gathering data for '" + org + "'...\033[m")
s.Set(spin.Spin10)
s.Start()
allStats, err := stats.Gather(token, org)
s.Stop()
var spin = spin.New(" \033[36m%s Gathering data for '" + org + "'...\033[m")
spin.Start()
allStats, err := orgstats.Gather(token, org)
spin.Stop()
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
printHighlights(allStats)
return nil
}
app.Run(os.Args)
if err := app.Run(os.Args); err != nil {
panic(err)
}
}

func printHighlights(s stats.Stats) {
func printHighlights(s orgstats.Stats) {
data := []struct {
stats []stats.StatPair
stats []orgstats.StatPair
trophy string
kind string
}{
{
stats: stats.Sort(s, stats.ExtractCommits),
stats: orgstats.Sort(s, orgstats.ExtractCommits),
trophy: "Commit",
kind: "commits",
}, {
stats: stats.Sort(s, stats.ExtractAdditions),
stats: orgstats.Sort(s, orgstats.ExtractAdditions),
trophy: "Lines Added",
kind: "lines added",
}, {
stats: stats.Sort(s, stats.ExtractDeletions),
stats: orgstats.Sort(s, orgstats.ExtractDeletions),
trophy: "Housekeeper",
kind: "lines removed",
},
Expand Down
38 changes: 0 additions & 38 deletions glide.lock

This file was deleted.

10 changes: 0 additions & 10 deletions glide.yaml

This file was deleted.

6 changes: 5 additions & 1 deletion goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
build:
main: ./cmd/main/main.go
brew:
repo: caarlos0/homebrew-tap
github:
owner: caarlos0
name: homebrew-tap
folder: Formula
fpm:
formats:
Expand Down
28 changes: 10 additions & 18 deletions internal/stats/sort.go → sort.go
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]
}
Loading

0 comments on commit 3010453

Please sign in to comment.