2023-06-30 10:09:01 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-06-30 15:25:39 -04:00
|
|
|
func ListGitHubProjectsfromUser(username string, token string) ([]*github.Repository, error) {
|
2023-06-30 10:09:01 -04:00
|
|
|
|
|
|
|
// Replace with your access token
|
2023-06-30 15:25:39 -04:00
|
|
|
// token := "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"
|
2023-06-30 10:09:01 -04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|