Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/irevenko/octostats
🐙🐱📦 Additional GitHub API methods
https://github.com/irevenko/octostats
github github-api github-app github-profile go golang
Last synced: 26 days ago
JSON representation
🐙🐱📦 Additional GitHub API methods
- Host: GitHub
- URL: https://github.com/irevenko/octostats
- Owner: irevenko
- License: mit
- Created: 2021-03-08T14:30:54.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-04-13T10:07:13.000Z (over 3 years ago)
- Last Synced: 2024-06-21T15:25:18.808Z (6 months ago)
- Topics: github, github-api, github-app, github-profile, go, golang
- Language: Go
- Homepage:
- Size: 216 KB
- Stars: 16
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# octostats 🐙🐱📦
[![Go Reference](https://pkg.go.dev/badge/github.com/irevenko/octostats.svg)](https://pkg.go.dev/github.com/irevenko/octostats)
> 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 🧰
* [REST](#REST "Goto #REST")
* [AllRepos](#AllRepos "Goto ##AllRepos")
* [LanguagesByRepo](#LanguagesByRepo "Goto ##LanguagesByRepo")
* [MostUsedLicenses](#MostUsedLicenses "Goto ##MostUsedLicenses")
* [MostStarredRepos](#MostStarredRepos "Goto ##MostStarredRepos")
* [MostForkedRepos](#MostForkedRepos "Goto ##MostForkedRepos")
* [StarsPerLanguage](#StarsPerLanguage "Goto ##StarsPerLanguage")
* [ForksPerLanguage](#AllRepos "Goto ##ForksPerLanguage")
* [TotalStars](#TotalStars "Goto ##TotalStars")
* [TotalForks](#TotalForks "Goto ##TotalForks")
* [GraphQL](#GraphQL "Goto #GraphQL")
* [LanguagesByCommit](#LanguagesByCommit "Goto ##LanguagesByCommit")
* [AllContributions](#AllContributions "Goto ##AllContributions")
* [AllCommits](#AllCommits "Goto ##AllCommits")
* [AllIssues](#AllIssues "Goto ##AllIssues")
* [AllPullRequests](#AllPullRequests "Goto ##AllPullRequests")
* [YearActivity](#YearActivity "Goto ##YearActivity")
* [UserDetails](#UserDetails "Goto ##UserDetails")
* [OrganizationDetails](#OrganizationDetails "Goto ##OrganizationDetails")# Docs 📋
Go Reference: https://pkg.go.dev/github.com/irevenko/octostats
# REST
All examples are using ```AuthREST```
```ctx, client := r.AuthREST("")```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)
```go
import (
"fmt"
"log""github.com/google/go-github/github"
r "github.com/irevenko/octostats/rest"
)func main() {
ctx, client := r.AuthREST("")allRepos, err := r.AllRepos(ctx, client, "")
if err != nil {
log.Fatal(err)
}
fmt.Println(allRepos)
}
```## LanguagesByRepo
Returns two slices of names and occurrences
```go
import (
"fmt"
"log"
"strconv""github.com/google/go-github/github"
r "github.com/irevenko/octostats/rest"
)func main() {
ctx, client := r.AuthREST("")allRepos, err := r.AllRepos(ctx, client, "")
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
``` go
import (
"fmt"
"log"
"strconv""github.com/google/go-github/github"
r "github.com/irevenko/octostats/rest"
)func main() {
ctx, client := r.AuthREST("")allRepos, err := r.AllRepos(ctx, client, "")
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
``` go
import (
"fmt"
"log"
"strconv""github.com/google/go-github/github"
r "github.com/irevenko/octostats/rest"
)func main() {
ctx, client := r.AuthREST("")
allRepos, err := r.AllRepos(ctx, client, "")
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
```go
import (
"fmt"
"log"
"strconv""github.com/google/go-github/github"
r "github.com/irevenko/octostats/rest"
)func main() {
ctx, client := r.AuthREST("")allRepos, err := r.AllRepos(ctx, client, "")
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
```go
import (
"fmt"
"log"
"strconv""github.com/google/go-github/github"
r "github.com/irevenko/octostats/rest"
)func main() {
ctx, client := r.AuthREST("")allRepos, err := r.AllRepos(ctx, client, "")
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
```go
import (
"fmt"
"log"
"strconv""github.com/google/go-github/github"
r "github.com/irevenko/octostats/rest"
)func main() {
ctx, client := r.AuthREST("")allRepos, err := r.AllRepos(ctx, client, "")
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
```go
import (
"fmt"
"log""github.com/google/go-github/github"
r "github.com/irevenko/octostats/rest"
)func main() {
ctx, client := r.AuthREST("")allRepos, err := r.AllRepos(ctx, client, "")
if err != nil {
log.Fatal(err)
}
totalStars := r.TotalStars(client, allRepos)
fmt.Println("Total stars")
fmt.Println(totalStars)
}
```## TotalForks
Returns integer number
```go
import (
"fmt"
"log""github.com/google/go-github/github"
r "github.com/irevenko/octostats/rest"
)func main() {
ctx, client := r.AuthREST("")
allRepos, err := r.AllRepos(ctx, client, "")
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("")```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...)
```go
import (
"fmt"
"log""github.com/shurcooL/githubv4"
g "github.com/irevenko/octostats/graphql"
)func main() {
qlClient := g.AuthGraphQL("")langs, commits, err := g.LanguagesByCommit(qlClient, "", 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...)
```go
import (
"fmt"
"log""github.com/shurcooL/githubv4"
g "github.com/irevenko/octostats/graphql"
)func main() {
qlClient := g.AuthGraphQL("")allContribs, err := g.AllContributions(qlClient, "", 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...)
```go
import (
"fmt"
"log""github.com/shurcooL/githubv4"
g "github.com/irevenko/octostats/graphql"
)func main() {
qlClient := g.AuthGraphQL("")allCommits, err := g.AllCommits(qlClient, "", 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...)
```go
import (
"fmt"
"log""github.com/shurcooL/githubv4"
g "github.com/irevenko/octostats/graphql"
)func main() {
qlClient := g.AuthGraphQL("")allIssues, err := g.AllIssues(qlClient, "", 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...)
```go
import (
"fmt"
"log""github.com/shurcooL/githubv4"
g "github.com/irevenko/octostats/graphql"
)func main() {
qlClient := g.AuthGraphQL("")allPrs, err := g.AllPullRequests(qlClient, "", 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
```go
import (
"fmt"
"log""github.com/shurcooL/githubv4"
g "github.com/irevenko/octostats/graphql"
)func main() {
qlClient := g.AuthGraphQL("")dates, contribs, err := g.YearActivity(qlClient, "")
if err != nil {
log.Fatal(err)
}
fmt.Println(dates, contribs)
}
```## UserDetails
Returns ```User``` (see https://github.com/irevenko/octostats/blob/main/graphql/types.go)
```go
import (
"fmt"
"log""github.com/shurcooL/githubv4"
g "github.com/irevenko/octostats/graphql"
)func main() {
qlClient := g.AuthGraphQL("")fmt.Println("User Details:")
userInfo, err := g.UserDetails(qlClient, "")
if err != nil {
log.Fatal(err)
}
fmt.Println(userInfo)
}
```## OrganizationDetails
Returns ```Organization``` (see https://github.com/irevenko/octostats/blob/main/graphql/types.go)
```go
import (
"fmt"
"log""github.com/shurcooL/githubv4"
g "github.com/irevenko/octostats/graphql"
)func main() {
qlClient := g.AuthGraphQL("")fmt.Println("Organization Details:")
orgInfo, err := g.OrganizationDetails(qlClient, "")
if err != nil {
log.Fatal(err)
}
fmt.Println(orgInfo)
}
```# Contributing 🤝
Contributions, issues and feature requests are welcome! 👍
Feel free to check [open issues](https://github.com/irevenko/octostats/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](https://tldrlegal.com/license/mit-license)