Get default branch and show message in pipeline list (#3867)

This commit is contained in:
Anbraten 2024-07-03 15:58:51 +02:00 committed by GitHub
parent 28e982fffb
commit 38b8a55714
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 11 deletions

View file

@ -30,7 +30,7 @@ import (
// Command exports the deploy command. // Command exports the deploy command.
var Command = &cli.Command{ var Command = &cli.Command{
Name: "deploy", Name: "deploy",
Usage: "deploy code", Usage: "trigger a pipeline with the 'deployment' event",
ArgsUsage: "<repo-id|repo-full-name> <pipeline> <environment>", ArgsUsage: "<repo-id|repo-full-name> <pipeline> <environment>",
Action: deploy, Action: deploy,
Flags: []cli.Flag{ Flags: []cli.Flag{
@ -38,7 +38,6 @@ var Command = &cli.Command{
&cli.StringFlag{ &cli.StringFlag{
Name: "branch", Name: "branch",
Usage: "branch filter", Usage: "branch filter",
Value: "main",
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "event", Name: "event",
@ -74,6 +73,15 @@ func deploy(c *cli.Context) error {
event := c.String("event") event := c.String("event")
status := c.String("status") status := c.String("status")
if branch == "" {
repo, err := client.Repo(repoID)
if err != nil {
return err
}
branch = repo.DefaultBranch
}
pipelineArg := c.Args().Get(1) pipelineArg := c.Args().Get(1)
var number int64 var number int64
if pipelineArg == "last" { if pipelineArg == "last" {

View file

@ -77,7 +77,7 @@ func pipelineOutput(c *cli.Context, resources []woodpecker.Pipeline, fd ...io.Wr
fallthrough fallthrough
default: default:
table := output.NewTable(out) table := output.NewTable(out)
cols := []string{"Number", "Status", "Event", "Branch", "Commit", "Author"} cols := []string{"Number", "Status", "Event", "Branch", "Message", "Author"}
if len(outOpt) > 0 { if len(outOpt) > 0 {
cols = outOpt cols = outOpt

View file

@ -22,7 +22,7 @@ func TestPipelineOutput(t *testing.T) {
{ {
name: "table output with default columns", name: "table output with default columns",
args: []string{}, args: []string{},
expected: "NUMBER STATUS EVENT BRANCH COMMIT AUTHOR\n1 success push main abcdef John Doe\n", expected: "NUMBER STATUS EVENT BRANCH MESSAGE AUTHOR\n1 success push main message John Doe\n",
}, },
{ {
name: "table output with custom columns", name: "table output with custom columns",
@ -32,7 +32,7 @@ func TestPipelineOutput(t *testing.T) {
{ {
name: "table output with no header", name: "table output with no header",
args: []string{"output", "--output-no-headers"}, args: []string{"output", "--output-no-headers"},
expected: "1 success push main abcdef John Doe\n", expected: "1 success push main message John Doe\n",
}, },
{ {
name: "go-template output", name: "go-template output",
@ -48,12 +48,12 @@ func TestPipelineOutput(t *testing.T) {
pipelines := []woodpecker.Pipeline{ pipelines := []woodpecker.Pipeline{
{ {
Number: 1, Number: 1,
Status: "success", Status: "success",
Event: "push", Event: "push",
Branch: "main", Branch: "main",
Commit: "abcdef", Message: "message",
Author: "John Doe", Author: "John Doe",
}, },
} }