Skip to content

Commit ac76b33

Browse files
committed
docs: update rest api desc
1 parent 7293d16 commit ac76b33

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

api-docs.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,20 +713,27 @@ definitions:
713713
type: integer
714714
status:
715715
type: string
716-
debug:
717-
type: boolean
718716
playbook:
719717
type: string
720718
environment:
721719
type: string
722720
secret:
723721
type: string
724-
limit:
725-
type: string
726722
git_branch:
727723
type:
728724
- string
729725
- 'null'
726+
params:
727+
type: object
728+
properties:
729+
debug:
730+
type: boolean
731+
dry_run:
732+
type: boolean
733+
diff:
734+
type: boolean
735+
limit:
736+
type: string
730737
message:
731738
type: string
732739

db/Task.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7+
"strings"
78
"time"
89

910
"github.com/semaphoreui/semaphore/pkg/tz"
@@ -74,6 +75,9 @@ type Task struct {
7475
InventoryID *int `db:"inventory_id" json:"inventory_id,omitempty"`
7576

7677
Params MapStringAnyField `db:"params" json:"params,omitempty"`
78+
79+
// Limit is deprecated, use Params.Limit instead
80+
Limit string `db:"hosts_limit" json:"limit"`
7781
}
7882

7983
func (task *Task) FillParams(target interface{}) (err error) {
@@ -85,9 +89,25 @@ func (task *Task) FillParams(target interface{}) (err error) {
8589
return
8690
}
8791

92+
// PreInsert is a hook which is called before inserting task into database.
93+
// Called directly in BoltDB implementation.
8894
func (task *Task) PreInsert(gorp.SqlExecutor) error {
8995
task.Created = tz.In(task.Created)
9096

97+
if _, ok := task.Params["limit"]; !ok {
98+
if task.Params == nil {
99+
task.Params = make(MapStringAnyField)
100+
}
101+
102+
limits := strings.Split(task.Limit, ",")
103+
104+
for i := range limits {
105+
limits[i] = strings.TrimSpace(limits[i])
106+
}
107+
108+
task.Params["limit"] = limits
109+
}
110+
91111
return nil
92112
}
93113

db/bolt/task.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package bolt
22

33
import (
44
"github.com/semaphoreui/semaphore/db"
5-
"github.com/semaphoreui/semaphore/pkg/tz"
65
"go.etcd.io/bbolt"
76
)
87

@@ -90,7 +89,11 @@ func (d *BoltDb) clearTasks(projectID int, templateID int, maxTasks int) {
9089
}
9190

9291
func (d *BoltDb) CreateTask(task db.Task, maxTasks int) (newTask db.Task, err error) {
93-
task.Created = tz.Now()
92+
err = task.PreInsert(nil)
93+
if err != nil {
94+
return
95+
}
96+
9497
task.ID = 0
9598
res, err := d.createObject(0, db.TaskProps, task)
9699
if err != nil {

openapi.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,22 +1556,26 @@ paths:
15561556
properties:
15571557
template_id:
15581558
type: integer
1559-
debug:
1560-
type: boolean
1561-
dry_run:
1562-
type: boolean
1563-
diff:
1564-
type: boolean
15651559
playbook:
15661560
type: string
15671561
environment:
15681562
type: string
1569-
limit:
1570-
type: string
15711563
git_branch:
15721564
type: string
15731565
message:
15741566
type: string
1567+
params:
1568+
type: object
1569+
properties:
1570+
debug:
1571+
type: boolean
1572+
dry_run:
1573+
type: boolean
1574+
diff:
1575+
type: boolean
1576+
limit:
1577+
type: string
1578+
15751579
required: true
15761580
responses:
15771581
'201':

0 commit comments

Comments
 (0)