Repository navigation
Expand file tree
/
Copy pathdeployment.go
More file actions
82 lines (73 loc) · 2.05 KB
/
Copy pathdeployment.go
File metadata and controls
82 lines (73 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<
8000
div data-line-number="34" class="react-line-number react-code-text" style="padding-right:16px">3435
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package gateway
import (
"context"
"fmt"
"github.com/railwayapp/cli/entity"
"github.com/railwayapp/cli/errors"
gqlgen "github.com/railwayapp/cli/lib/gql"
)
func (g *Gateway) GetDeploymentsForEnvironment(ctx context.Context, projectId, environmentId string) ([]*entity.Deployment, error) {
gqlReq, err := g.NewRequestWithAuth(`
query ($projectId: ID!, $environmentId: ID!) {
allDeploymentsForEnvironment(projectId: $projectId, environmentId: $environmentId) {
id
status
projectId
meta
staticUrl
}
}
`)
if err != nil {
return nil, err
}
gqlReq.Var("projectId", projectId)
gqlReq.Var("environmentId", environmentId)
var resp struct {
Deployments []*entity.Deployment `json:"allDeploymentsForEnvironment"`
}
if err := gqlReq.Run(ctx, &resp); err != nil {
return nil, errors.DeploymentFetchingFailed
}
return resp.Deployments, nil
}
func (g *Gateway) GetLatestDeploymentForEnvironment(ctx context.Context, projectID, environmentID string) (*entity.Deployment, error) {
deployments, err := g.GetDeploymentsForEnvironment(ctx, projectID, environmentID)
if err != nil {
return nil, err
}
if len(deployments) == 0 {
return nil, errors.NoDeploymentsFound
}
for _, deploy := range deployments {
if deploy.Status != entity.STATUS_REMOVED {
return deploy, nil
}
}
return nil, errors.NoDeploymentsFound
}
func (g *Gateway) GetDeploymentByID(ctx context.Context, req *entity.DeploymentByIDRequest) (*entity.Deployment, error) {
gen, err := gqlgen.AsGQL(ctx, req.GQL)
if err != nil {
return nil, err
}
gqlReq, err := g.NewRequestWithAuth(fmt.Sprintf(`
query ($projectId: ID!, $deploymentId: ID!) {
deploymentById(projectId: $projectId, deploymentId: $deploymentId) {
%s
}
}
`, *gen))
if err != nil {
return nil, err
}
gqlReq.Var("projectId", req.ProjectID)
gqlReq.Var("deploymentId", req.DeploymentID)
var resp struct {
Deployment *entity.Deployment `json:"deploymentById"`
}
if err := gqlReq.Run(ctx, &resp); err != nil {
return nil, errors.DeploymentFetchingFailed
}
return resp.Deployment, nil
}