go-KodeStarter/cmdLists/gitHub.go

43 lines
953 B
Go

package cmdLists
import (
"context"
"fmt"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
func ListGitHubOrganization() ([]string, error) {
var orgs []string
return orgs, nil
}
func ListGitHubProjectsfromUser(username string, token string) ([]*github.Repository, error) {
// Replace with your access token
// token := "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"
// Create an oauth2 token source with the access token
tokenSource := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
// Create an oauth2 http client with the token source
oauth2Client := oauth2.NewClient(context.Background(), tokenSource)
// Create a new github client with the oauth2 http client
client := github.NewClient(oauth2Client)
// List the repositories of the user
repos, _, err := client.Repositories.List(context.Background(), username, nil)
if err != nil {
fmt.Println(err)
return nil, err
}
return repos, nil
}