Skip to content

Commit

Permalink
Add github clone URL
Browse files Browse the repository at this point in the history
  • Loading branch information
pratishshr committed Aug 30, 2019
1 parent 77f8677 commit 7102282
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
13 changes: 8 additions & 5 deletions cli/internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ func chooseOrganization(personalToken string) string {
return org
}

func chooseRepo(personalToken string, organization string) string {
func chooseRepo(personalToken string, organization string) (string, string) {
repos := []string{}
repoURL := map[string]string{}

spinner.Start("Fetching your repositories...")
if strings.Contains(organization, "(User)") {
repos, _ = github.FetchUserRepos(personalToken)
repos, repoURL, _ = github.FetchUserRepos(personalToken)
} else {
repos, _ = github.FetchOrgRepos(personalToken, organization)
repos, repoURL, _ = github.FetchOrgRepos(personalToken, organization)
}
spinner.Stop()

Expand All @@ -166,7 +167,7 @@ func chooseRepo(personalToken string, organization string) string {
fmt.Println(err)
}

return org
return org, repoURL[org]
}

// Run initializes setup for shift projects.
Expand All @@ -180,7 +181,7 @@ func Run() {
spinner.Stop()

organization := chooseOrganization(personalToken)
repo := chooseRepo(personalToken, organization)
repo, repoURL := chooseRepo(personalToken, organization)

fmt.Print("ProjectDetails: ")
fmt.Println(projectDetails)
Expand All @@ -196,4 +197,6 @@ func Run() {

fmt.Print("Repository: ")
fmt.Println(repo)
fmt.Print("Clone URL: ")
fmt.Println(repoURL)
}
25 changes: 14 additions & 11 deletions cli/utils/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ type user struct {
}

type repo struct {
Name string `json:"name"`
Name string `json:"name"`
CloneURL string `json:"clone_url"`
}

// CreatePersonalToken creates a personal access token in github
Expand Down Expand Up @@ -112,8 +113,10 @@ func FetchUser(personalToken string) (string, error) {
}

// FetchOrgRepos fetches user's repositories
func FetchOrgRepos(personalToken string, organization string) ([]string, error) {
func FetchOrgRepos(personalToken string, organization string) ([]string, map[string]string, error) {
response := []repo{}
repos := []string{}
repoURL := map[string]string{}

_, err := http.Client.R().
SetHeader("Authorization", "token "+personalToken).
Expand All @@ -124,21 +127,22 @@ func FetchOrgRepos(personalToken string, organization string) ([]string, error)
fmt.Println("Error:")
fmt.Println(err)

return []string{}, err
return repos, repoURL, err
}

repos := []string{}

for _, repo := range response {
repos = append(repos, repo.Name)
repoURL[repo.Name] = repo.CloneURL
}

return repos, nil
return repos, repoURL, nil
}

// FetchUserRepos fetches user's repositories
func FetchUserRepos(personalToken string) ([]string, error) {
func FetchUserRepos(personalToken string) ([]string, map[string]string, error) {
response := []repo{}
repos := []string{}
repoURL := map[string]string{}

_, err := http.Client.R().
SetHeader("Authorization", "token "+personalToken).
Expand All @@ -149,14 +153,13 @@ func FetchUserRepos(personalToken string) ([]string, error) {
fmt.Println("Error:")
fmt.Println(err)

return []string{}, err
return repos, repoURL, err
}

repos := []string{}

for _, repo := range response {
repos = append(repos, repo.Name)
repoURL[repo.Name] = repo.CloneURL
}

return repos, nil
return repos, repoURL, nil
}

0 comments on commit 7102282

Please sign in to comment.