package cmdLists import ( "encoding/json" "fmt" "kode-starter/utils" "github.com/joho/godotenv" ) // The ListOrganization function retrieves a list of organizations from a specified URL and returns // their names and URLs. func ListGitTeaOrganization() ([]string, error) { godotenv.Load() body := UrlGetBody(CfgGlobal.GetUrlApiOrgs()) if CfgGlobal.GetJsonFlag() { return utils.BytesToStrings(body), nil } else { var orgs []map[string]interface{} err := json.Unmarshal(body, &orgs) if err != nil { return nil, err } else { var orgNames []string for i, org := range orgs { // nb := "[ " + strconv.FormatInt(int64(i+1), 10) + " ] " nb := fmt.Sprintf("[ %02d ] ", int64(i+1)) orgName := fmt.Sprintf("%s", org["username"]) orgUrl := fmt.Sprintf("[ %s/%s ]\n", CfgGlobal.GetUrlBase(), org["username"]) orgNames = append( orgNames, utils.PadString(nb, 4), utils.PadDotString(orgName, 30), orgUrl) } return orgNames, nil } } } // This function lists the projects of a given organization and returns their names and clone URLs. func ListGitTeaProjects(org string) ([]string, error) { godotenv.Load() body := UrlGetBody(CfgGlobal.GetUrlApiOrgs() + "/" + org + "/repos") if CfgGlobal.GetJsonFlag() { return utils.BytesToStrings(body), nil } else { var prjs []map[string]interface{} err := json.Unmarshal(body, &prjs) if err != nil { return nil, err } else { var orgNames []string for i, prj := range prjs { nb := fmt.Sprintf("[ %02d ] ", int64(i+1)) projectName := fmt.Sprintf("%s", prj["name"]) cloneUrl := fmt.Sprintf("[ %s ]\n", prj["clone_url"]) orgNames = append( orgNames, utils.PadString(nb, 4), utils.PadString(projectName, 40), cloneUrl, ) } return orgNames, nil } } }