2019-04-06 19:32:14 +00:00
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"text/template"
|
|
|
|
|
2021-10-27 19:03:14 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2021-10-12 07:25:13 +00:00
|
|
|
|
2021-10-27 19:03:14 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/common"
|
2021-09-21 14:36:41 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/internal"
|
2019-04-06 19:32:14 +00:00
|
|
|
)
|
|
|
|
|
2021-10-27 19:03:14 +00:00
|
|
|
var repoSyncCmd = &cli.Command{
|
2019-04-06 19:32:14 +00:00
|
|
|
Name: "sync",
|
|
|
|
Usage: "synchronize the repository list",
|
|
|
|
ArgsUsage: " ",
|
|
|
|
Action: repoSync,
|
2021-10-27 19:03:14 +00:00
|
|
|
Flags: append(common.GlobalFlags,
|
|
|
|
common.FormatFlag(tmplRepoList),
|
|
|
|
),
|
2019-04-06 19:32:14 +00:00
|
|
|
}
|
|
|
|
|
2023-06-12 23:07:52 +00:00
|
|
|
// TODO: remove this and add an option to the list cmd as we do not store the remote repo list anymore
|
2019-04-06 19:32:14 +00:00
|
|
|
func repoSync(c *cli.Context) error {
|
|
|
|
client, err := internal.NewClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-08-03 00:39:37 +00:00
|
|
|
repos, err := client.RepoListOpts(true)
|
2019-04-06 19:32:14 +00:00
|
|
|
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 14:36:52 +00:00
|
|
|
if err := tmpl.Execute(os.Stdout, repo); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-04-06 19:32:14 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|