@@ -46,8 +46,33 @@ type deploymentInput struct {
46
46
ProductionEnvironment bool `json:"production_environment"`
47
47
}
48
48
49
+ type deploymentStatus struct {
50
+ ID int `json:"id"`
51
+ State string `json:"state"`
52
+ Author * user `json:"creator"`
53
+ Description string `json:"description"`
54
+ Environment string `json:"environment"`
55
+ DeploymentLink string `json:"deployment_url"`
56
+ EnvironmentLink string `json:"environment_url"`
57
+ LogLink string `json:"log_url"`
58
+ RepositoryLink string `json:"repository_url"`
59
+ TargetLink string `json:"target_url"`
60
+ Created time.Time `json:"created_at"`
61
+ Updated time.Time `json:"updated_at"`
62
+ }
63
+
64
+ type deploymentStatusInput struct {
65
+ State string `json:"state"`
66
+ TargetLink string `json:"target_url"`
67
+ LogLink string `json:"log_url"`
68
+ Description string `json:"description"`
69
+ Environment string `json:"environment"`
70
+ EnvironmentLink string `json:"environment_url"`
71
+ AutoInactive bool `json:"auto_inactive"`
72
+ }
73
+
49
74
func (s * deploymentService ) Find (ctx context.Context , repoFullName string , deploymentID string ) (* scm.Deployment , * scm.Response , error ) {
50
- path := fmt .Sprintf ("repos/%s/deployments/%s? " , repoFullName , deploymentID )
75
+ path := fmt .Sprintf ("repos/%s/deployments/%s" , repoFullName , deploymentID )
51
76
out := new (deployment )
52
77
res , err := s .client .do (ctx , "GET" , path , nil , out )
53
78
return convertDeployment (out , repoFullName ), res , err
@@ -69,27 +94,30 @@ func (s *deploymentService) Create(ctx context.Context, repoFullName string, dep
69
94
}
70
95
71
96
func (s * deploymentService ) Delete (ctx context.Context , repoFullName string , deploymentID string ) (* scm.Response , error ) {
72
- panic ("implement me" )
97
+ path := fmt .Sprintf ("repos/%s/deployments/%s" , repoFullName , deploymentID )
98
+ return s .client .do (ctx , "DELETE" , path , nil , nil )
73
99
}
74
100
75
101
func (s * deploymentService ) FindStatus (ctx context.Context , repoFullName string , deploymentID string , statusID string ) (* scm.DeploymentStatus , * scm.Response , error ) {
76
- panic ("implement me" )
77
- }
78
-
79
- func (s * deploymentService ) ListStatus (ctx context.Context , repoFullName string , options scm.ListOptions ) ([]* scm.DeploymentStatus , * scm.Response , error ) {
80
- panic ("implement me" )
81
- }
82
-
83
- func (s * deploymentService ) CreateStatus (ctx context.Context , repoFullName string , deployment * scm.DeploymentStatus ) (* scm.DeploymentStatus , * scm.Response , error ) {
84
- panic ("implement me" )
102
+ path := fmt .Sprintf ("repos/%s/deployments/%s/statuses/%s" , repoFullName , deploymentID , statusID )
103
+ out := new (deploymentStatus )
104
+ res , err := s .client .do (ctx , "GET" , path , nil , out )
105
+ return convertDeploymentStatus (out ), res , err
85
106
}
86
107
87
- func (s * deploymentService ) UpdateStatus (ctx context.Context , repoFullName string , deployment * scm.DeploymentStatus ) (* scm.DeploymentStatus , * scm.Response , error ) {
88
- panic ("implement me" )
108
+ func (s * deploymentService ) ListStatus (ctx context.Context , repoFullName string , deploymentID string , opts scm.ListOptions ) ([]* scm.DeploymentStatus , * scm.Response , error ) {
109
+ path := fmt .Sprintf ("repos/%s/deployments/%s/statuses?%s" , repoFullName , deploymentID , encodeListOptions (opts ))
110
+ out := []* deploymentStatus {}
111
+ res , err := s .client .do (ctx , "GET" , path , nil , & out )
112
+ return convertDeploymentStatusList (out ), res , err
89
113
}
90
114
91
- func (s * deploymentService ) DeleteStatus (ctx context.Context , repoFullName string , deploymentID string , statusID string ) (* scm.Response , error ) {
92
- panic ("implement me" )
115
+ func (s * deploymentService ) CreateStatus (ctx context.Context , repoFullName string , deploymentID string , deploymentStatusInput * scm.DeploymentStatusInput ) (* scm.DeploymentStatus , * scm.Response , error ) {
116
+ path := fmt .Sprintf ("repos/%s/deployments/%s/statuses" , repoFullName , deploymentID )
117
+ in := convertToDeploymentStatusInput (deploymentStatusInput )
118
+ out := new (deploymentStatus )
119
+ res , err := s .client .do (ctx , "POST" , path , in , out )
120
+ return convertDeploymentStatus (out ), res , err
93
121
}
94
122
95
123
func convertDeploymentList (out []* deployment , fullName string ) []* scm.Deployment {
@@ -100,6 +128,15 @@ func convertDeploymentList(out []*deployment, fullName string) []*scm.Deployment
100
128
return answer
101
129
}
102
130
131
+ func convertDeploymentStatusList (out []* deploymentStatus ) []* scm.DeploymentStatus {
132
+ answer := []* scm.DeploymentStatus {}
133
+ for _ , o := range out {
134
+ answer = append (answer , convertDeploymentStatus (o ))
135
+ }
136
+ return answer
137
+
138
+ }
139
+
103
140
func convertToDeploymentInput (from * scm.DeploymentInput ) * deploymentInput {
104
141
return & deploymentInput {
105
142
Ref : from .Ref ,
@@ -139,3 +176,32 @@ func convertDeployment(from *deployment, fullName string) *scm.Deployment {
139
176
}
140
177
return dst
141
178
}
179
+
180
+ func convertDeploymentStatus (from * deploymentStatus ) * scm.DeploymentStatus {
181
+ return & scm.DeploymentStatus {
182
+ ID : strconv .Itoa (from .ID ),
183
+ State : from .State ,
184
+ Author : convertUser (from .Author ),
185
+ Description : from .Description ,
186
+ Environment : from .Environment ,
187
+ DeploymentLink : from .DeploymentLink ,
188
+ EnvironmentLink : from .EnvironmentLink ,
189
+ LogLink : from .LogLink ,
190
+ RepositoryLink : from .RepositoryLink ,
191
+ TargetLink : from .TargetLink ,
192
+ Created : from .Created ,
193
+ Updated : from .Updated ,
194
+ }
195
+ }
196
+
197
+ func convertToDeploymentStatusInput (from * scm.DeploymentStatusInput ) * deploymentStatusInput {
198
+ return & deploymentStatusInput {
199
+ State : from .State ,
200
+ TargetLink : from .TargetLink ,
201
+ LogLink : from .LogLink ,
202
+ Description : from .Description ,
203
+ Environment : from .Environment ,
204
+ EnvironmentLink : from .EnvironmentLink ,
205
+ AutoInactive : from .AutoInactive ,
206
+ }
207
+ }
0 commit comments