@@ -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"`
@@ -152,3 +159,93 @@ func (g *Gitlab) ProjectMembers(id string) ([]*Member, error) {
152159
153160 return members , err
154161}
162+
163+ /*
164+ Lists all variables of a project
165+ */
166+ func (g * Gitlab ) ProjectVariables (id string ) ([]* Variable , error ) {
167+ url , opaque := g .ResourceUrlRaw (project_url_variables , map [string ]string {":id" : id })
168+
169+ var variables []* Variable
170+
171+ contents , err := g .buildAndExecRequestRaw ("GET" , url , opaque , nil )
172+ if err == nil {
173+ err = json .Unmarshal (contents , & variables )
174+ }
175+
176+ return variables , err
177+ }
178+
179+ /*
180+ Shows a project variable
181+ */
182+ func (g * Gitlab ) ProjectVariable (id string , key string ) (* Variable , error ) {
183+ url , opaque := g .ResourceUrlRaw (project_url_variable , map [string ]string {":id" : id , ":variable_key" : key })
184+
185+ var result * Variable
186+
187+ contents , err := g .buildAndExecRequestRaw ("GET" , url , opaque , nil )
188+ if err == nil {
189+ err = json .Unmarshal (contents , & result )
190+ }
191+
192+ return result , err
193+ }
194+
195+ /*
196+ Adds a project variable
197+ */
198+ func (g * Gitlab ) AddProjectVariable (id string , variable * Variable ) (* Variable , error ) {
199+ url , opaque := g .ResourceUrlRaw (project_url_variables , map [string ]string {":id" : id })
200+
201+ encodedRequest , err := json .Marshal (variable )
202+ if err != nil {
203+ return nil , err
204+ }
205+
206+ var result * Variable
207+
208+ contents , err := g .buildAndExecRequestRaw ("POST" , url , opaque , encodedRequest )
209+ if err == nil {
210+ err = json .Unmarshal (contents , & result )
211+ }
212+
213+ return result , err
214+ }
215+
216+ /*
217+ Updates a project variable
218+ */
219+ func (g * Gitlab ) UpdateProjectVariable (id string , variable * Variable ) (* Variable , error ) {
220+ url := g .ResourceUrl (project_url_variable , map [string ]string {":id" : id , ":variable_key" : variable .Key })
221+
222+ encodedRequest , err := json .Marshal (variable )
223+ if err != nil {
224+ return nil , err
225+ }
226+ var result * Variable
227+
228+ contents , err := g .buildAndExecRequest ("PUT" , url , encodedRequest )
229+
230+ if err == nil {
231+ err = json .Unmarshal (contents , & result )
232+ }
233+
234+ return result , err
235+ }
236+
237+ /*
238+ Deletes a project variable
239+ */
240+ func (g * Gitlab ) DeleteProjectVariable (id string , key string ) (* Variable , error ) {
241+ url , opaque := g .ResourceUrlRaw (project_url_variable , map [string ]string {":id" : id , ":variable_key" : key })
242+
243+ var result * Variable
244+
245+ contents , err := g .buildAndExecRequestRaw ("DELETE" , url , opaque , nil )
246+ if err == nil {
247+ err = json .Unmarshal (contents , & result )
248+ }
249+
250+ return result , err
251+ }
0 commit comments