Skip to content

Commit

Permalink
add expand mode and minor README fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nimakaviani committed Nov 13, 2020
1 parent 5b196d9 commit 7fe912f
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 63 deletions.
46 changes: 37 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,47 +51,75 @@ Use "github-contrib [command] --help" for more information about a command.

## Output

Check the list of issues or PRs for insights
Get higher level insights from the list of contributors

```
❯ ./github-contrib --repo kubernetes/kubernetes --expand=false
Analyzig the top 30 contributors on kubernetes/kubernetes
30 / 30 [==================] 100.00% 18s
+----------------+-------+------------+
| ORG | COUNT | PERCENTAGE |
+----------------+-------+------------+
| microsoft.com | 1 | 3.3% |
+----------------+-------+------------+
| redhat.com | 4 | 13.3% |
+----------------+-------+------------+
| google.com | 15 | 50.0% |
+----------------+-------+------------+
| liggitt.net | 1 | 3.3% |
+----------------+-------+------------+
| bedafamily.com | 1 | 3.3% |
+----------------+-------+------------+
| gmail.com | 6 | 20.0% |
+----------------+-------+------------+
```

Or get an extended view when checking contributors, issues, or PRs.

```
❯ ./github-contrib issues --repo kubernetes/kubernetes
10 / 10 [=========================================================================================================================] 100.00% 10s
+---------------+----------------+----------------------------+-----------------------------------------------------------------+-------------+-------+
| ORG | GITHUBID | EMAIL | ISSUE / PR | ASSOCIATION | STATE |
+---------------+----------------+----------------------------+-----------------------------------------------------------------+-------------+-------+
| google.com | adtac | adtac@google.com | Issue(96527) : promote API priority | MEMBER | open |
| google.com | adtac | axxxc@google.com | Issue(96527) : promote API priority | MEMBER | open |
| | | | and fairness types and APIs to beta | | |
| | | | https://api.github.com/repos/kubernetes/kubernetes/issues/96527 | | |
+ +----------------+----------------------------+-----------------------------------------------------------------+ + +
| | apelisse | apelisse@google.com | Issue(96480) : Add defaults openapi | | |
| | apelisse | axxxxxxx@google.com | Issue(96480) : Add defaults openapi | | |
| | | | https://api.github.com/repos/kubernetes/kubernetes/issues/96480 | | |
+ +----------------+----------------------------+-----------------------------------------------------------------+ + +
| | caesarxuchao | xuchao@google.com | Issue(96549) : update golang.org/x/net and golang.org/x/sys | | |
| | caesarxuchao | xxxxxx@google.com | Issue(96549) : update golang.org/x/net and golang.org/x/sys | | |
| | | | https://api.github.com/repos/kubernetes/kubernetes/issues/96549 | | |
+---------------+----------------+----------------------------+-----------------------------------------------------------------+ + +
| live.com | Jefftree | jeffrey.ying86@live.com | Issue(96317) : Integrate defaults marker to defaulter-gen | | |
| live.com | Jefftree | jxxxxxxxxxxxxx@live.com | Issue(96317) : Integrate defaults marker to defaulter-gen | | |
| | | | https://api.github.com/repos/kubernetes/kubernetes/issues/96317 | | |
+---------------+----------------+----------------------------+-----------------------------------------------------------------+ + +
| microsoft.com | andyzhangx | xiazhang@microsoft.com | Issue(96293) : azure file migration go beta in 1.20 | | |
| microsoft.com | andyzhangx | xxxxxxxx@microsoft.com | Issue(96293) : azure file migration go beta in 1.20 | | |
| | | | https://api.github.com/repos/kubernetes/kubernetes/issues/96293 | | |
+ + + +-----------------------------------------------------------------+ + +
| | | | Issue(96546) : Automated cherry pick of #96355: fix pull | | |
| | | | image error from multiple ACRs using azure managed | | |
| | | | https://api.github.com/repos/kubernetes/kubernetes/issues/96546 | | |
+---------------+----------------+----------------------------+-----------------------------------------------------------------+-------------+ +
| redhat.com | smarterclayton | ccoleman@redhat.com | Issue(96375) : api: Allow MaxSurge to | CONTRIBUTOR | |
| redhat.com | smarterclayton | cxxxxxxx@redhat.com | Issue(96375) : api: Allow MaxSurge to | CONTRIBUTOR | |
| | | | be set on DaemonSets during update | | |
| | | | https://api.github.com/repos/kubernetes/kubernetes/issues/96375 | | |
+---------------+----------------+----------------------------+-----------------------------------------------------------------+-------------+ +
| uservers.net | puerco | adolfo.garcia@uservers.net | Issue(96544) : Update 1.18 changelog | MEMBER | |
| uservers.net | puerco | axxxxxxxxxxxx@uservers.net | Issue(96544) : Update 1.18 changelog | MEMBER | |
| | | | with entries from v1.18.11 | | |
| | | | https://api.github.com/repos/kubernetes/kubernetes/issues/96544 | | |
+---------------+----------------+----------------------------+-----------------------------------------------------------------+ + +
| zackz.dev | knight42 | i@zackz.dev | Issue(96550) : chore(gce): pass auth flags to KCM and KS | | |
| | | | https://api.github.com/repos/kubernetes/kubernetes/issues/96550 | | |
+---------------+----------------+----------------------------+-----------------------------------------------------------------+ + +
| gmail.com | nilo19 | pomelonicky@gmail.com | Issue(96545) : Update the route table | | |
| gmail.com | nilo19 | pxxxxxxxxxx@gmail.com | Issue(96545) : Update the route table | | |
| | | | tag in the route reconcile loop | | |
| | | | https://api.github.com/repos/kubernetes/kubernetes/issues/96545 | | |
+---------------+----------------+----------------------------+-----------------------------------------------------------------+-------------+-------+
```

