2019-04-06 21:32:14 +02:00
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"text/template"
|
|
|
|
|
2021-10-27 21:03:14 +02:00
|
|
|
"github.com/urfave/cli/v2"
|
2021-10-12 09:25:13 +02:00
|
|
|
|
2021-10-27 21:03:14 +02:00
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/common"
|
2021-09-21 16:36:41 +02:00
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/internal"
|
2019-04-06 21:32:14 +02:00
|
|
|
)
|
|
|
|
|
2021-10-27 21:03:14 +02:00
|
|
|
var repoSyncCmd = &cli.Command{
|
2019-04-06 21:32:14 +02:00
|
|
|
Name: "sync",
|
|
|
|
Usage: "synchronize the repository list",
|
|
|
|
ArgsUsage: " ",
|
|
|
|
Action: repoSync,
|
2021-10-27 21:03:14 +02:00
|
|
|
Flags: append(common.GlobalFlags,
|
|
|
|
common.FormatFlag(tmplRepoList),
|
|
|
|
),
|
2019-04-06 21:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func repoSync(c *cli.Context) error {
|
|
|
|
client, err := internal.NewClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
repos, err := client.RepoListOpts(true, true)
|
|
|
|
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
|
|
|
|
}
|
2021-11-23 16:36:52 +02:00
|
|
|
if err := tmpl.Execute(os.Stdout, repo); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-04-06 21:32:14 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|