Skip to content

Commit

Permalink
Merge pull request #200 from Scalingo/fix/GRR-39/follow_deployment_st…
Browse files Browse the repository at this point in the history
…ream

Add named constants to deployment stream event
  • Loading branch information
EtienneM authored Feb 16, 2021
2 parents ba5c568 + 087ecf5 commit 43470fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ type Deployment struct {
Links *DeploymentLinks `json:"links"`
}

// DeploymentEventStatus holds all different deployment stream types of event.
type DeploymentEventStatus string

const (
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"`
Expand Down Expand Up @@ -140,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 {
Expand Down

0 comments on commit 43470fc

Please sign in to comment.