-
-
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.
- Loading branch information
Showing
7 changed files
with
198 additions
and
91 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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/google/go-github/github" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
func getGitHubOrgCloneUrls() ([]string, error) { | ||
|
||
ctx := context.Background() | ||
ts := oauth2.StaticTokenSource( | ||
&oauth2.Token{AccessToken: os.Getenv("GHORG_GITHUB_TOKEN")}, | ||
) | ||
tc := oauth2.NewClient(ctx, ts) | ||
client := github.NewClient(tc) | ||
|
||
opt := &github.RepositoryListByOrgOptions{ | ||
Type: "all", | ||
ListOptions: github.ListOptions{PerPage: 100, Page: 0}, | ||
} | ||
|
||
// get all pages of results | ||
var allRepos []*github.Repository | ||
for { | ||
repos, resp, err := client.Repositories.ListByOrg(context.Background(), args[0], opt) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
allRepos = append(allRepos, repos...) | ||
if resp.NextPage == 0 { | ||
break | ||
} | ||
opt.Page = resp.NextPage | ||
} | ||
cloneUrls := []string{} | ||
|
||
for _, repo := range allRepos { | ||
if os.Getenv("GHORG_CLONE_PROTOCOL") == "https" { | ||
cloneUrls = append(cloneUrls, *repo.CloneURL) | ||
} else { | ||
cloneUrls = append(cloneUrls, *repo.SSHURL) | ||
} | ||
} | ||
|
||
return cloneUrls, nil | ||
} | ||
|
||
// TODO: refactor with getAllOrgCloneUrls | ||
func getGitHubUserCloneUrls() ([]string, error) { | ||
ctx := context.Background() | ||
|
||
ts := oauth2.StaticTokenSource( | ||
&oauth2.Token{AccessToken: os.Getenv("GHORG_GITHUB_TOKEN")}, | ||
) | ||
tc := oauth2.NewClient(ctx, ts) | ||
client := github.NewClient(tc) | ||
|
||
opt := &github.RepositoryListOptions{ | ||
Type: "all", | ||
ListOptions: github.ListOptions{PerPage: 100, Page: 0}, | ||
} | ||
|
||
// get all pages of results | ||
var allRepos []*github.Repository | ||
for { | ||
repos, resp, err := client.Repositories.List(context.Background(), args[0], opt) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
allRepos = append(allRepos, repos...) | ||
if resp.NextPage == 0 { | ||
break | ||
} | ||
opt.Page = resp.NextPage | ||
} | ||
cloneUrls := []string{} | ||
|
||
for _, repo := range allRepos { | ||
if os.Getenv("GHORG_CLONE_PROTOCOL") == "https" { | ||
cloneUrls = append(cloneUrls, *repo.CloneURL) | ||
} else { | ||
cloneUrls = append(cloneUrls, *repo.SSHURL) | ||
} | ||
} | ||
|
||
return cloneUrls, nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/gabrie30/ghorg/colorlog" | ||
) | ||
|
||
func getGitLabOrgCloneUrls() ([]string, error) { | ||
colorlog.PrintError("Gitlab org clone not available yet") | ||
os.Exit(1) | ||
// todo | ||
cloneUrls := []string{} | ||
return cloneUrls, nil | ||
} | ||
|
||
func getGitLabUserCloneUrls() ([]string, error) { | ||
colorlog.PrintError("Gitlab user clone not available yet") | ||
os.Exit(1) | ||
// todo | ||
cloneUrls := []string{} | ||
return cloneUrls, nil | ||
} |
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
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