GitHub API Superstructure
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
Go Reference: https://pkg.go.dev/github.com/irevenko/octostats
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
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)
}
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]))
}
}
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]))
}
}
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]))
}
}
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]))
}
}
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]))
}
}
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]))
}
}
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)
}
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)
}
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
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])
}
}
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)
}
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)
}
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)
}
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)
}
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)
}
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)
}
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)
}
Contributions, issues and feature requests are welcome! π
Feel free to check open issues.
- GraphQL basics
- GoLang API auth
- shows private repos and repos from orgs when using empty string as name (if authorized)
- see readme-stats, metrics
(c) 2021 Ilya Revenko. MIT License