-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://woodpecker-ci.org/docs/usage/cron Co-authored-by: Anbraten <anton@ju60.de> Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
- Loading branch information
1 parent
65587e3
commit 383f273
Showing
63 changed files
with
1,604 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cron | ||
|
||
import ( | ||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/woodpecker-ci/woodpecker/cli/common" | ||
) | ||
|
||
// Command exports the cron command set. | ||
var Command = &cli.Command{ | ||
Name: "cron", | ||
Usage: "manage cron jobs", | ||
Flags: common.GlobalFlags, | ||
Subcommands: []*cli.Command{ | ||
cronCreateCmd, | ||
cronDeleteCmd, | ||
cronUpdateCmd, | ||
cronInfoCmd, | ||
cronListCmd, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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" | ||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker" | ||
) | ||
|
||
var cronCreateCmd = &cli.Command{ | ||
Name: "add", | ||
Usage: "adds a cron", | ||
ArgsUsage: "[repo/name]", | ||
Action: cronCreate, | ||
Flags: append(common.GlobalFlags, | ||
common.RepoFlag, | ||
&cli.StringFlag{ | ||
Name: "name", | ||
Usage: "cron name", | ||
Required: true, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "branch", | ||
Usage: "cron branch", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "schedule", | ||
Usage: "cron schedule", | ||
Required: true, | ||
}, | ||
common.FormatFlag(tmplCronList, true), | ||
), | ||
} | ||
|
||
func cronCreate(c *cli.Context) error { | ||
var ( | ||
jobName = c.String("name") | ||
branch = c.String("branch") | ||
schedule = c.String("schedule") | ||
reponame = c.String("repository") | ||
format = c.String("format") + "\n" | ||
) | ||
if reponame == "" { | ||
reponame = c.Args().First() | ||
} | ||
owner, name, err := internal.ParseRepo(reponame) | ||
if err != nil { | ||
return err | ||
} | ||
client, err := internal.NewClient(c) | ||
if err != nil { | ||
return err | ||
} | ||
cron := &woodpecker.Cron{ | ||
Name: jobName, | ||
Branch: branch, | ||
Schedule: schedule, | ||
} | ||
cron, err = client.CronCreate(owner, name, cron) | ||
if err != nil { | ||
return err | ||
} | ||
tmpl, err := template.New("_").Parse(format) | ||
if err != nil { | ||
return err | ||
} | ||
return tmpl.Execute(os.Stdout, cron) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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", | ||
Usage: "display cron info", | ||
ArgsUsage: "[repo/name]", | ||
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 ( | ||
jobID = c.Int64("id") | ||
reponame = c.String("repository") | ||
format = c.String("format") + "\n" | ||
) | ||
if reponame == "" { | ||
reponame = c.Args().First() | ||
} | ||
owner, name, err := internal.ParseRepo(reponame) | ||
if err != nil { | ||
return err | ||
} | ||
client, err := internal.NewClient(c) | ||
if err != nil { | ||
return err | ||
} | ||
cron, err := client.CronGet(owner, name, jobID) | ||
if err != nil { | ||
return err | ||
} | ||
tmpl, err := template.New("_").Parse(format) | ||
if err != nil { | ||
return err | ||
} | ||
return tmpl.Execute(os.Stdout, cron) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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 cronListCmd = &cli.Command{ | ||
Name: "ls", | ||
Usage: "list registries", | ||
ArgsUsage: "[repo/name]", | ||
Action: cronList, | ||
Flags: append(common.GlobalFlags, | ||
common.RepoFlag, | ||
common.FormatFlag(tmplCronList, true), | ||
), | ||
} | ||
|
||
func cronList(c *cli.Context) error { | ||
var ( | ||
format = c.String("format") + "\n" | ||
reponame = c.String("repository") | ||
) | ||
if reponame == "" { | ||
reponame = c.Args().First() | ||
} | ||
owner, name, err := internal.ParseRepo(reponame) | ||
if err != nil { | ||
return err | ||
} | ||
client, err := internal.NewClient(c) | ||
if err != nil { | ||
return err | ||
} | ||
list, err := client.CronList(owner, name) | ||
if err != nil { | ||
return err | ||
} | ||
tmpl, err := template.New("_").Parse(format) | ||
if err != nil { | ||
return err | ||
} | ||
for _, cron := range list { | ||
if err := tmpl.Execute(os.Stdout, cron); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// template for build list information | ||
var tmplCronList = "\x1b[33m{{ .Name }} \x1b[0m" + ` | ||
ID: {{ .ID }} | ||
Branch: {{ .Branch }} | ||
Schedule: {{ .Schedule }} | ||
NextExec: {{ .NextExec }} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cron | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/woodpecker-ci/woodpecker/cli/common" | ||
"github.com/woodpecker-ci/woodpecker/cli/internal" | ||
) | ||
|
||
var cronDeleteCmd = &cli.Command{ | ||
Name: "rm", | ||
Usage: "remove a cron", | ||
ArgsUsage: "[repo/name]", | ||
Action: cronDelete, | ||
Flags: append(common.GlobalFlags, | ||
common.RepoFlag, | ||
&cli.StringFlag{ | ||
Name: "id", | ||
Usage: "cron id", | ||
Required: true, | ||
}, | ||
), | ||
} | ||
|
||
func cronDelete(c *cli.Context) error { | ||
var ( | ||
jobID = c.Int64("id") | ||
reponame = c.String("repository") | ||
) | ||
if reponame == "" { | ||
reponame = c.Args().First() | ||
} | ||
owner, name, err := internal.ParseRepo(reponame) | ||
if err != nil { | ||
return err | ||
} | ||
client, err := internal.NewClient(c) | ||
if err != nil { | ||
return err | ||
} | ||
err = client.CronDelete(owner, name, jobID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println("Success") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
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" | ||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker" | ||
) | ||
|
||
var cronUpdateCmd = &cli.Command{ | ||
Name: "update", | ||
Usage: "update a cron", | ||
ArgsUsage: "[repo/name]", | ||
Action: cronUpdate, | ||
Flags: append(common.GlobalFlags, | ||
common.RepoFlag, | ||
&cli.StringFlag{ | ||
Name: "id", | ||
Usage: "cron id", | ||
Required: true, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "name", | ||
Usage: "cron name", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "branch", | ||
Usage: "cron branch", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "schedule", | ||
Usage: "cron schedule", | ||
}, | ||
common.FormatFlag(tmplCronList, true), | ||
), | ||
} | ||
|
||
func cronUpdate(c *cli.Context) error { | ||
var ( | ||
reponame = c.String("repository") | ||
jobID = c.Int64("id") | ||
jobName = c.String("name") | ||
branch = c.String("branch") | ||
schedule = c.String("schedule") | ||
format = c.String("format") + "\n" | ||
) | ||
if reponame == "" { | ||
reponame = c.Args().First() | ||
} | ||
owner, name, err := internal.ParseRepo(reponame) | ||
if err != nil { | ||
return err | ||
} | ||
client, err := internal.NewClient(c) | ||
if err != nil { | ||
return err | ||
} | ||
cron := &woodpecker.Cron{ | ||
ID: jobID, | ||
Name: jobName, | ||
Branch: branch, | ||
Schedule: schedule, | ||
} | ||
cron, err = client.CronUpdate(owner, name, cron) | ||
if err != nil { | ||
return err | ||
} | ||
tmpl, err := template.New("_").Parse(format) | ||
if err != nil { | ||
return err | ||
} | ||
return tmpl.Execute(os.Stdout, cron) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.