From b87d71b6f361ee5cf7b1dc3a2509933c9c4a9fbe Mon Sep 17 00:00:00 2001 From: curzola pierre Date: Tue, 16 Feb 2021 15:42:16 +0100 Subject: [PATCH 1/2] Add named constants to deployment stream event --- deployments.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/deployments.go b/deployments.go index 14831bb6..149e81b5 100644 --- a/deployments.go +++ b/deployments.go @@ -50,6 +50,22 @@ type Deployment struct { Links *DeploymentLinks `json:"links"` } +// DeploymentEventStatus hold all different kind of event handled by deployment stream +type DeploymentEventStatus string + +const ( + EventKeepalive DeploymentEventStatus = "ping" + EventNew DeploymentEventStatus = "new" + EventLog DeploymentEventStatus = "log" + EventStatus DeploymentEventStatus = "status" +) + +type DeployEvent struct { + ID string `json:"id"` + Type DeploymentEventStatus `json:"type"` + Data json.RawMessage `json:"data"` +} + type DeploymentsCreateParams struct { GitRef *string `json:"git_ref"` SourceURL string `json:"source_url"` From 087ecf5162eafa7229a1f6f9bec779163d4ddbb9 Mon Sep 17 00:00:00 2001 From: Jonathan Hurter Date: Tue, 16 Feb 2021 18:10:12 +0100 Subject: [PATCH 2/2] Add DeploymentEventData* and fix comments --- CHANGELOG.md | 2 ++ deployments.go | 23 ++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edb3944c..b94ebfba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## To Be Released +* Add `DeployEvent` structure which represents a deployment stream event sent on the websocket [#200](https://github.com/Scalingo/go-scalingo/pull/200) + ## 4.10.0 * Remove headers from `Request` of `http.parseJSON` returned error diff --git a/deployments.go b/deployments.go index 149e81b5..bd861d11 100644 --- a/deployments.go +++ b/deployments.go @@ -50,22 +50,34 @@ type Deployment struct { Links *DeploymentLinks `json:"links"` } -// DeploymentEventStatus hold all different kind of event handled by deployment stream +// DeploymentEventStatus holds all different deployment stream types of event. type DeploymentEventStatus string const ( - EventKeepalive DeploymentEventStatus = "ping" - EventNew DeploymentEventStatus = "new" - EventLog DeploymentEventStatus = "log" - EventStatus DeploymentEventStatus = "status" + EventPing DeploymentEventStatus = "ping" + EventNew DeploymentEventStatus = "new" + EventLog DeploymentEventStatus = "log" + EventStatus DeploymentEventStatus = "status" ) +// DeployEvent represents a deployment stream event sent on the websocket. type DeployEvent struct { + // ID of the deployment which this event belongs to ID string `json:"id"` Type DeploymentEventStatus `json:"type"` Data json.RawMessage `json:"data"` } +// DeployEventDataLog is the data type present in the DeployEvent.Data field if the DeployEvent.Type is EventLog +type DeployEventDataLog struct { + Content string `json:"content"` +} + +// DeployEventDataStatus is the data type present in the DeployEvent.Data field if the DeployEvent.Type is EventStatus +type DeployEventDataStatus struct { + Status string `json:"Status"` +} + type DeploymentsCreateParams struct { GitRef *string `json:"git_ref"` SourceURL string `json:"source_url"` @@ -156,6 +168,7 @@ func (c *Client) DeploymentLogs(deployURL string) (*http.Response, error) { return c.ScalingoAPI().Do(req) } +// DeploymentStream returns a websocket connection to follow the various deployment events happening on an application. The type of the data sent on this connection is DeployEvent. func (c *Client) DeploymentStream(deployURL string) (*websocket.Conn, error) { token, err := c.ScalingoAPI().TokenGenerator().GetAccessToken() if err != nil {