mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-22 10:08:14 +00:00
Access repos by their ids (#1691)
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
This commit is contained in:
@@ -27,14 +27,18 @@ import (
|
||||
var pipelineApproveCmd = &cli.Command{
|
||||
Name: "approve",
|
||||
Usage: "approve a pipeline",
|
||||
ArgsUsage: "<repo/name> <pipeline>",
|
||||
ArgsUsage: "<repo-id|repo-full-name> <pipeline>",
|
||||
Action: pipelineApprove,
|
||||
Flags: common.GlobalFlags,
|
||||
}
|
||||
|
||||
func pipelineApprove(c *cli.Context) (err error) {
|
||||
repo := c.Args().First()
|
||||
owner, name, err := internal.ParseRepo(repo)
|
||||
repoIDOrFullName := c.Args().First()
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -43,16 +47,11 @@ func pipelineApprove(c *cli.Context) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := internal.NewClient(c)
|
||||
_, err = client.PipelineApprove(repoID, number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = client.PipelineApprove(owner, name, number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Approving pipeline %s/%s#%d\n", owner, name, number)
|
||||
fmt.Printf("Approving pipeline %s#%d\n", repoIDOrFullName, number)
|
||||
return nil
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ import (
|
||||
var pipelineCreateCmd = &cli.Command{
|
||||
Name: "create",
|
||||
Usage: "create new pipeline",
|
||||
ArgsUsage: "<repo/name>",
|
||||
ArgsUsage: "<repo-id|repo-full-name>",
|
||||
Action: pipelineCreate,
|
||||
Flags: append(common.GlobalFlags,
|
||||
common.FormatFlag(tmplPipelineList),
|
||||
@@ -47,14 +47,12 @@ var pipelineCreateCmd = &cli.Command{
|
||||
}
|
||||
|
||||
func pipelineCreate(c *cli.Context) error {
|
||||
repo := c.Args().First()
|
||||
|
||||
owner, name, err := internal.ParseRepo(repo)
|
||||
repoIDOrFullName := c.Args().First()
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := internal.NewClient(c)
|
||||
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -74,7 +72,7 @@ func pipelineCreate(c *cli.Context) error {
|
||||
Variables: variables,
|
||||
}
|
||||
|
||||
pipeline, err := client.PipelineCreate(owner, name, options)
|
||||
pipeline, err := client.PipelineCreate(repoID, options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -27,32 +27,32 @@ import (
|
||||
var pipelineDeclineCmd = &cli.Command{
|
||||
Name: "decline",
|
||||
Usage: "decline a pipeline",
|
||||
ArgsUsage: "<repo/name> <pipeline>",
|
||||
ArgsUsage: "<repo-id|repo-full-name> <pipeline>",
|
||||
Action: pipelineDecline,
|
||||
Flags: common.GlobalFlags,
|
||||
}
|
||||
|
||||
func pipelineDecline(c *cli.Context) (err error) {
|
||||
repo := c.Args().First()
|
||||
owner, name, err := internal.ParseRepo(repo)
|
||||
repoIDOrFullName := c.Args().First()
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
number, err := strconv.Atoi(c.Args().Get(1))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := internal.NewClient(c)
|
||||
_, err = client.PipelineDecline(repoID, number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = client.PipelineDecline(owner, name, number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Declining pipeline %s/%s#%d\n", owner, name, number)
|
||||
fmt.Printf("Declining pipeline %s#%d\n", repoIDOrFullName, number)
|
||||
return nil
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ import (
|
||||
var pipelineInfoCmd = &cli.Command{
|
||||
Name: "info",
|
||||
Usage: "show pipeline details",
|
||||
ArgsUsage: "<repo/name> [pipeline]",
|
||||
ArgsUsage: "<repo-id|repo-full-name> [pipeline]",
|
||||
Action: pipelineInfo,
|
||||
Flags: append(common.GlobalFlags,
|
||||
common.FormatFlag(tmplPipelineInfo),
|
||||
@@ -36,22 +36,21 @@ var pipelineInfoCmd = &cli.Command{
|
||||
}
|
||||
|
||||
func pipelineInfo(c *cli.Context) error {
|
||||
repo := c.Args().First()
|
||||
owner, name, err := internal.ParseRepo(repo)
|
||||
repoIDOrFullName := c.Args().First()
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pipelineArg := c.Args().Get(1)
|
||||
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var number int
|
||||
if pipelineArg == "last" || len(pipelineArg) == 0 {
|
||||
// Fetch the pipeline number from the last pipeline
|
||||
pipeline, err := client.PipelineLast(owner, name, "")
|
||||
pipeline, err := client.PipelineLast(repoID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -63,7 +62,7 @@ func pipelineInfo(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
pipeline, err := client.Pipeline(owner, name, number)
|
||||
pipeline, err := client.Pipeline(repoID, number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -27,33 +27,33 @@ import (
|
||||
var pipelineKillCmd = &cli.Command{
|
||||
Name: "kill",
|
||||
Usage: "force kill a pipeline",
|
||||
ArgsUsage: "<repo/name> <pipeline>",
|
||||
ArgsUsage: "<repo-id|repo-full-name> <pipeline>",
|
||||
Action: pipelineKill,
|
||||
Hidden: true,
|
||||
Flags: common.GlobalFlags,
|
||||
}
|
||||
|
||||
func pipelineKill(c *cli.Context) (err error) {
|
||||
repo := c.Args().First()
|
||||
owner, name, err := internal.ParseRepo(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
number, err := strconv.Atoi(c.Args().Get(1))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
repoIDOrFullName := c.Args().First()
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = client.PipelineKill(owner, name, number)
|
||||
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Force killing pipeline %s/%s#%d\n", owner, name, number)
|
||||
err = client.PipelineKill(repoID, number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Force killing pipeline %s#%d\n", repoIDOrFullName, number)
|
||||
return nil
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ import (
|
||||
var pipelineLastCmd = &cli.Command{
|
||||
Name: "last",
|
||||
Usage: "show latest pipeline details",
|
||||
ArgsUsage: "<repo/name>",
|
||||
ArgsUsage: "<repo-id|repo-full-name>",
|
||||
Action: pipelineLast,
|
||||
Flags: append(common.GlobalFlags,
|
||||
common.FormatFlag(tmplPipelineInfo),
|
||||
@@ -40,18 +40,17 @@ var pipelineLastCmd = &cli.Command{
|
||||
}
|
||||
|
||||
func pipelineLast(c *cli.Context) error {
|
||||
repo := c.Args().First()
|
||||
owner, name, err := internal.ParseRepo(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
repoIDOrFullName := c.Args().First()
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pipeline, err := client.PipelineLast(owner, name, c.String("branch"))
|
||||
pipeline, err := client.PipelineLast(repoID, c.String("branch"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ import (
|
||||
var pipelineListCmd = &cli.Command{
|
||||
Name: "ls",
|
||||
Usage: "show pipeline history",
|
||||
ArgsUsage: "<repo/name>",
|
||||
ArgsUsage: "<repo-id|repo-full-name>",
|
||||
Action: pipelineList,
|
||||
Flags: append(common.GlobalFlags,
|
||||
common.FormatFlag(tmplPipelineList),
|
||||
@@ -52,18 +52,17 @@ var pipelineListCmd = &cli.Command{
|
||||
}
|
||||
|
||||
func pipelineList(c *cli.Context) error {
|
||||
repo := c.Args().First()
|
||||
owner, name, err := internal.ParseRepo(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
repoIDOrFullName := c.Args().First()
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pipelines, err := client.PipelineList(owner, name)
|
||||
pipelines, err := client.PipelineList(repoID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -101,7 +100,7 @@ func pipelineList(c *cli.Context) error {
|
||||
}
|
||||
|
||||
// template for pipeline list information
|
||||
var tmplPipelineList = "\x1b[33mBuild #{{ .Number }} \x1b[0m" + `
|
||||
var tmplPipelineList = "\x1b[33mPipeline #{{ .Number }} \x1b[0m" + `
|
||||
Status: {{ .Status }}
|
||||
Event: {{ .Event }}
|
||||
Commit: {{ .Commit }}
|
||||
|
@@ -27,14 +27,18 @@ import (
|
||||
var pipelineLogsCmd = &cli.Command{
|
||||
Name: "logs",
|
||||
Usage: "show pipeline logs",
|
||||
ArgsUsage: "<repo/name> [pipeline] [stepID]",
|
||||
ArgsUsage: "<repo-id|repo-full-name> [pipeline] [stepID]",
|
||||
Action: pipelineLogs,
|
||||
Flags: common.GlobalFlags,
|
||||
}
|
||||
|
||||
func pipelineLogs(c *cli.Context) error {
|
||||
repo := c.Args().First()
|
||||
owner, name, err := internal.ParseRepo(repo)
|
||||
repoIDOrFullName := c.Args().First()
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -49,12 +53,7 @@ func pipelineLogs(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logs, err := client.StepLogEntries(owner, name, number, step)
|
||||
logs, err := client.StepLogEntries(repoID, number, step)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ import (
|
||||
var pipelinePsCmd = &cli.Command{
|
||||
Name: "ps",
|
||||
Usage: "show pipeline steps",
|
||||
ArgsUsage: "<repo/name> [pipeline]",
|
||||
ArgsUsage: "<repo-id|repo-full-name> [pipeline]",
|
||||
Action: pipelinePs,
|
||||
Flags: append(common.GlobalFlags,
|
||||
common.FormatFlag(tmplPipelinePs),
|
||||
@@ -36,14 +36,12 @@ var pipelinePsCmd = &cli.Command{
|
||||
}
|
||||
|
||||
func pipelinePs(c *cli.Context) error {
|
||||
repo := c.Args().First()
|
||||
|
||||
owner, name, err := internal.ParseRepo(repo)
|
||||
repoIDOrFullName := c.Args().First()
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := internal.NewClient(c)
|
||||
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -53,7 +51,7 @@ func pipelinePs(c *cli.Context) error {
|
||||
|
||||
if pipelineArg == "last" || len(pipelineArg) == 0 {
|
||||
// Fetch the pipeline number from the last pipeline
|
||||
pipeline, err := client.PipelineLast(owner, name, "")
|
||||
pipeline, err := client.PipelineLast(repoID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -66,7 +64,7 @@ func pipelinePs(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
pipeline, err := client.Pipeline(owner, name, number)
|
||||
pipeline, err := client.Pipeline(repoID, number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ import (
|
||||
var pipelineStartCmd = &cli.Command{
|
||||
Name: "start",
|
||||
Usage: "start a pipeline",
|
||||
ArgsUsage: "<repo/name> [pipeline]",
|
||||
ArgsUsage: "<repo-id|repo-full-name> [pipeline]",
|
||||
Action: pipelineStart,
|
||||
Flags: append(common.GlobalFlags,
|
||||
&cli.StringSliceFlag{
|
||||
@@ -40,13 +40,12 @@ var pipelineStartCmd = &cli.Command{
|
||||
}
|
||||
|
||||
func pipelineStart(c *cli.Context) (err error) {
|
||||
repo := c.Args().First()
|
||||
owner, name, err := internal.ParseRepo(repo)
|
||||
repoIDOrFullName := c.Args().First()
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := internal.NewClient(c)
|
||||
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -55,7 +54,7 @@ func pipelineStart(c *cli.Context) (err error) {
|
||||
var number int
|
||||
if pipelineArg == "last" {
|
||||
// Fetch the pipeline number from the last pipeline
|
||||
pipeline, err := client.PipelineLast(owner, name, "")
|
||||
pipeline, err := client.PipelineLast(repoID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -72,11 +71,11 @@ func pipelineStart(c *cli.Context) (err error) {
|
||||
|
||||
params := internal.ParseKeyPair(c.StringSlice("param"))
|
||||
|
||||
pipeline, err := client.PipelineStart(owner, name, number, params)
|
||||
pipeline, err := client.PipelineStart(repoID, number, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Starting pipeline %s/%s#%d\n", owner, name, pipeline.Number)
|
||||
fmt.Printf("Starting pipeline %s#%d\n", repoIDOrFullName, pipeline.Number)
|
||||
return nil
|
||||
}
|
||||
|
@@ -27,14 +27,18 @@ import (
|
||||
var pipelineStopCmd = &cli.Command{
|
||||
Name: "stop",
|
||||
Usage: "stop a pipeline",
|
||||
ArgsUsage: "<repo/name> [pipeline]",
|
||||
ArgsUsage: "<repo-id|repo-full-name> [pipeline]",
|
||||
Flags: common.GlobalFlags,
|
||||
Action: pipelineStop,
|
||||
}
|
||||
|
||||
func pipelineStop(c *cli.Context) (err error) {
|
||||
repo := c.Args().First()
|
||||
owner, name, err := internal.ParseRepo(repo)
|
||||
repoIDOrFullName := c.Args().First()
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -43,16 +47,11 @@ func pipelineStop(c *cli.Context) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := internal.NewClient(c)
|
||||
err = client.PipelineStop(repoID, number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = client.PipelineStop(owner, name, number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Stopping pipeline %s/%s#%d\n", owner, name, number)
|
||||
fmt.Printf("Stopping pipeline %s#%d\n", repoIDOrFullName, number)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user