2022-08-31 22:36:32 +00:00
|
|
|
package cron
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/common"
|
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/internal"
|
|
|
|
)
|
|
|
|
|
|
|
|
var cronInfoCmd = &cli.Command{
|
|
|
|
Name: "info",
|
2022-11-16 13:58:30 +00:00
|
|
|
Usage: "display info about a cron job",
|
2023-06-12 23:07:52 +00:00
|
|
|
ArgsUsage: "[repo-id|repo-full-name]",
|
2022-08-31 22:36:32 +00:00
|
|
|
Action: cronInfo,
|
|
|
|
Flags: append(common.GlobalFlags,
|
|
|
|
common.RepoFlag,
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "id",
|
|
|
|
Usage: "cron id",
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
common.FormatFlag(tmplCronList, true),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
func cronInfo(c *cli.Context) error {
|
|
|
|
var (
|
2023-06-12 23:07:52 +00:00
|
|
|
jobID = c.Int64("id")
|
|
|
|
repoIDOrFullName = c.String("repository")
|
|
|
|
format = c.String("format") + "\n"
|
2022-08-31 22:36:32 +00:00
|
|
|
)
|
2023-06-12 23:07:52 +00:00
|
|
|
if repoIDOrFullName == "" {
|
|
|
|
repoIDOrFullName = c.Args().First()
|
2022-08-31 22:36:32 +00:00
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
client, err := internal.NewClient(c)
|
2022-08-31 22:36:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
|
2022-08-31 22:36:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
|
|
|
|
cron, err := client.CronGet(repoID, jobID)
|
2022-08-31 22:36:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
tmpl, err := template.New("_").Parse(format)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return tmpl.Execute(os.Stdout, cron)
|
|
|
|
}
|