From 4f8fe1a19fa89a271e7e03ef6b50740d6364f988 Mon Sep 17 00:00:00 2001 From: Andy Royle Date: Tue, 15 Nov 2022 10:02:12 +0000 Subject: [PATCH] bug: fix scheduler parameters to support bools and numbers --- api/schedule.go | 18 +++++++++--------- api/schedule_rest.go | 28 ++++++++++++++-------------- api/schedule_test.go | 3 ++- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/api/schedule.go b/api/schedule.go index 9452195b1..3ed8687f0 100644 --- a/api/schedule.go +++ b/api/schedule.go @@ -17,15 +17,15 @@ type Actor struct { } type Schedule struct { - ID string `json:"id"` - ProjectSlug string `json:"project-slug"` - Name string `json:"name"` - Description string `json:"description,omitempty"` - Timetable Timetable `json:"timetable"` - Actor Actor `json:"actor"` - Parameters map[string]string `json:"parameters"` - CreatedAt time.Time `json:"created-at"` - UpdatedAt time.Time `json:"updated-at"` + ID string `json:"id"` + ProjectSlug string `json:"project-slug"` + Name string `json:"name"` + Description string `json:"description,omitempty"` + Timetable Timetable `json:"timetable"` + Actor Actor `json:"actor"` + Parameters map[string]interface{} `json:"parameters"` + CreatedAt time.Time `json:"created-at"` + UpdatedAt time.Time `json:"updated-at"` } type ScheduleInterface interface { diff --git a/api/schedule_rest.go b/api/schedule_rest.go index 6b35d700f..6abe469b4 100644 --- a/api/schedule_rest.go +++ b/api/schedule_rest.go @@ -36,7 +36,7 @@ type listSchedulesParams struct { // Creates a new schedule in the supplied project. func (c *ScheduleRestClient) CreateSchedule(vcs, org, project, name, description string, - useSchedulingSystem bool, timetable Timetable, parameters map[string]string) (*Schedule, error) { + useSchedulingSystem bool, timetable Timetable, parameters map[string]interface{}) (*Schedule, error) { req, err := c.newCreateScheduleRequest(vcs, org, project, name, description, useSchedulingSystem, timetable, parameters) if err != nil { @@ -73,7 +73,7 @@ func (c *ScheduleRestClient) CreateSchedule(vcs, org, project, name, description // Updates an existing schedule. func (c *ScheduleRestClient) UpdateSchedule(scheduleID, name, description string, - useSchedulingSystem bool, timetable Timetable, parameters map[string]string) (*Schedule, error) { + useSchedulingSystem bool, timetable Timetable, parameters map[string]interface{}) (*Schedule, error) { req, err := c.newUpdateScheduleRequest(scheduleID, name, description, useSchedulingSystem, timetable, parameters) if err != nil { @@ -273,7 +273,7 @@ func (c *ScheduleRestClient) newGetScheduleRequest(scheduleID string) (*http.Req // Builds a request to create a new schedule. func (c *ScheduleRestClient) newCreateScheduleRequest(vcs, org, project, name, description string, - useSchedulingSystem bool, timetable Timetable, parameters map[string]string) (*http.Request, error) { + useSchedulingSystem bool, timetable Timetable, parameters map[string]interface{}) (*http.Request, error) { var err error queryURL, err := url.Parse(c.server) @@ -293,11 +293,11 @@ func (c *ScheduleRestClient) newCreateScheduleRequest(vcs, org, project, name, d var bodyReader io.Reader var body = struct { - Name string `json:"name"` - Description string `json:"description,omitempty"` - AttributionActor string `json:"attribution-actor"` - Parameters map[string]string `json:"parameters"` - Timetable Timetable `json:"timetable"` + Name string `json:"name"` + Description string `json:"description,omitempty"` + AttributionActor string `json:"attribution-actor"` + Parameters map[string]interface{} `json:"parameters"` + Timetable Timetable `json:"timetable"` }{ Name: name, Description: description, @@ -318,7 +318,7 @@ func (c *ScheduleRestClient) newCreateScheduleRequest(vcs, org, project, name, d // Builds a request to update an existing schedule. func (c *ScheduleRestClient) newUpdateScheduleRequest(scheduleID, name, description string, - useSchedulingSystem bool, timetable Timetable, parameters map[string]string) (*http.Request, error) { + useSchedulingSystem bool, timetable Timetable, parameters map[string]interface{}) (*http.Request, error) { var err error queryURL, err := url.Parse(c.server) @@ -338,11 +338,11 @@ func (c *ScheduleRestClient) newUpdateScheduleRequest(scheduleID, name, descript var bodyReader io.Reader var body = struct { - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - AttributionActor string `json:"attribution-actor,omitempty"` - Parameters map[string]string `json:"parameters,omitempty"` - Timetable Timetable `json:"timetable,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + AttributionActor string `json:"attribution-actor,omitempty"` + Parameters map[string]interface{} `json:"parameters,omitempty"` + Timetable Timetable `json:"timetable,omitempty"` }{ Name: name, Description: description, diff --git a/api/schedule_test.go b/api/schedule_test.go index c046b4321..2fbcf3d50 100644 --- a/api/schedule_test.go +++ b/api/schedule_test.go @@ -28,8 +28,9 @@ func mockSchedule() Schedule { Login: "test-actor", Name: "T. Actor", }, - Parameters: map[string]string{ + Parameters: map[string]interface{}{ "test": "parameter", + "bool": true, }, } }