Skip to content

πŸ™πŸ±πŸ“¦ Additional GitHub API methods

License

Notifications You must be signed in to change notification settings

irevenko/octostats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

octostats πŸ™πŸ±πŸ“¦

Go Reference

A supplementary Go package on top of go-github and githubv4

GitHub API Superstructure


Installation πŸ”¨

go get github.com/google/go-github
go get github.com/google/go-querystring
go get github.com/shurcooL/githubv4
go get golang.org/x/oauth2

go get github.com/irevenko/octostats

Methods 🧰

Docs πŸ“‹

Go Reference: https://pkg.go.dev/github.com/irevenko/octostats

REST

All examples are using AuthREST
ctx, client := r.AuthREST("<YOUR_TOKEN>")

If you want you can write your own auth but keep in mind that you in order to use this package client, context are required

AllRepos

Returns slice of repos for user/organization (https://api.github.com/users/USERNAME/repos)

import ( 
    "fmt"
    "log"

    "github.com/google/go-github/github"
    r "github.com/irevenko/octostats/rest"
)

func main() {
	ctx, client := r.AuthREST("<YOUR_TOKEN>")

	allRepos, err := r.AllRepos(ctx, client, "<USER_OR_ORGANIZATION>")
	if err != nil {
	    log.Fatal(err)
	}
	fmt.Println(allRepos)
}

LanguagesByRepo

Returns two slices of names and occurrences

import ( 
    "fmt"
    "log"
    "strconv"

    "github.com/google/go-github/github"
    r "github.com/irevenko/octostats/rest"
)

func main() {
	ctx, client := r.AuthREST("<YOUR_TOKEN>")

	allRepos, err := r.AllRepos(ctx, client, "<USER_OR_ORGANIZATION>")
	if err != nil {
	    log.Fatal(err)
	}

	usedLangs, langsNum := r.LanguagesByRepo(client, allRepos)
	fmt.Println("Languages By Repo")
	for i, v := range usedLangs {
		fmt.Println(v + ": " + strconv.Itoa(langsNum[i]))
	}
}

MostUsedLicenses

Returns two slices of names and occurrences

import ( 
	"fmt"
	"log"
	"strconv"

	"github.com/google/go-github/github"
	r "github.com/irevenko/octostats/rest"
)

func main() {
	ctx, client := r.AuthREST("<YOUR_TOKEN>")

	allRepos, err := r.AllRepos(ctx, client, "<USER_OR_ORGANIZATION>")
	if err != nil {
	    log.Fatal(err)
	}

	usedLicenses, licsNum := r.MostUsedLicenses(client, allRepos)
	fmt.Println("Most used licenses")
	for i, v := range usedLicenses {
		fmt.Println(v + ": " + strconv.Itoa(licsNum[i]))
	}
}

MostStarredRepos

Returns two slices of names and stars num

import ( 
	"fmt"
	"log"
	"strconv"

	"github.com/google/go-github/github"
	r "github.com/irevenko/octostats/rest"
)

func main() {
	ctx, client := r.AuthREST("<YOUR_TOKEN>")
	
	allRepos, err := r.AllRepos(ctx, client, "<USER_OR_ORGANIZATION>")
	if err != nil {
	    log.Fatal(err)
	}
    
	starredRepos, starredNums := r.MostStarredRepos(client, allRepos)
	fmt.Println("Most starred repos")
	for i, v := range starredRepos {
		fmt.Println(v + ": " + strconv.Itoa(starredNums[i]))
	}
}

MostForkedRepos

Returns two slices of names and forks num

import ( 
	"fmt"
	"log"
	"strconv"

	"github.com/google/go-github/github"
	r "github.com/irevenko/octostats/rest"
)

func main() {
	ctx, client := r.AuthREST("<YOUR_TOKEN>")

	allRepos, err := r.AllRepos(ctx, client, "<USER_OR_ORGANIZATION>")
	if err != nil {
	    log.Fatal(err)
	}
    
	forkedRepos, forkedNums := r.MostForkedRepos(client, allRepos)
	fmt.Println("Most forked repos")
	for i, v := range forkedRepos {
		fmt.Println(v + ": " + strconv.Itoa(forkedNums[i]))
	}
}

StarsPerLanguage

Returns two slices of languages and stars num

import ( 
	"fmt"
	"log"
	"strconv"

	"github.com/google/go-github/github"
	r "github.com/irevenko/octostats/rest"
)

func main() {
	ctx, client := r.AuthREST("<YOUR_TOKEN>")

	allRepos, err := r.AllRepos(ctx, client, "<USER_OR_ORGANIZATION>")
	if err != nil {
	    log.Fatal(err)
	}
    
	starsPerL, starsNum := r.StarsPerLanguage(client, allRepos)
	fmt.Println("Stars per lang")
	for i, v := range starsPerL {
		fmt.Println(v + ": " + strconv.Itoa(starsNum[i]))
	}
}

ForksPerLanguage

Returns two slices of languages and forks num

import ( 
 	"fmt"
	"log"
	"strconv"

	"github.com/google/go-github/github"
	r "github.com/irevenko/octostats/rest"
)

func main() {
	ctx, client := r.AuthREST("<YOUR_TOKEN>")

	allRepos, err := r.AllRepos(ctx, client, "<USER_OR_ORGANIZATION>")
	if err != nil {
	    log.Fatal(err)
	}

	forksPerL, forksNum := r.ForksPerLanguage(client, allRepos)
	fmt.Println("Forks per lang")
	for i, v := range forksPerL {
		fmt.Println(v + ": " + strconv.Itoa(forksNum[i]))
	}
}

TotalStars

Returns integer number

import ( 
	"fmt"
	"log"

	"github.com/google/go-github/github"
	r "github.com/irevenko/octostats/rest"
)

func main() {
	ctx, client := r.AuthREST("<YOUR_TOKEN>")

	allRepos, err := r.AllRepos(ctx, client, "<USER_OR_ORGANIZATION>")
	if err != nil {
	    log.Fatal(err)
	}
    
	totalStars := r.TotalStars(client, allRepos)
	fmt.Println("Total stars")
	fmt.Println(totalStars)
}

TotalForks

Returns integer number

import ( 
	"fmt"
	"log"

	"github.com/google/go-github/github"
	r "github.com/irevenko/octostats/rest"
)

func main() {
	ctx, client := r.AuthREST("<YOUR_TOKEN>")
	
	allRepos, err := r.AllRepos(ctx, client, "<USER_OR_ORGANIZATION>")
	if err != nil {
	    log.Fatal(err)
	}
    
	totalForks := r.TotalForks(client, allRepos)
	fmt.Println("Total forks")
	fmt.Println(totalForks)
}

GraphQL

All examples are using AuthGraphQL
client := g.AuthGraphQL("<YOUR_TOKEN>")

If you want you can write your own auth but keep in mind that you in order to use this package client is required

LanguagesByCommit

Returns two slices of languages and commits
from and to must be within 1 year span (2009, 2010 OR 2014, 2015 etc...)

import ( 
	"fmt"
	"log"

	"github.com/shurcooL/githubv4"
	g "github.com/irevenko/octostats/graphql"
)

func main() {
	qlClient := g.AuthGraphQL("<YOUR_TOKEN>")

	langs, commits, err := g.LanguagesByCommit(qlClient, "<USER_OR_ORGANIZATION>", 2020, 2021)
	if err != nil {
	    log.Fatal(err)
	}
	fmt.Println("\nLanguages by commit")
	for i, v := range langs {
		fmt.Printf("%v : %v\n", v, commits[i])
	}
}

AllContributions

Returns ContributionsCollection (see https://github.com/irevenko/octostats/blob/main/graphql/types.go)
from and to must be within 1 year span (2009, 2010 OR 2014, 2015 etc...)

import ( 
	"fmt"
	"log"

	"github.com/shurcooL/githubv4"
	g "github.com/irevenko/octostats/graphql"
)

func main() {
	qlClient := g.AuthGraphQL("<YOUR_TOKEN>")

	allContribs, err := g.AllContributions(qlClient, "<USER_OR_ORGANIZATION>", 2020, 2021)
	if err != nil {
	    log.Fatal(err)
	}
	fmt.Println("\nAll contribs 2020-2021:")
	fmt.Println(allContribs)
}

AllCommits

Returns []commitContributions (see https://github.com/irevenko/octostats/blob/main/graphql/types.go)
from and to must be within 1 year span (2009, 2010 OR 2014, 2015 etc...)

import ( 
	"fmt"
	"log"

	"github.com/shurcooL/githubv4"
	g "github.com/irevenko/octostats/graphql"
)

func main() {
	qlClient := g.AuthGraphQL("<YOUR_TOKEN>")

	allCommits, err := g.AllCommits(qlClient, "<USER_OR_ORGANIZATION>", 2020, 2021)
	if err != nil {
	    log.Fatal(err)
	}
	fmt.Println("\nAll commits 2020-2021:")
	fmt.Println(allCommits)
}

AllIssues

Returns []issueContributions (see https://github.com/irevenko/octostats/blob/main/graphql/types.go)
from and to must be within 1 year span (2009, 2010 OR 2014, 2015 etc...)

import ( 
	"fmt"
	"log"

	"github.com/shurcooL/githubv4"
	g "github.com/irevenko/octostats/graphql"
)

func main() {
	qlClient := g.AuthGraphQL("<YOUR_TOKEN>")

	allIssues, err := g.AllIssues(qlClient, "<USER_OR_ORGANIZATION>", 2020, 2021)
	if err != nil {
	    log.Fatal(err)
	}
	fmt.Println("\nAll issues 2020-2021:")
	fmt.Println(allIssues)
}

AllPullRequests

Returns []pullRequestContributions (see https://github.com/irevenko/octostats/blob/main/graphql/types.go)
from and to must be within 1 year span (2009, 2010 OR 2014, 2015 etc...)

import ( 
	"fmt"
	"log"

	"github.com/shurcooL/githubv4"
	g "github.com/irevenko/octostats/graphql"
)

func main() {
	qlClient := g.AuthGraphQL("<YOUR_TOKEN>")

	allPrs, err := g.AllPullRequests(qlClient, "<USER_OR_ORGANIZATION>", 2020, 2021)
	if err != nil {
	    log.Fatal(err)
	}
	fmt.Println("\nAll pull requests 2020-2021:")
	fmt.Println(allPrs)
}

YearActivity

Returns two slices of dates and contributions

import ( 
	"fmt"
	"log"

	"github.com/shurcooL/githubv4"
	g "github.com/irevenko/octostats/graphql"
)

func main() {
	qlClient := g.AuthGraphQL("<YOUR_TOKEN>")

	dates, contribs, err := g.YearActivity(qlClient, "<USER_OR_ORGANIZATION>")
	if err != nil {
	    log.Fatal(err)
	}
	fmt.Println(dates, contribs)
}

UserDetails

Returns User (see https://github.com/irevenko/octostats/blob/main/graphql/types.go)

import ( 
	"fmt"
	"log"

	"github.com/shurcooL/githubv4"
	g "github.com/irevenko/octostats/graphql"
)

func main() {
	qlClient := g.AuthGraphQL("<YOUR_TOKEN>")

	fmt.Println("User Details:")
	userInfo, err := g.UserDetails(qlClient, "<USER>")
	if err != nil {
	    log.Fatal(err)
	}
	fmt.Println(userInfo)
}

OrganizationDetails

Returns Organization (see https://github.com/irevenko/octostats/blob/main/graphql/types.go)

import ( 
	"fmt"
	"log"

	"github.com/shurcooL/githubv4"
	g "github.com/irevenko/octostats/graphql"
)

func main() {
	qlClient := g.AuthGraphQL("<YOUR_TOKEN>")

	fmt.Println("Organization Details:")
	orgInfo, err := g.OrganizationDetails(qlClient, "<ORGANIZATION>")
	if err != nil {
	    log.Fatal(err)
	}
	fmt.Println(orgInfo)
}

Contributing 🀝

Contributions, issues and feature requests are welcome! πŸ‘
Feel free to check open issues.

What I Learned 🧠

  • GraphQL basics
  • GoLang API auth

Notes

  • shows private repos and repos from orgs when using empty string as name (if authorized)
  • see readme-stats, metrics

License πŸ“‘

(c) 2021 Ilya Revenko. MIT License