Skip to content

Commit

Permalink
add deployments repositories list command
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Sep 26, 2023
1 parent 5084c29 commit de40f2e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/plural/cd.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,19 @@ func (p *Plural) handleCreateCDRepository(c *cli.Context) error {
}

func (p *Plural) handleListCDRepositories(c *cli.Context) error {
if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
return err
}
repos, err := p.ConsoleClient.ListRepositories()
if err != nil {
return err
}

headers := []string{"ID", "URL"}
return utils.PrintTable(repos, headers, func(r console.GitRepository) ([]string, error) {
return []string{r.Id, r.URL}, nil
})

return nil
}

func (p *Plural) handleListClusterServices(c *cli.Context) error {
Expand Down
1 change: 1 addition & 0 deletions pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ConsoleClient interface {
ListClusters() ([]Cluster, error)
ListClusterServices() ([]ServiceDeployment, error)
CreateRepository(url string, privateKey, passphrase, username, password *string) (*GitRepository, error)
ListRepositories() ([]GitRepository, error)
}

func NewConsoleClient(token, url string) (ConsoleClient, error) {
Expand Down
15 changes: 15 additions & 0 deletions pkg/console/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,18 @@ func (c *consoleClient) CreateRepository(url string, privateKey, passphrase, use

return convertGitRepository(result.CreateGitRepository), nil
}

func (c *consoleClient) ListRepositories() ([]GitRepository, error) {
result, err := c.pluralClient.ListGitRepositories(c.ctx, nil, nil, nil)
if err != nil {
return nil, api.GetErrorResponse(err, "CreateGitRepository")
}

var output []GitRepository
for _, repo := range result.GitRepositories.Edges {
r := convertGitRepository(repo.Node)
output = append(output, *r)
}

return output, nil
}

0 comments on commit de40f2e

Please sign in to comment.