Skip to content

Commit

Permalink
init commit : statistics analysis of the numbers of merged/LGTM'ed/No…
Browse files Browse the repository at this point in the history
…nLGTM'ed(open) PRs in specified repos for specified user(s)
  • Loading branch information
bruceauyeung committed Dec 19, 2016
1 parent 810b40b commit 2abffd7
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 139 deletions.
44 changes: 21 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
# github-stat
# github-contrib-stats

tutorial for myself to write in golang and to use [go-github](https://github.com/google/go-github)
this repository is originally forked from https://github.com/yshnb/github-stat, this repo does different jobs.
this repo does statistics analysis of the numbers of merged/LGTM'ed/NonLGTM'ed(open) PRs in specified repos for specified user(s)

## Usage

1. `git clone https://github.com/yshnb/github-stat.git`
2. `cd ./github-stat`
3. `cp config.json.dist config.json`
4. fill in valid `accessToken` generated in Github
1. `go get -u github.com/google/go-github/github`
2. `go get -u github.com/mgutz/ansi`
3. `go get -u golang.org/x/oauth2`
4. `go get -u github.com/olekukonko/tablewriter`
5. `git clone https://github.com/yshnb/github-stat.git`
6. `cd ./github-stat`
7. `cp config.toml.dist config.toml`
8. fill in valid `accessToken` generated from https://github.com/settings/tokens
9. fill in other fields.

After, you can run the below command
```
$ go run main.go --metrics=star google/go-github
target repository: google/go-github
metrics: star
star: 1079
$ go run main.go
......
+--------------+--------+---------+------------+
| NAME | MERGED | LGTM'ED | NONLGTM'ED |
+--------------+--------+---------+------------+
| bruceauyeung | 10 | 0 | 6 |
| tanshanshan | 8 | 0 | 6 |
+--------------+--------+---------+------------+
```
like this.

## Available metrics

For now, it can only get the numbers of github star in each repository.

My plan ....

- issue
- pull_requests (open/closed)
- code changes(additions/deletions)
- etc.

like this.
3 changes: 0 additions & 3 deletions config.json.dist

This file was deleted.

7 changes: 7 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
statBeginTime = 2016-10-01T00:00:00
accessToken = "0161c6ec49fb95d2d04550c72965dd55921bb775"
users = ["bruceauyeung","tanshanshan"]
repos = ["kubernetes/*"]
metrics = "pr"


7 changes: 7 additions & 0 deletions config.toml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
statBeginTime = 2016-10-01T00:00:00
accessToken = "personal access token"
users = ["bruceauyeung","tanshanshan"]
repos = ["kubernetes/*"]
metrics = "pr"


2 changes: 1 addition & 1 deletion githubstat/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (t *tokenSource) Token() (*oauth2.Token, error) {
func (c *ProxyClient) getClient() *github.Client {
if nil == c.client {
ts := &tokenSource{
&oauth2.Token{AccessToken: config.AccessToken},
&oauth2.Token{AccessToken: Config.AccessToken},
}

tc := oauth2.NewClient(oauth2.NoContext, ts)
Expand Down
20 changes: 11 additions & 9 deletions githubstat/load.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package githubstat

import (
"encoding/json"
"io/ioutil"
"time"

"github.com/BurntSushi/toml"
)

type Load interface {
}

var config Config
var Config Configuration

type Config struct {
AccessToken string
OrgName string
type Configuration struct {
StatBeginTime time.Time
AccessToken string
Users []string
Repos []string
Metrics string
}

// read config file
var _ = func() int {
file, err := ioutil.ReadFile("./config.json")
if err != nil {
if _, err := toml.DecodeFile("./config.toml", &Config); err != nil {
panic(err)
}
json.Unmarshal(file, &config)
return 0
}()
18 changes: 8 additions & 10 deletions githubstat/metrics.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package githubstat

import (
"fmt"

"github.com/mgutz/ansi"
)
import "fmt"

type Metrics interface {
GetMetrics()
Show()
}

type MetricsRequest interface {
Expand All @@ -19,21 +15,23 @@ type MetricsRequest interface {

// metrics parameters
type MetricsParameters struct {
OrgName *string
Repos []*RepoParameters
Dimension *string
}
type RepoParameters struct {
OwnerName *string
RepoName *string
}

type DefaultMetrics struct{}

type DefaultMetricsRequest struct{}

func (m *DefaultMetrics) GetMetrics() {
func (m *DefaultMetrics) Show() {
// void
}

func (m *DefaultMetricsRequest) express() {
fmt.Println(ansi.Color("you must select available metrics at least one.", "yellow"))
fmt.Println("you must select available metrics at least one.")
}

func (m *DefaultMetricsRequest) validate() bool {
Expand Down
12 changes: 4 additions & 8 deletions githubstat/metrics_issue.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
package githubstat

import (
"fmt"

"github.com/mgutz/ansi"
)
import "fmt"

type IssueMetrics struct {
issue int
}

func (m *IssueMetrics) GetMetrics() {
fmt.Printf(ansi.Color("this metrics has not been implemented yet.", "red"))
func (m *IssueMetrics) Show() {
fmt.Printf("this metrics has not been implemented yet.")
}

type IssueMetricsRequest struct {
param *MetricsParameters
}

func (m *IssueMetricsRequest) express() {
fmt.Printf("target repository: %s/%s\n", *m.param.OwnerName, *m.param.RepoName)
//fmt.Printf("target repository: %s/%s\n", *m.param.OwnerName, *m.param.RepoName)
fmt.Println("metrics: issue count")
}

Expand Down
Loading

0 comments on commit 2abffd7

Please sign in to comment.