@@ -6,14 +6,16 @@ import (
66)
77
88const (
9- projects_url = "/projects" // Get a list of projects owned by the authenticated user
10- projects_all = "/projects/all" // Get a list of all GitLab projects (admin only)
11- projects_search_url = "/projects/search/:query" // Search for projects by name
12- project_url = "/projects/:id" // Get a specific project, identified by project ID or NAME
13- project_url_events = "/projects/:id/events" // Get project events
14- project_url_branches = "/projects/:id/repository/branches" // Lists all branches of a project
15- project_url_members = "/projects/:id/members" // List project team members
16- project_url_member = "/projects/:id/members/:user_id" // Get project team member
9+ projects_url = "/projects" // Get a list of projects owned by the authenticated user
10+ projects_all = "/projects/all" // Get a list of all GitLab projects (admin only)
11+ projects_search_url = "/projects/search/:query" // Search for projects by name
12+ project_url = "/projects/:id" // Get a specific project, identified by project ID or NAME
13+ project_url_events = "/projects/:id/events" // Get project events
14+ project_url_branches = "/projects/:id/repository/branches" // Lists all branches of a project
15+ project_url_members = "/projects/:id/members" // List project team members
16+ project_url_member = "/projects/:id/members/:user_id" // Get project team member
17+ project_url_variables = "/projects/:id/variables" // List project variables or add one
18+ project_url_variable = "/projects/:id/variables/:variable_key" // Get or Update project variable
1719)
1820
1921type Member struct {
@@ -36,6 +38,11 @@ type Namespace struct {
3638 Updated_At string
3739}
3840
41+ type Variable struct {
42+ Key string `json:"key"`
43+ Value string `json:"value"`
44+ }
45+
3946// A gitlab project
4047type Project struct {
4148 Id int `json:"id,omitempty"`
@@ -180,3 +187,93 @@ func (g *Gitlab) ProjectMembers(id string) ([]*Member, error) {
180187
181188 return members , err
182189}
190+
191+ /*
192+ Lists all variables of a project
193+ */
194+ func (g * Gitlab ) ProjectVariables (id string ) ([]* Variable , error ) {
195+ url , opaque := g .ResourceUrlRaw (project_url_variables , map [string ]string {":id" : id })
196+
197+ var variables []* Variable
198+
199+ contents , err := g .buildAndExecRequestRaw ("GET" , url , opaque , nil )
200+ if err == nil {
201+ err = json .Unmarshal (contents , & variables )
202+ }
203+
204+ return variables , err
205+ }
206+
207+ /*
208+ Shows a project variable
209+ */
210+ func (g * Gitlab ) ProjectVariable (id string , key string ) (* Variable , error ) {
211+ url , opaque := g .ResourceUrlRaw (project_url_variable , map [string ]string {":id" : id , ":variable_key" : key })
212+
213+ var result * Variable
214+
215+ contents , err := g .buildAndExecRequestRaw ("GET" , url , opaque , nil )
216+ if err == nil {
217+ err = json .Unmarshal (contents , & result )
218+ }
219+
220+ return result , err
221+ }
222+
223+ /*
224+ Adds a project variable
225+ */
226+ func (g * Gitlab ) AddProjectVariable (id string , variable * Variable ) (* Variable , error ) {
227+ url , opaque := g .ResourceUrlRaw (project_url_variables , map [string ]string {":id" : id })
228+
229+ encodedRequest , err := json .Marshal (variable )
230+ if err != nil {
231+ return nil , err
232+ }
233+
234+ var result * Variable
235+
236+ contents , err := g .buildAndExecRequestRaw ("POST" , url , opaque , encodedRequest )
237+ if err == nil {
238+ err = json .Unmarshal (contents , & result )
239+ }
240+
241+ return result , err
242+ }
243+
244+ /*
245+ Updates a project variable
246+ */
247+ func (g * Gitlab ) UpdateProjectVariable (id string , variable * Variable ) (* Variable , error ) {
248+ url := g .ResourceUrl (project_url_variable , map [string ]string {":id" : id , ":variable_key" : variable .Key })
249+
250+ encodedRequest , err := json .Marshal (variable )
251+ if err != nil {
252+ return nil , err
253+ }
254+ var result * Variable
255+
256+ contents , err := g .buildAndExecRequest ("PUT" , url , encodedRequest )
257+
258+ if err == nil {
259+ err = json .Unmarshal (contents , & result )
260+ }
261+
262+ return result , err
263+ }
264+
265+ /*
266+ Deletes a project variable
267+ */
268+ func (g * Gitlab ) DeleteProjectVariable (id string , key string ) (* Variable , error ) {
269+ url , opaque := g .ResourceUrlRaw (project_url_variable , map [string ]string {":id" : id , ":variable_key" : key })
270+
271+ var result * Variable
272+
273+ contents , err := g .buildAndExecRequestRaw ("DELETE" , url , opaque , nil )
274+ if err == nil {
275+ err = json .Unmarshal (contents , & result )
276+ }
277+
278+ return result , err
279+ }
0 commit comments