Skip to content

Commit

Permalink
fix issue with clone path for single repositories + update README
Browse files Browse the repository at this point in the history
  • Loading branch information
headyj committed Oct 1, 2020
1 parent 9509272 commit e0fc63a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
giterate
giterate*
*.exe
.DS_Store
.vscode
__debug_bin
*.json
*.yaml
*.yaml
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ Each git provider will have the same available parameters:
You can find an example of configuration file on this repository

## Available services
- Gitlab
- Bitbucket V1
- Bitbucket V2
- Github
- Gitlab (https://www.github.com/xanzy/go-gitlab)
- Bitbucket V1 (https://www.github.com/gfleury/go-bitbucket-v1)
- Bitbucket V2 (https://www.github.com/ktrysmt/go-bitbucket)
- Github (https://www.github.com/google/go-github/github)

## Available commands
- [x] clone: clone repositories according to configuration file
Expand Down Expand Up @@ -61,7 +61,7 @@ You can find an example of configuration file on this repository
- [x] --config-file: set json/yaml configuration file path

## Roadmap
[ ] tests
[ ] commit command
[ ] push command
[ ] implement parameters
- [ ] tests
- [ ] commit command
- [ ] push command
- [ ] implement parameters
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
Args: args,
Commands: Commands,
HelpFunc: cli.BasicHelpFunc("giterate"),
Version: "0.1",
Version: "0.2",
}

status, err := cli.Run()
Expand Down
30 changes: 17 additions & 13 deletions pkg/entities/abstract_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

bitbucketv1 "github.com/gfleury/go-bitbucket-v1"
"github.com/google/go-github/github"
bitbucket "github.com/ktrysmt/go-bitbucket"
bitbucketv2 "github.com/ktrysmt/go-bitbucket"
"github.com/xanzy/go-gitlab"
"golang.org/x/oauth2"
Expand All @@ -34,7 +33,7 @@ type BitbucketClient struct {
}

type BitbucketClientV2 struct {
Client *bitbucket.Client
Client *bitbucketv2.Client
}

type GithubClient struct {
Expand All @@ -44,9 +43,15 @@ type GithubClient struct {
// Gitlab
func (gl GitlabClient) GetGroupRepositories(path string, name string, recurse bool, cloneType string) []RepositoryInfo {
var repositoriesInfo []RepositoryInfo
projects, _, err := gl.Client.Groups.ListGroupProjects(path+"/"+name, &gitlab.ListGroupProjectsOptions{ListOptions: gitlab.ListOptions{PerPage: 10000}, IncludeSubgroups: gitlab.Bool(recurse)})
var finalPath string
if path == "" {
finalPath = name
} else {
finalPath = path + "/" + name
}
projects, _, err := gl.Client.Groups.ListGroupProjects(finalPath, &gitlab.ListGroupProjectsOptions{ListOptions: gitlab.ListOptions{PerPage: 10000}, IncludeSubgroups: gitlab.Bool(recurse)})
if err != nil {
log.Fatalf("Failed to get group %s: %v", path+"/"+name, err)
log.Fatalf("Failed to get group %s: %v", finalPath, err)
}
for _, project := range projects {
var repositoryLink string
Expand All @@ -58,7 +63,6 @@ func (gl GitlabClient) GetGroupRepositories(path string, name string, recurse bo
repositoryInfo := RepositoryInfo{repositoryLink, project.PathWithNamespace}
repositoriesInfo = append(repositoriesInfo, repositoryInfo)
}

return repositoriesInfo
}
func (gl GitlabClient) GetRepository(path string, name string, cloneType string) RepositoryInfo {
Expand Down Expand Up @@ -141,7 +145,7 @@ func (bb BitbucketClient) GetRepository(path string, name string, cloneType stri
repositoryLink = links.Href
}
}
return RepositoryInfo{repositoryLink, repository.Slug}
return RepositoryInfo{repositoryLink, strings.ToLower(repository.Project.Key) + "/" + repository.Slug}
}
func BitbucketAuth(service Service) GitClient {
var git *bitbucketv1.APIClient
Expand Down Expand Up @@ -179,7 +183,7 @@ func (gh GithubClient) GetGroupRepositories(path string, name string, recurse bo
} else {
repositoryLink = repository.GetHTMLURL()
}
repositoryInfo := RepositoryInfo{repositoryLink, repository.GetName()}
repositoryInfo := RepositoryInfo{repositoryLink, repository.GetFullName()}
repositoriesInfo = append(repositoriesInfo, repositoryInfo)
}
return repositoriesInfo
Expand All @@ -195,7 +199,7 @@ func (gh GithubClient) GetRepository(path string, name string, cloneType string)
} else {
repositoryLink = repository.GetHTMLURL()
}
return RepositoryInfo{repositoryLink, repository.GetName()}
return RepositoryInfo{repositoryLink, repository.GetFullName()}
}
func GithubAuth(service Service) GitClient {
var git *github.Client
Expand All @@ -219,9 +223,9 @@ func GithubAuth(service Service) GitClient {

//Bitbucket V2
func (bb BitbucketClientV2) GetRepository(path string, name string, cloneType string) RepositoryInfo {
project := bitbucket.Project{Name: path}
repository := bitbucket.Repository{Slug: name, Project: project}
repository2, err := repository.Get(&bitbucket.RepositoryOptions{})
project := bitbucketv2.Project{Name: path}
repository := bitbucketv2.Repository{Slug: name, Project: project}
repository2, err := repository.Get(&bitbucketv2.RepositoryOptions{})
if err != nil {
log.Fatalf("Cannot get repository response: %s", err)
}
Expand All @@ -240,11 +244,11 @@ func (bb BitbucketClientV2) GetRepository(path string, name string, cloneType st
}
}
}
return RepositoryInfo{repositoryLink, repository.Slug}
return RepositoryInfo{repositoryLink, strings.ToLower(repository.Project.Key) + "/" + repository.Slug}
}
func (bb BitbucketClientV2) GetGroupRepositories(path string, name string, recurse bool, cloneType string) []RepositoryInfo {
var repositoriesInfo []RepositoryInfo
response, err := bb.Client.Repositories.ListForAccount(&bitbucket.RepositoriesOptions{Owner: name})
response, err := bb.Client.Repositories.ListForAccount(&bitbucketv2.RepositoriesOptions{Owner: name})
if err != nil {
log.Fatalf("Cannot get repositories response: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/entities/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func PopulateRepositories(services []Service) []Service {
}
case "repository":
repositoryInfo := gitClient.GetRepository(jsonEntity.Path, jsonEntity.Name, service.CloneType)
repository := NewRepository(&service, repositoryInfo.URL, jsonEntity.Destination, "", jsonEntity.CloneOptions)
repository := NewRepository(&service, repositoryInfo.URL, jsonEntity.Destination, repositoryInfo.Path, jsonEntity.CloneOptions)
UpdateRepositories(&repositories, repository)
default:
log.Fatalf("%s is not a valid Type", jsonEntity.Type)
Expand Down

0 comments on commit e0fc63a

Please sign in to comment.