## Contribute

Of course, contributions are very welcome. File issues or PRs if you find this
useful.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.15

require (
github.com/cheggaaa/pb v1.0.29
github.com/cheggaaa/pb/v3 v3.0.5 // indirect
github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0 // indirect
github.com/olekukonko/tablewriter v0.0.4
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0
github.com/olekukonko/tablewriter v0.0.5-0.20201029120751-42e21c7531a3
github.com/spf13/cobra v1.1.1
)
72 changes: 47 additions & 25 deletions pkg/analyzer/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,40 @@ func (i *activities) Process(repo string) error {
return nil
}

func (i *activities) Write() {
func (i *activities) Write(expand bool) {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Org",
"GitHubId",
"Email",
"Issue / PR",
"Association",
"State",
})
table.SetHeaderColor(
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
)
if expand {
table.SetHeader([]string{
"Org",
"GitHubId",
"Email",
"Issue / PR",
"Association",
"State",
})
table.SetHeaderColor(
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
)
} else {
table.SetHeader([]string{
"Org",
"GitHubId",
"Association",
})
table.SetHeaderColor(
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
)
}
table.SetAutoMergeCells(true)
table.SetBorder(true)
table.SetRowLine(true)
table.SetAutoMergeCells(true)

activities := i.activities
sort.Slice(activities, func(i, j int) bool {
Expand All @@ -110,13 +123,22 @@ func (i *activities) Write() {

data := make([][]string, 0)
for _, activity := range activities {
row := []string{
activity.userDetails.org,
activity.User.Login,
activity.userDetails.email,
fmt.Sprintf("%s(%s) : %s \n\n %s", i.activityName, strconv.Itoa(activity.Number), activity.Title, activity.Url),
activity.userDetails.association,
activity.State,
var row []string
if expand {
row = []string{
activity.userDetails.org,
activity.User.Login,
activity.userDetails.email,
fmt.Sprintf("%s(%s) : %s \n\n %s", i.activityName, strconv.Itoa(activity.Number), activity.Title, activity.Url),
activity.userDetails.association,
activity.State,
}
} else {
row = []string{
activity.userDetails.org,
activity.User.Login,
activity.userDetails.association,
}
}
data = append(data, row)
}
Expand Down
71 changes: 48 additions & 23 deletions pkg/analyzer/charter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math"
"os"
"regexp"
"strconv"

"github.com/cheggaaa/pb"
"github.com/nimakaviani/github-contributors/pkg/scraper"
Expand All @@ -27,6 +28,7 @@ type charter struct {
charterMap map[string]interface{}
userOrg map[string]string
scraper scraper.Scraper
total float64
}

func NewCharter(scraper scraper.Scraper) *charter {
Expand All @@ -47,7 +49,8 @@ func (c *charter) Process(repo string, count int) error {
return err
}

fmt.Printf("Analyzig the last %d commits on %s\n", int(math.Max(float64(len(users)), float64(count))), repo)
c.total = math.Max(float64(len(users)), float64(count))
fmt.Printf("Analyzig the top %d contributors on %s\n", int(c.total), repo)
bar := pb.StartNew(len(users))
utils.Log("> building charter ...")
for _, user := range users {
Expand Down Expand Up @@ -119,38 +122,60 @@ func (c *charter) parse(login, email string) error {

func (c *charter) Write(expand bool) {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Org",
"Association",
"GitHubId",
"Email",
})
table.SetHeaderColor(
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
)
table.SetAutoMergeCells(true)

if expand {
table.SetHeader([]string{
"Org",
"GitHubId",
"Email",
})
table.SetHeaderColor(
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
)
table.SetAutoMergeCells(true)
} else {
table.SetHeader([]string{
"Org",
"Count",
"Percentage",
})
table.SetHeaderColor(
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
)
}

table.SetRowLine(true)
table.SetBorder(true)

data := make([][]string, 0)
for org, users := range c.charterMap {
if !expand {
continue
}

count := len(users.(map[string]*Details))
for login, details := range users.(map[string]*Details) {

if expand {
for login, details := range users.(map[string]*Details) {
data = append(data, []string{
fmt.Sprintf("%s \n %.1f%% ", org, (float64(count)/c.total)*100.0),
login,
details.email,
})
}
} else {
if count == 0 {
continue
}

data = append(data, []string{
fmt.Sprintf("%s (%d)", org, count),
details.association,
login,
details.email,
org,
strconv.Itoa(count),
fmt.Sprintf("%.1f%%", float64(float64(count)/c.total)*100.0),
})
}
}

table.AppendBulk(data)
table.Render()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
println(err.Error())
os.Exit(1)
}
issues.Write()
issues.Write(expand)
},
}
)
2 changes: 1 addition & 1 deletion pkg/cmd/prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
println(err.Error())
os.Exit(1)
}
prs.Write()
prs.Write(expand)
},
}
)
2 changes: 1 addition & 1 deletion pkg/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ var versionCmd = &cobra.Command{
Short: "Print the version number of Hugo",
Long: `All software has versions. This is Hugo's`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("0.0.2")
fmt.Println("0.0.3")
},
}

0 comments on commit 7fe912f

Please sign in to comment.