2019-04-06 21:32:14 +02:00
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-06-13 01:07:52 +02:00
|
|
|
"strconv"
|
2019-04-06 21:32:14 +02:00
|
|
|
|
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 repoAddCmd = &cli.Command{
|
2019-04-06 21:32:14 +02:00
|
|
|
Name: "add",
|
|
|
|
Usage: "add a repository",
|
2023-06-13 01:07:52 +02:00
|
|
|
ArgsUsage: "<forge-remote-id>",
|
2019-04-06 21:32:14 +02:00
|
|
|
Action: repoAdd,
|
2021-10-27 21:03:14 +02:00
|
|
|
Flags: common.GlobalFlags,
|
2019-04-06 21:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func repoAdd(c *cli.Context) error {
|
2023-06-13 01:07:52 +02:00
|
|
|
_forgeRemoteID := c.Args().First()
|
|
|
|
forgeRemoteID, err := strconv.Atoi(_forgeRemoteID)
|
2019-04-06 21:32:14 +02:00
|
|
|
if err != nil {
|
2023-06-13 01:07:52 +02:00
|
|
|
return fmt.Errorf("invalid forge remote id: %s", _forgeRemoteID)
|
2019-04-06 21:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
client, err := internal.NewClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-06-13 01:07:52 +02:00
|
|
|
repo, err := client.RepoPost(int64(forgeRemoteID))
|
|
|
|
if err != nil {
|
2019-04-06 21:32:14 +02:00
|
|
|
return err
|
|
|
|
}
|
2023-06-13 01:07:52 +02:00
|
|
|
|
|
|
|
fmt.Printf("Successfully activated repository with forge remote %s\n", repo.FullName)
|
2019-04-06 21:32:14 +02:00
|
|
|
return nil
|
|
|
|
}
|