예제 #1
0
func GetCredential() (Credential, error) {

	if _, err := os.Stat(credentialPath); os.IsNotExist(err) {
		utils.Dieif(err)
	}

	return parseCredential()
}
예제 #2
0
func parseCredential() (Credential, error) {
	var credential Credential

	file, err := ioutil.ReadFile(credentialPath)
	utils.Dieif(err)
	err = json.Unmarshal(file, &credential)

	return credential, err
}
예제 #3
0
func GetGithubClient() (*github.Client, string) {
	credential, err := GetCredential()
	utils.Dieif(err)

	ts := oauth2.StaticTokenSource(
		&oauth2.Token{
			AccessToken: credential.OauthAccessToken,
		},
	)
	tc := oauth2.NewClient(oauth2.NoContext, ts)
	// TODO: error handling
	return github.NewClient(tc), credential.User
}
예제 #4
0
파일: dump.go 프로젝트: knakayama/ghdump
// Dump github repository
func DumpRepository() {
	var allRepos []github.Repository

	ghClient, user := credential.GetGithubClient()
	opt := &github.RepositoryListOptions{
		ListOptions: github.ListOptions{PerPage: 100},
	}

	for {
		repos, response, err := ghClient.Repositories.List(user, opt)
		utils.Dieif(err)

		allRepos = append(allRepos, repos...)
		if response.NextPage == 0 {
			break
		} else {
			opt.ListOptions.Page = response.NextPage
		}
	}

	showResultRepository(allRepos)

	//fmt.Println(*repo.HTMLURL)
	//wg.Wait()
	//for _, repo := range allRepos {
	//	fmt.Println(*repo.HTMLURL)
	// TODO: goroutine
	//var wg sync.WaitGroup
	//count := 0
	//for {
	//	wg.Add(count)
	//	count += 1
	//	go func() {
	//		repos, response, err := ghClient.Repositories.List(user, opt)
	//		utils.Dieif(err)

	//		allRepos = append(allRepos, repos...)
	//		if response.NextPage == 0 {
	//			return
	//		} else {
	//			opt.ListOptions.Page = response.NextPage
	//		}
	//		wg.Done()
	//	}()
	//}
	//wg.Wait()
	//for _, repo := range allRepos {
	//	fmt.Println(*repo.HTMLURL)
	//}
}
예제 #5
0
파일: dump.go 프로젝트: knakayama/ghdump
// Dump github starred repository
func DumpStarredRepository() {
	var allRepos []github.StarredRepository
	ghClient, user := credential.GetGithubClient()
	opt := &github.ActivityListStarredOptions{
		ListOptions: github.ListOptions{PerPage: 100},
	}

	// TODO: goroutine
	for {
		repos, response, err := ghClient.Activity.ListStarred(user, opt)
		utils.Dieif(err)

		allRepos = append(allRepos, repos...)
		if response.NextPage == 0 {
			break
		} else {
			opt.ListOptions.Page = response.NextPage
		}
	}

	showResultStarredRepository(allRepos)
}