Created
January 20, 2015 16:47
-
-
Save itarato/96a07ee4032b2b06d75f to your computer and use it in GitHub Desktop.
Special GitHub repo crawler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The script requires your GitHub token. | |
// It fetches the teams for a given organisation. | |
// Then goes through one team's repos. | |
// Config file format: | |
// { | |
// "personalToken": "TOKEN_FROM_GITHUB", | |
// "orgName": "SELECTED_ORG_NAME", | |
// "teamName": "SELECTED_TEAM_NAME" | |
// } | |
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"github.com/google/go-github/github" | |
"golang.org/x/oauth2" | |
"io/ioutil" | |
) | |
var ( | |
repoPageLimit int = 30 | |
) | |
type Config struct { | |
PersonalToken string `json:"personalToken"` | |
OrgName string `json:"orgName"` | |
TeamName string `json:"teamName"` | |
} | |
type GithubTokenSource struct { | |
PersonalToken string | |
} | |
func (gts *GithubTokenSource) Token() (*oauth2.Token, error) { | |
return &oauth2.Token{AccessToken: gts.PersonalToken}, nil | |
} | |
func main() { | |
var config Config | |
b, err := ioutil.ReadFile("config.json") | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
if err = json.Unmarshal(b, &config); err != nil { | |
fmt.Println(err) | |
return | |
} | |
c := oauth2.NewClient(oauth2.NoContext, &GithubTokenSource{config.PersonalToken}) | |
client := github.NewClient(c) | |
teams, _, err := client.Organizations.ListTeams(config.OrgName, nil) | |
if err != nil { | |
fmt.Println(err) | |
} | |
var highwire_team_id int | |
for _, team := range teams { | |
if *team.Name == config.TeamName { | |
highwire_team_id = *team.ID | |
break | |
} | |
} | |
for page := 0; ; page++ { | |
opt := &github.ListOptions{PerPage: repoPageLimit, Page: page} | |
repos, _, err := client.Organizations.ListTeamRepos(highwire_team_id, opt) | |
if err != nil { | |
fmt.Println(err) | |
break | |
} | |
if len(repos) == 0 { | |
break | |
} | |
for _, repo := range repos { | |
fmt.Println(*repo.SSHURL) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment