Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from caarlos0/bumps
Browse files Browse the repository at this point in the history
Bumps
  • Loading branch information
caarlos0 committed May 5, 2017
2 parents fee262f + ddae4e4 commit ea3d2b2
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 147 deletions.
38 changes: 25 additions & 13 deletions Gopkg.lock

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

15 changes: 1 addition & 14 deletions Gopkg.toml
@@ -1,16 +1,3 @@

[[dependencies]]
branch = "master"
name = "github.com/caarlos0/spin"

[[dependencies]]
branch = "master"
name = "github.com/google/go-github"

[[dependencies]]
branch = "master"
name = "github.com/urfave/cli"

[[dependencies]]
branch = "master"
name = "golang.org/x/oauth2"
version = "v1.1.0"
98 changes: 0 additions & 98 deletions cmd/karmahub/main.go

This file was deleted.

135 changes: 135 additions & 0 deletions cmd/root.go
@@ -0,0 +1,135 @@
package cmd

import (
"context"
"fmt"
"os"
"time"

"github.com/caarlos0/karmahub/karma"
"github.com/caarlos0/spin"
"github.com/google/go-github/github"
"github.com/spf13/cobra"
"golang.org/x/oauth2"
)

var token string
var user string
var filter string
var months int

// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "karmahub",
Short: "get your history of reviews/comments and pull requests/issues opened",
Long: `Compares the amount of issues and pull requests you created with the
amount of comments and code reviews you did.
The idea is to use it at your daily job organization, so you can get an idea
of how much are you actually contributing to the code review practices.`,
RunE: func(cmd *cobra.Command, args []string) error {
if token == "" {
return fmt.Errorf("missing github token")
}
var spin = spin.New("%s Gathering data...").Start()

var ctx = context.Background()
var client = github.NewClient(oauth2.NewClient(
ctx,
oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token}),
))
var fn = karma.GitHubSearch(ctx, client)
if user == "" {
me, _, err := client.Users.Get(ctx, "")
if err != nil {
spin.Stop()
return err
}
user = *me.Login
}
prs, err := karma.Authors(fn, user, filter, months)
if err != nil {
spin.Stop()
return err
}
crs, err := karma.Reviews(fn, user, filter, months)
if err != nil {
spin.Stop()
return err
}
spin.Stop()

// header
fmt.Printf("\033[1;36mAction ")
for i := 0; i < months; i++ {
fmt.Printf(
"\t%v",
time.Now().AddDate(0, i*-1, 0).UTC().Format("Jan"),
)
}
fmt.Printf("\033[0m\n")

// authored
fmt.Printf("Authored ")
for i := 0; i < months; i++ {
fmt.Printf("\t%v", prs[i])
}
fmt.Printf("\n")

// reviewed
fmt.Printf("Reviewed ")
for i := 0; i < months; i++ {
fmt.Printf("\t%v", crs[i])
}
fmt.Printf("\n")

// karma
fmt.Printf("Karma ")
for i := 0; i < months; i++ {
fmt.Printf("\t%.1f", float32(crs[i])/float32(prs[i]))
}
fmt.Printf("\n")
return nil
},
}

// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute(version string) {
Version = version
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}

func init() {
RootCmd.PersistentFlags().StringVarP(
&token,
"token",
"t",
os.Getenv("GITHUB_TOKEN"),
"Your GitHub token",
)
RootCmd.PersistentFlags().StringVarP(
&user,
"user",
"u",
"",
"User to collect data from",
)
RootCmd.PersistentFlags().IntVarP(
&months,
"months",
"m",
3,
"Number of months to search",
)
RootCmd.PersistentFlags().StringVarP(
&filter,
"filter",
"f",
"",
"Additional filters, github syntax. E.g.: is:pr will gather data for pull requests only",
)
}
22 changes: 22 additions & 0 deletions cmd/version.go
@@ -0,0 +1,22 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// Version of karma
var Version = "dev"

var versionCmd = &cobra.Command{
Use: "version",
Short: "shows karmahub version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("karmahub version", Version)
},
}

func init() {
RootCmd.AddCommand(versionCmd)
}
1 change: 0 additions & 1 deletion goreleaser.yml
@@ -1,5 +1,4 @@
build:
main: ./cmd/karmahub/main.go
goos:
- windows
- darwin
Expand Down

0 comments on commit ea3d2b2

Please sign in to comment.