mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 10:21:00 +00:00
798c2bc8b2
* migrate urfave/ci v1 -> v2 * refactor cli (format flag) * log error if agent can not listen on port 3000 close #452
105 lines
2.3 KiB
Go
105 lines
2.3 KiB
Go
package repo
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/common"
|
|
"github.com/woodpecker-ci/woodpecker/cli/internal"
|
|
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
|
)
|
|
|
|
var repoUpdateCmd = &cli.Command{
|
|
Name: "update",
|
|
Usage: "update a repository",
|
|
ArgsUsage: "<repo/name>",
|
|
Action: repoUpdate,
|
|
Flags: append(common.GlobalFlags,
|
|
&cli.BoolFlag{
|
|
Name: "trusted",
|
|
Usage: "repository is trusted",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "gated",
|
|
Usage: "repository is gated",
|
|
},
|
|
&cli.DurationFlag{
|
|
Name: "timeout",
|
|
Usage: "repository timeout",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "visibility",
|
|
Usage: "repository visibility",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "config",
|
|
Usage: "repository configuration path (e.g. .woodpecker.yml)",
|
|
},
|
|
&cli.IntFlag{
|
|
Name: "build-counter",
|
|
Usage: "repository starting build number",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "unsafe",
|
|
Usage: "validate updating the build-counter is unsafe",
|
|
},
|
|
),
|
|
}
|
|
|
|
func repoUpdate(c *cli.Context) error {
|
|
repo := c.Args().First()
|
|
owner, name, err := internal.ParseRepo(repo)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
client, err := internal.NewClient(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var (
|
|
visibility = c.String("visibility")
|
|
config = c.String("config")
|
|
timeout = c.Duration("timeout")
|
|
trusted = c.Bool("trusted")
|
|
gated = c.Bool("gated")
|
|
buildCounter = c.Int("build-counter")
|
|
unsafe = c.Bool("unsafe")
|
|
)
|
|
|
|
patch := new(woodpecker.RepoPatch)
|
|
if c.IsSet("trusted") {
|
|
patch.IsTrusted = &trusted
|
|
}
|
|
if c.IsSet("gated") {
|
|
patch.IsGated = &gated
|
|
}
|
|
if c.IsSet("timeout") {
|
|
v := int64(timeout / time.Minute)
|
|
patch.Timeout = &v
|
|
}
|
|
if c.IsSet("config") {
|
|
patch.Config = &config
|
|
}
|
|
if c.IsSet("visibility") {
|
|
switch visibility {
|
|
case "public", "private", "internal":
|
|
patch.Visibility = &visibility
|
|
}
|
|
}
|
|
if c.IsSet("build-counter") && !unsafe {
|
|
fmt.Printf("Setting the build counter is an unsafe operation that could put your repository in an inconsistent state. Please use --unsafe to proceed")
|
|
}
|
|
if c.IsSet("build-counter") && unsafe {
|
|
patch.BuildCounter = &buildCounter
|
|
}
|
|
|
|
if _, err := client.RepoPatch(owner, name, patch); err != nil {
|
|
return err
|
|
}
|
|
fmt.Printf("Successfully updated repository %s/%s\n", owner, name)
|
|
return nil
|
|
}
|