mirror of
https://github.com/outbackdingo/ghorg.git
synced 2026-01-27 18:18:58 +00:00
wire up GitHub calls
This commit is contained in:
1
.env-sample
Normal file
1
.env-sample
Normal file
@@ -0,0 +1 @@
|
||||
GITHUB_TOKEN=
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
ghorg
|
||||
.env
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
## Ghorg
|
||||
# Ghorg
|
||||
|
||||
|
||||
### Access
|
||||
- Create a personal access token, if the org is behind SSO add it to the token https://help.github.com/articles/authorizing-a-personal-access-token-for-use-with-a-saml-single-sign-on-organization/
|
||||
|
||||
35
cmd/clone.go
35
cmd/clone.go
@@ -1,9 +1,40 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
func Clone(arg string) {
|
||||
fmt.Println("Cloning Repos", arg)
|
||||
func authSetup() (*github.Client, *github.RepositoryListByOrgOptions) {
|
||||
ctx := context.Background()
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
|
||||
)
|
||||
tc := oauth2.NewClient(ctx, ts)
|
||||
client := github.NewClient(tc)
|
||||
|
||||
opt := &github.RepositoryListByOrgOptions{
|
||||
Type: "all",
|
||||
ListOptions: github.ListOptions{PerPage: 1000},
|
||||
}
|
||||
|
||||
return client, opt
|
||||
}
|
||||
|
||||
// CloneAllReposByOrg clones all repos for a given org
|
||||
func CloneAllReposByOrg() {
|
||||
client, opt := authSetup()
|
||||
repos, _, err := client.Repositories.ListByOrg(context.Background(), os.Args[1], opt)
|
||||
if err != nil {
|
||||
fmt.Print("Oh no error city: ", err)
|
||||
}
|
||||
|
||||
fmt.Println(repos)
|
||||
}
|
||||
|
||||
// Could clone all repos on a user
|
||||
// orgs, _, err := client.Organizations.List(context.Background(), "willnorris", nil)
|
||||
|
||||
12
main.go
12
main.go
@@ -2,12 +2,20 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"log"
|
||||
|
||||
"github.com/ghorg/cmd"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, Ghorg")
|
||||
cmd.Clone(os.Args[1])
|
||||
cmd.CloneAllReposByOrg()
|
||||
}
|
||||
|
||||
func init() {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user