-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/gabrie30/ghorg
- Loading branch information
Showing
2 changed files
with
17 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,9 @@ import ( | |
) | ||
|
||
var ( | ||
_ Client = Github{} | ||
reposPerPage = 100 | ||
selfCloneUsername = "" | ||
_ Client = Github{} | ||
reposPerPage = 100 | ||
tokenUsername = "" | ||
) | ||
|
||
func init() { | ||
|
@@ -41,6 +41,8 @@ func (c Github) GetOrgRepos(targetOrg string) ([]Repo, error) { | |
ListOptions: github.ListOptions{PerPage: c.perPage}, | ||
} | ||
|
||
c.SetTokensUsername() | ||
|
||
// get all pages of results | ||
var allRepos []*github.Repository | ||
for { | ||
|
@@ -75,12 +77,9 @@ func (c Github) GetOrgRepos(targetOrg string) ([]Repo, error) { | |
|
||
// GetUserRepos gets user repos | ||
func (c Github) GetUserRepos(targetUser string) ([]Repo, error) { | ||
|
||
userToken, _, _ := c.Users.Get(context.Background(), "") | ||
|
||
if targetUser == userToken.GetLogin() { | ||
c.SetTokensUsername() | ||
if targetUser == tokenUsername { | ||
colorlog.PrintSubtleInfo("\nCloning all your public/private repos. This process may take a bit longer than other clones, please be patient...") | ||
selfCloneUsername = targetUser | ||
targetUser = "" | ||
} | ||
|
||
|
@@ -151,12 +150,7 @@ func (_ Github) NewClient() (Client, error) { | |
|
||
func (_ Github) addTokenToHTTPSCloneURL(url string, token string) string { | ||
splitURL := strings.Split(url, "https://") | ||
|
||
// When a user is cloning themselves add the username | ||
if selfCloneUsername != "" { | ||
return "https://" + selfCloneUsername + ":" + token + "@" + splitURL[1] | ||
} | ||
return "https://" + token + "@" + splitURL[1] | ||
return "https://" + tokenUsername + ":" + token + "@" + splitURL[1] | ||
} | ||
|
||
func (c Github) filter(allRepos []*github.Repository) []Repo { | ||
|
@@ -218,3 +212,11 @@ func (c Github) filter(allRepos []*github.Repository) []Repo { | |
|
||
return repoData | ||
} | ||
|
||
// Sets the GitHub username tied to the github token to the package variable tokenUsername | ||
// Then if https clone method is used the clone url will be https://username:[email protected]/org/repo.git | ||
// The username is now needed when using the new fine-grained tokens for github | ||
func (c Github) SetTokensUsername() { | ||
userToken, _, _ := c.Users.Get(context.Background(), "") | ||
tokenUsername = userToken.GetLogin() | ||
} |