2019-04-06 19:32:14 +00:00
|
|
|
package build
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-08-09 08:17:39 +00:00
|
|
|
"strconv"
|
2019-04-06 19:32:14 +00:00
|
|
|
|
2021-10-27 19:03:14 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/common"
|
2022-08-09 08:17:39 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/internal"
|
2021-10-27 19:03:14 +00:00
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
2019-04-06 19:32:14 +00:00
|
|
|
)
|
|
|
|
|
2021-10-27 19:03:14 +00:00
|
|
|
var buildLogsCmd = &cli.Command{
|
2019-04-06 19:32:14 +00:00
|
|
|
Name: "logs",
|
|
|
|
Usage: "show build logs",
|
|
|
|
ArgsUsage: "<repo/name> [build] [job]",
|
|
|
|
Action: buildLogs,
|
2021-10-27 19:03:14 +00:00
|
|
|
Flags: common.GlobalFlags,
|
2019-04-06 19:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func buildLogs(c *cli.Context) error {
|
2022-08-09 08:17:39 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
job, err := strconv.Atoi(c.Args().Get(2))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
client, err := internal.NewClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
logs, err := client.BuildLogs(owner, name, number, job)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, log := range logs {
|
|
|
|
fmt.Print(log.Output)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2019-04-06 19:32:14 +00:00
|
|
|
}
|