mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
ff01a9ff1d
closes #1295 closes #648 # TODO - [x] add new routes with `:repoID` - [x] load repo in middleware using `:repoID` if present - [x] update UI routes `:owner/:name` to `:repoID` - [x] load repos using id in UI - [x] add lookup endpoint `:owner/:name` to `:repoID` - [x] redirect `:owner/:name` to `:repoID` in UI - [x] use badge with `:repoID` route in UI - [x] update `woodpecker-go` - [x] check cli - [x] add migrations / deprecation notes - [x] check if #648 got solved directly - [x] Test - [x] create repo - [x] repo pages - [x] ui redirects - [x] forge status links
56 lines
1 KiB
Go
56 lines
1 KiB
Go
package repo
|
|
|
|
import (
|
|
"os"
|
|
"text/template"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/common"
|
|
"github.com/woodpecker-ci/woodpecker/cli/internal"
|
|
)
|
|
|
|
var repoListCmd = &cli.Command{
|
|
Name: "ls",
|
|
Usage: "list all repos",
|
|
ArgsUsage: " ",
|
|
Action: repoList,
|
|
Flags: append(common.GlobalFlags,
|
|
common.FormatFlag(tmplRepoList),
|
|
&cli.StringFlag{
|
|
Name: "org",
|
|
Usage: "filter by organization",
|
|
},
|
|
),
|
|
}
|
|
|
|
func repoList(c *cli.Context) error {
|
|
client, err := internal.NewClient(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
repos, err := client.RepoList()
|
|
if err != nil || len(repos) == 0 {
|
|
return err
|
|
}
|
|
|
|
tmpl, err := template.New("_").Parse(c.String("format") + "\n")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
org := c.String("org")
|
|
for _, repo := range repos {
|
|
if org != "" && org != repo.Owner {
|
|
continue
|
|
}
|
|
if err := tmpl.Execute(os.Stdout, repo); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// template for repository list items
|
|
var tmplRepoList = "\x1b[33m{{ .FullName }}\x1b[0m (id: {{ .ID }})"
|