-
Notifications
You must be signed in to change notification settings - Fork 28
/
deployment.go
109 lines (88 loc) · 2.45 KB
/
deployment.go
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
34
35
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// SPDX-License-Identifier: Apache-2.0
package server
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/go-vela/types"
"github.com/go-vela/types/library"
)
const (
// DeploymentResp represents a JSON return for a single build.
DeploymentResp = `{
"id": 1,
"number": 1234,
"repo_id": 1,
"url": "https://api.github.com/repos/github/octocat/deployments/1",
"commit": "48afb5bdc41ad69bf22588491333f7cf71135163",
"ref": "main",
"task": "deploy:vela",
"target": "production",
"description": "Deployment request from Vela",
"payload": {},
"created_at": 1,
"created_by": "octocat",
"builds": []
}`
// DeploymentsResp represents a JSON return for one to many builds.
DeploymentsResp = `[
{
"id": 2,
"repo_id": 1,
"url": "https://api.github.com/repos/github/octocat/deployments/2",
"user": "octocat",
"commit": "48afb5bdc41ad69bf22588491333f7cf71135163",
"ref": "main",
"task": "deploy:vela",
"target": "production",
"description": "Deployment request from Vela"
},
{
"id": 1,
"repo_id": 1,
"url": "https://api.github.com/repos/github/octocat/deployments/1",
"user": "octocat",
"commit": "48afb5bdc41ad69bf22588491333f7cf71135163",
"ref": "main",
"task": "deploy:vela",
"target": "production",
"description": "Deployment request from Vela"
}
]`
)
// getDeployments returns mock JSON for a http GET.
func getDeployments(c *gin.Context) {
data := []byte(DeploymentsResp)
var body []library.Deployment
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
}
// getDeployment has a param :deployment returns mock JSON for a http GET.
func getDeployment(c *gin.Context) {
d := c.Param("deployment")
if strings.EqualFold(d, "0") {
msg := fmt.Sprintf("Deployment %s does not exist", d)
c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
return
}
data := []byte(DeploymentResp)
var body library.Deployment
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
}
// addDeployment returns mock JSON for a http POST.
func addDeployment(c *gin.Context) {
data := []byte(DeploymentResp)
var body library.Deployment
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusCreated, body)
}
// updateDeployment returns mock JSON for a http PUT.
func updateDeployment(c *gin.Context) {
data := []byte(DeploymentResp)
var body library.Deployment
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
}