@@ -49,60 +49,62 @@ type hook struct {
49
49
} `json:"config"`
50
50
}
51
51
52
- type repositoryService struct {
52
+ // RepositoryService implements the repository service for
53
+ // the GitHub driver.
54
+ type RepositoryService struct {
53
55
client * wrapper
54
56
}
55
57
56
58
// Find returns the repository by name.
57
- func (s * repositoryService ) Find (ctx context.Context , repo string ) (* scm.Repository , * scm.Response , error ) {
59
+ func (s * RepositoryService ) Find (ctx context.Context , repo string ) (* scm.Repository , * scm.Response , error ) {
58
60
path := fmt .Sprintf ("repos/%s" , repo )
59
61
out := new (repository )
60
62
res , err := s .client .do (ctx , "GET" , path , nil , out )
61
63
return convertRepository (out ), res , err
62
64
}
63
65
64
66
// FindHook returns a repository hook.
65
- func (s * repositoryService ) FindHook (ctx context.Context , repo string , id string ) (* scm.Hook , * scm.Response , error ) {
67
+ func (s * RepositoryService ) FindHook (ctx context.Context , repo string , id string ) (* scm.Hook , * scm.Response , error ) {
66
68
path := fmt .Sprintf ("repos/%s/hooks/%s" , repo , id )
67
69
out := new (hook )
68
70
res , err := s .client .do (ctx , "GET" , path , nil , out )
69
71
return convertHook (out ), res , err
70
72
}
71
73
72
74
// FindPerms returns the repository permissions.
73
- func (s * repositoryService ) FindPerms (ctx context.Context , repo string ) (* scm.Perm , * scm.Response , error ) {
75
+ func (s * RepositoryService ) FindPerms (ctx context.Context , repo string ) (* scm.Perm , * scm.Response , error ) {
74
76
path := fmt .Sprintf ("repos/%s" , repo )
75
77
out := new (repository )
76
78
res , err := s .client .do (ctx , "GET" , path , nil , out )
77
79
return convertRepository (out ).Perm , res , err
78
80
}
79
81
80
82
// List returns the user repository list.
81
- func (s * repositoryService ) List (ctx context.Context , opts scm.ListOptions ) ([]* scm.Repository , * scm.Response , error ) {
83
+ func (s * RepositoryService ) List (ctx context.Context , opts scm.ListOptions ) ([]* scm.Repository , * scm.Response , error ) {
82
84
path := fmt .Sprintf ("user/repos?%s" , encodeListOptions (opts ))
83
85
out := []* repository {}
84
86
res , err := s .client .do (ctx , "GET" , path , nil , & out )
85
87
return convertRepositoryList (out ), res , err
86
88
}
87
89
88
90
// ListHooks returns a list or repository hooks.
89
- func (s * repositoryService ) ListHooks (ctx context.Context , repo string , opts scm.ListOptions ) ([]* scm.Hook , * scm.Response , error ) {
91
+ func (s * RepositoryService ) ListHooks (ctx context.Context , repo string , opts scm.ListOptions ) ([]* scm.Hook , * scm.Response , error ) {
90
92
path := fmt .Sprintf ("repos/%s/hooks?%s" , repo , encodeListOptions (opts ))
91
93
out := []* hook {}
92
94
res , err := s .client .do (ctx , "GET" , path , nil , & out )
93
95
return convertHookList (out ), res , err
94
96
}
95
97
96
98
// ListStatus returns a list of commit statuses.
97
- func (s * repositoryService ) ListStatus (ctx context.Context , repo , ref string , opts scm.ListOptions ) ([]* scm.Status , * scm.Response , error ) {
99
+ func (s * RepositoryService ) ListStatus (ctx context.Context , repo , ref string , opts scm.ListOptions ) ([]* scm.Status , * scm.Response , error ) {
98
100
path := fmt .Sprintf ("repos/%s/statuses/%s?%s" , repo , ref , encodeListOptions (opts ))
99
101
out := []* status {}
100
102
res , err := s .client .do (ctx , "GET" , path , nil , & out )
101
103
return convertStatusList (out ), res , err
102
104
}
103
105
104
106
// CreateHook creates a new repository webhook.
105
- func (s * repositoryService ) CreateHook (ctx context.Context , repo string , input * scm.HookInput ) (* scm.Hook , * scm.Response , error ) {
107
+ func (s * RepositoryService ) CreateHook (ctx context.Context , repo string , input * scm.HookInput ) (* scm.Hook , * scm.Response , error ) {
106
108
path := fmt .Sprintf ("repos/%s/hooks" , repo )
107
109
in := new (hook )
108
110
in .Active = true
@@ -120,7 +122,7 @@ func (s *repositoryService) CreateHook(ctx context.Context, repo string, input *
120
122
}
121
123
122
124
// CreateStatus creates a new commit status.
123
- func (s * repositoryService ) CreateStatus (ctx context.Context , repo , ref string , input * scm.StatusInput ) (* scm.Status , * scm.Response , error ) {
125
+ func (s * RepositoryService ) CreateStatus (ctx context.Context , repo , ref string , input * scm.StatusInput ) (* scm.Status , * scm.Response , error ) {
124
126
path := fmt .Sprintf ("repos/%s/statuses/%s" , repo , ref )
125
127
in := & status {
126
128
State : convertFromState (input .State ),
@@ -133,8 +135,23 @@ func (s *repositoryService) CreateStatus(ctx context.Context, repo, ref string,
133
135
return convertStatus (out ), res , err
134
136
}
135
137
138
+ // CreateDeployStatus creates a new deployment status.
139
+ func (s * RepositoryService ) CreateDeployStatus (ctx context.Context , repo string , input * scm.DeployStatus ) (* scm.DeployStatus , * scm.Response , error ) {
140
+ path := fmt .Sprintf ("repos/%s/deployments/%d/statuses" , repo , input .Number )
141
+ in := & deployStatus {
142
+ State : convertFromState (input .State ),
143
+ Environment : input .Environment ,
144
+ EnvironmentURL : input .EnvironmentURL ,
145
+ Description : input .Desc ,
146
+ TargetURL : input .Target ,
147
+ }
148
+ out := new (deployStatus )
149
+ res , err := s .client .do (ctx , "POST" , path , in , out )
150
+ return convertDeployStatus (out ), res , err
151
+ }
152
+
136
153
// DeleteHook deletes a repository webhook.
137
- func (s * repositoryService ) DeleteHook (ctx context.Context , repo string , id string ) (* scm.Response , error ) {
154
+ func (s * RepositoryService ) DeleteHook (ctx context.Context , repo string , id string ) (* scm.Response , error ) {
138
155
path := fmt .Sprintf ("repos/%s/hooks/%s" , repo , id )
139
156
return s .client .do (ctx , "DELETE" , path , nil , nil )
140
157
}
@@ -224,6 +241,15 @@ type status struct {
224
241
Context string `json:"context"`
225
242
}
226
243
244
+ type deployStatus struct {
245
+ ID int `json:"id"`
246
+ Environment string `json:"environment"`
247
+ EnvironmentURL string `json:"environment_url"`
248
+ State string `json:"state"`
249
+ TargetURL string `json:"log_url"`
250
+ Description string `json:"description"`
251
+ }
252
+
227
253
func convertStatusList (from []* status ) []* scm.Status {
228
254
to := []* scm.Status {}
229
255
for _ , v := range from {
@@ -241,6 +267,17 @@ func convertStatus(from *status) *scm.Status {
241
267
}
242
268
}
243
269
270
+ func convertDeployStatus (from * deployStatus ) * scm.DeployStatus {
271
+ return & scm.DeployStatus {
272
+ Number : from .ID ,
273
+ State : convertState (from .State ),
274
+ Desc : from .Description ,
275
+ Target : from .TargetURL ,
276
+ Environment : from .Environment ,
277
+ EnvironmentURL : from .EnvironmentURL ,
278
+ }
279
+ }
280
+
244
281
func convertState (from string ) scm.State {
245
282
switch from {
246
283
case "error" :
0 commit comments