Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cron jobs #934

Merged
merged 77 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
bbe2123
draft-00.0.0.1
6543 Jun 15, 2022
47b2654
Start: dev ... [storage]: draft interface and implement lock mechanism
6543 Jun 15, 2022
79c6503
[store] clean and implement
6543 Jun 1, 2022
1962d1a
do TestCronList
6543 Jun 1, 2022
d2e4fd8
add "github.com/robfig/cron"
6543 Jun 1, 2022
a7a49a2
implement core
6543 Jun 1, 2022
20012c6
make build & more
6543 Jun 1, 2022
db02291
more const
6543 Jun 1, 2022
c947962
start code move
6543 Jun 15, 2022
ea91757
connect
6543 Jun 2, 2022
5d7e3fe
Merge remote-tracking branch 'upstream/master' into cron
anbraten Jul 11, 2022
151b481
remove vendor folder
anbraten Jul 11, 2022
a13efbd
add api and ui for crons
anbraten Jul 11, 2022
a85242d
Merge pull request #1 from anbraten/cron
6543 Jul 17, 2022
1b79a63
Merge branch 'master' into add-cron-jobs
6543 Jul 17, 2022
4441ee6
Merge branch 'master' into add-cron-jobs
6543 Aug 15, 2022
202e387
Merge branch 'master' into add-cron-jobs
6543 Aug 25, 2022
e9afa4a
let it run
6543 Aug 25, 2022
6a4ec2e
yes now (we) can
6543 Aug 25, 2022
88af950
implement sha from branch fetcher
6543 Aug 25, 2022
3587046
fix mock
6543 Aug 25, 2022
2faa774
Merge branch 'master' into add-cron-jobs
anbraten Aug 27, 2022
f0d29c8
make branch optional in UI
anbraten Aug 27, 2022
6cfe6a7
backend: branch fallback
6543 Aug 27, 2022
1e6dd99
Update server/api/cron_job.go
6543 Aug 27, 2022
71dc72c
cron builds dont have a sender
6543 Aug 27, 2022
83f8dde
update remote.BranchCommit() desc
6543 Aug 27, 2022
dbdb7ae
github: use helper func
6543 Aug 27, 2022
26a1159
update web/components.d.ts
6543 Aug 27, 2022
c67049c
update client sdk
6543 Aug 27, 2022
98e9947
cli: draft1
6543 Aug 27, 2022
0cc443b
dont run on insert but calc nextExec
6543 Aug 27, 2022
47a9aa4
cli: refactor nit
6543 Aug 27, 2022
d7ec575
filters ...
6543 Aug 27, 2022
25ae507
use icon as avatar for cron jobs
anbraten Aug 27, 2022
82d1531
ad utc hint
anbraten Aug 27, 2022
18f3832
Merge branch 'master' into add-cron-jobs
anbraten Aug 27, 2022
02abb7e
allow secrets in cron jobs
6543 Aug 27, 2022
67468b4
Makefile: fix vendor target
6543 Aug 27, 2022
752346b
Update TestConstraints to respect default event filter
6543 Aug 27, 2022
11164e3
make code more redable
6543 Aug 27, 2022
39929a2
handle default constraint on Empty Constrains
6543 Aug 27, 2022
2e88aab
fix lint issues
6543 Aug 27, 2022
aa0611d
add test for 39929a284a5338cff5bfc7a3d096bd8135341ed8
6543 Aug 27, 2022
33269f3
fix unit test
6543 Aug 27, 2022
b4f61b8
Apply suggestions from code review
6543 Aug 28, 2022
f07cc1d
Merge branch 'master' into add-cron-jobs
6543 Aug 29, 2022
d01e54e
rename "Title" to "Name"
6543 Aug 29, 2022
88a2c37
fix more lint issues
6543 Aug 29, 2022
dc95744
add (1138) as todo ref
6543 Aug 29, 2022
64d6371
schema: use definition
6543 Aug 29, 2022
586a150
dedup metadataFromStruct and add extra field for cron name int metadata
6543 Aug 29, 2022
25261d1
explicit
6543 Aug 29, 2022
5761699
prettyRef for cron
6543 Aug 29, 2022
96d08ef
schema: add def "constraint_list" to match actual behavior of when pr…
6543 Aug 29, 2022
d576643
right highliting & add cron filter
6543 Aug 29, 2022
12cb498
mention default filter
6543 Aug 29, 2022
bf48d08
make it a warning
6543 Aug 29, 2022
d893484
add new docs section for cron
6543 Aug 29, 2022
9383c93
Apply suggestions from code review
6543 Aug 29, 2022
b5963fa
Apply suggestions from code review
6543 Aug 29, 2022
2844f2c
Merge branch 'master' into add-cron-jobs
anbraten Aug 29, 2022
02c44f9
Merge branch 'master' into add-cron-jobs
6543 Aug 29, 2022
c8dc4df
rename cron-job to cron and BranchCommit to BranchHead and nits
anbraten Aug 30, 2022
be0eb6e
Apply suggestions from code review
6543 Aug 30, 2022
320c69d
Update server/model/cron.go
6543 Aug 30, 2022
fdfa4f4
Merge branch 'master' into add-cron-jobs
6543 Aug 30, 2022
46dbddb
use UTC for now
6543 Aug 31, 2022
b87d088
Merge branch 'master' into add-cron-jobs
6543 Aug 31, 2022
ac1a551
Apply suggestions from code review
6543 Aug 31, 2022
a49ca5f
Apply suggestions from code review
6543 Aug 31, 2022
2be0c47
fix
6543 Aug 31, 2022
0a36937
tiny renamings
anbraten Aug 31, 2022
4e5c1c4
Update server/model/build.go
anbraten Aug 31, 2022
8eed2b0
fix; rename; add unit tests
6543 Aug 31, 2022
e5c7836
fix
6543 Aug 31, 2022
358384f
allow to change cron name
anbraten Aug 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cli/cron/cron.go
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,
},
}
72 changes: 72 additions & 0 deletions cli/cron/cron_add.go
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)
}
55 changes: 55 additions & 0 deletions cli/cron/cron_info.go
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)
}
62 changes: 62 additions & 0 deletions cli/cron/cron_list.go
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 }}
`
50 changes: 50 additions & 0 deletions cli/cron/cron_rm.go
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
}
77 changes: 77 additions & 0 deletions cli/cron/cron_update.go
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)
}
5 changes: 1 addition & 4 deletions cli/secret/secret_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ var secretCreateCmd = &cli.Command{
Name: "organization",
Usage: "organization name (e.g. octocat)",
},
&cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
common.RepoFlag,
&cli.StringFlag{
Name: "name",
Usage: "secret name",
Expand Down
5 changes: 1 addition & 4 deletions cli/secret/secret_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ var secretInfoCmd = &cli.Command{
Name: "organization",
Usage: "organization name (e.g. octocat)",
},
&cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
common.RepoFlag,
&cli.StringFlag{
Name: "name",
Usage: "secret name",
Expand Down
5 changes: 1 addition & 4 deletions cli/secret/secret_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ var secretListCmd = &cli.Command{
Name: "organization",
Usage: "organization name (e.g. octocat)",
},
&cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
common.RepoFlag,
common.FormatFlag(tmplSecretList, true),
),
}
Expand Down
5 changes: 1 addition & 4 deletions cli/secret/secret_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ var secretDeleteCmd = &cli.Command{
Name: "organization",
Usage: "organization name (e.g. octocat)",
},
&cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
common.RepoFlag,
&cli.StringFlag{
Name: "name",
Usage: "secret name",
Expand Down
Loading