plusieurs changements
This commit is contained in:
+2
-2
@@ -15,10 +15,10 @@ func ListGitHubOrganization() ([]string, error) {
|
||||
return orgs, nil
|
||||
}
|
||||
|
||||
func ListGitHubProjectsfromUser(username string) ([]*github.Repository, error) {
|
||||
func ListGitHubProjectsfromUser(username string, token string) ([]*github.Repository, error) {
|
||||
|
||||
// Replace with your access token
|
||||
token := "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"
|
||||
// token := "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"
|
||||
|
||||
// Create an oauth2 token source with the access token
|
||||
tokenSource := oauth2.StaticTokenSource(
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@ package cmdLists
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"kode-starter/utils"
|
||||
"kode-creator/utils"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
func ListGitTeaOrganization() ([]string, error) {
|
||||
godotenv.Load()
|
||||
|
||||
body := UrlGetBody(CfgGlobal.GetUrlApiOrgs())
|
||||
body := UrlGetBody(CfgGlobal.GetUrlApiOrgs(), CfgGlobal.GetGitTeaTokenEnv())
|
||||
if CfgGlobal.GetJsonFlag() {
|
||||
return utils.BytesToStrings(body), nil
|
||||
} else {
|
||||
@@ -44,7 +44,7 @@ func ListGitTeaOrganization() ([]string, error) {
|
||||
func ListGitTeaProjects(org string) ([]string, error) {
|
||||
godotenv.Load()
|
||||
|
||||
body := UrlGetBody(CfgGlobal.GetUrlApiOrgs() + "/" + org + "/repos")
|
||||
body := UrlGetBody(CfgGlobal.GetUrlApiOrgs()+"/"+org+"/repos", CfgGlobal.GetGitTeaTokenEnv())
|
||||
if CfgGlobal.GetJsonFlag() {
|
||||
return utils.BytesToStrings(body), nil
|
||||
} else {
|
||||
|
||||
+6
-6
@@ -3,8 +3,8 @@ package cmdLists
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"kode-starter/config"
|
||||
"kode-starter/utils"
|
||||
"kode-creator/config"
|
||||
"kode-creator/utils"
|
||||
"net/http"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -89,7 +89,7 @@ func startList(cmd *cobra.Command, args []string) {
|
||||
} else if CfgGlobal.GetGitFlag() {
|
||||
fmt.Println("\n L I S T G I T H U B P R O J E C T S F O R : " + CfgGlobal.GetListUser())
|
||||
fmt.Println(utils.CreateLine(11))
|
||||
repos, err := ListGitHubProjectsfromUser(CfgGlobal.GetListUser())
|
||||
repos, err := ListGitHubProjectsfromUser(CfgGlobal.GetListUser(), CfgGlobal.GetGithubTokenEnv())
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
return
|
||||
@@ -99,12 +99,12 @@ func startList(cmd *cobra.Command, args []string) {
|
||||
utils.PrintTreeElement(nb, *repo.Name, *repo.HTMLURL)
|
||||
nb++
|
||||
}
|
||||
fmt.Println(utils.CreateLine(11))
|
||||
|
||||
} else {
|
||||
|
||||
// print help if no flag is set
|
||||
cmd.Help()
|
||||
fmt.Println(utils.CreateLine(11))
|
||||
|
||||
}
|
||||
|
||||
@@ -112,14 +112,14 @@ func startList(cmd *cobra.Command, args []string) {
|
||||
|
||||
// This function sends a GET request to a specified URL with authorization and content-type headers,
|
||||
// and returns the response body as a byte array.
|
||||
func UrlGetBody(url string) []byte {
|
||||
func UrlGetBody(url string, token string) []byte {
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating request:", err)
|
||||
|
||||
}
|
||||
req.Header.Set("Authorization", "token "+CfgGlobal.GetTokenEnv())
|
||||
req.Header.Set("Authorization", "token "+token)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
// fmt.Println(req.Header.Get("Authorization"))
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
|
||||
Reference in New Issue
Block a user