gitlab-akerl 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.prospectus +11 -0
  4. data/.travis.yml +8 -0
  5. data/CHANGELOG.md +229 -0
  6. data/CONTRIBUTING.md +195 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +24 -0
  9. data/README.md +192 -0
  10. data/Rakefile +9 -0
  11. data/bin/console +10 -0
  12. data/bin/setup +6 -0
  13. data/exe/gitlab +7 -0
  14. data/gitlab-akerl.gemspec +31 -0
  15. data/lib/gitlab.rb +45 -0
  16. data/lib/gitlab/api.rb +19 -0
  17. data/lib/gitlab/cli.rb +89 -0
  18. data/lib/gitlab/cli_helpers.rb +241 -0
  19. data/lib/gitlab/client.rb +48 -0
  20. data/lib/gitlab/client/branches.rb +91 -0
  21. data/lib/gitlab/client/build_triggers.rb +51 -0
  22. data/lib/gitlab/client/build_variables.rb +66 -0
  23. data/lib/gitlab/client/builds.rb +106 -0
  24. data/lib/gitlab/client/commits.rb +121 -0
  25. data/lib/gitlab/client/groups.rb +144 -0
  26. data/lib/gitlab/client/issues.rb +113 -0
  27. data/lib/gitlab/client/labels.rb +57 -0
  28. data/lib/gitlab/client/merge_requests.rb +168 -0
  29. data/lib/gitlab/client/milestones.rb +78 -0
  30. data/lib/gitlab/client/namespaces.rb +20 -0
  31. data/lib/gitlab/client/notes.rb +161 -0
  32. data/lib/gitlab/client/pipelines.rb +68 -0
  33. data/lib/gitlab/client/projects.rb +471 -0
  34. data/lib/gitlab/client/repositories.rb +78 -0
  35. data/lib/gitlab/client/repository_files.rb +88 -0
  36. data/lib/gitlab/client/runners.rb +115 -0
  37. data/lib/gitlab/client/services.rb +50 -0
  38. data/lib/gitlab/client/snippets.rb +91 -0
  39. data/lib/gitlab/client/system_hooks.rb +59 -0
  40. data/lib/gitlab/client/tags.rb +96 -0
  41. data/lib/gitlab/client/users.rb +250 -0
  42. data/lib/gitlab/configuration.rb +55 -0
  43. data/lib/gitlab/error.rb +85 -0
  44. data/lib/gitlab/file_response.rb +46 -0
  45. data/lib/gitlab/help.rb +95 -0
  46. data/lib/gitlab/objectified_hash.rb +34 -0
  47. data/lib/gitlab/page_links.rb +33 -0
  48. data/lib/gitlab/paginated_response.rb +97 -0
  49. data/lib/gitlab/request.rb +117 -0
  50. data/lib/gitlab/shell.rb +84 -0
  51. data/lib/gitlab/shell_history.rb +59 -0
  52. data/lib/gitlab/version.rb +3 -0
  53. data/spec/fixtures/branch.json +1 -0
  54. data/spec/fixtures/branch_delete.json +3 -0
  55. data/spec/fixtures/branches.json +1 -0
  56. data/spec/fixtures/build.json +38 -0
  57. data/spec/fixtures/build_artifacts.json +0 -0
  58. data/spec/fixtures/build_cancel.json +24 -0
  59. data/spec/fixtures/build_erase.json +24 -0
  60. data/spec/fixtures/build_retry.json +24 -0
  61. data/spec/fixtures/builds.json +78 -0
  62. data/spec/fixtures/builds_commits.json +64 -0
  63. data/spec/fixtures/compare_merge_request_diff.json +31 -0
  64. data/spec/fixtures/error_already_exists.json +1 -0
  65. data/spec/fixtures/error_project_not_found.json +1 -0
  66. data/spec/fixtures/get_repository_file.json +1 -0
  67. data/spec/fixtures/git_hook.json +1 -0
  68. data/spec/fixtures/group.json +60 -0
  69. data/spec/fixtures/group_create.json +1 -0
  70. data/spec/fixtures/group_create_with_description.json +1 -0
  71. data/spec/fixtures/group_delete.json +1 -0
  72. data/spec/fixtures/group_member.json +1 -0
  73. data/spec/fixtures/group_member_delete.json +1 -0
  74. data/spec/fixtures/group_member_edit.json +1 -0
  75. data/spec/fixtures/group_members.json +1 -0
  76. data/spec/fixtures/group_projects.json +44 -0
  77. data/spec/fixtures/group_search.json +2 -0
  78. data/spec/fixtures/groups.json +2 -0
  79. data/spec/fixtures/issue.json +1 -0
  80. data/spec/fixtures/issues.json +1 -0
  81. data/spec/fixtures/key.json +1 -0
  82. data/spec/fixtures/keys.json +1 -0
  83. data/spec/fixtures/label.json +1 -0
  84. data/spec/fixtures/labels.json +1 -0
  85. data/spec/fixtures/merge_request.json +1 -0
  86. data/spec/fixtures/merge_request_changes.json +1 -0
  87. data/spec/fixtures/merge_request_comment.json +1 -0
  88. data/spec/fixtures/merge_request_comments.json +1 -0
  89. data/spec/fixtures/merge_request_commits.json +1 -0
  90. data/spec/fixtures/merge_requests.json +1 -0
  91. data/spec/fixtures/milestone.json +1 -0
  92. data/spec/fixtures/milestone_issues.json +1 -0
  93. data/spec/fixtures/milestones.json +1 -0
  94. data/spec/fixtures/namespaces.json +1 -0
  95. data/spec/fixtures/note.json +1 -0
  96. data/spec/fixtures/notes.json +1 -0
  97. data/spec/fixtures/pipeline.json +23 -0
  98. data/spec/fixtures/pipeline_cancel.json +23 -0
  99. data/spec/fixtures/pipeline_create.json +23 -0
  100. data/spec/fixtures/pipeline_retry.json +23 -0
  101. data/spec/fixtures/pipelines.json +48 -0
  102. data/spec/fixtures/project.json +1 -0
  103. data/spec/fixtures/project_commit.json +13 -0
  104. data/spec/fixtures/project_commit_comment.json +1 -0
  105. data/spec/fixtures/project_commit_comments.json +1 -0
  106. data/spec/fixtures/project_commit_diff.json +10 -0
  107. data/spec/fixtures/project_commit_status.json +42 -0
  108. data/spec/fixtures/project_commits.json +1 -0
  109. data/spec/fixtures/project_edit.json +21 -0
  110. data/spec/fixtures/project_events.json +1 -0
  111. data/spec/fixtures/project_for_user.json +1 -0
  112. data/spec/fixtures/project_fork.json +50 -0
  113. data/spec/fixtures/project_fork_link.json +1 -0
  114. data/spec/fixtures/project_forked_for_user.json +50 -0
  115. data/spec/fixtures/project_hook.json +1 -0
  116. data/spec/fixtures/project_hooks.json +1 -0
  117. data/spec/fixtures/project_issues.json +1 -0
  118. data/spec/fixtures/project_key.json +6 -0
  119. data/spec/fixtures/project_keys.json +6 -0
  120. data/spec/fixtures/project_runner_enable.json +7 -0
  121. data/spec/fixtures/project_runners.json +16 -0
  122. data/spec/fixtures/project_search.json +1 -0
  123. data/spec/fixtures/project_star.json +44 -0
  124. data/spec/fixtures/project_tag_annotated.json +1 -0
  125. data/spec/fixtures/project_tag_lightweight.json +1 -0
  126. data/spec/fixtures/project_tags.json +1 -0
  127. data/spec/fixtures/project_unstar.json +44 -0
  128. data/spec/fixtures/project_update_commit_status.json +20 -0
  129. data/spec/fixtures/projects.json +1 -0
  130. data/spec/fixtures/raw_file.json +2 -0
  131. data/spec/fixtures/release_create.json +1 -0
  132. data/spec/fixtures/release_update.json +1 -0
  133. data/spec/fixtures/repository_file.json +1 -0
  134. data/spec/fixtures/runner.json +26 -0
  135. data/spec/fixtures/runner_delete.json +7 -0
  136. data/spec/fixtures/runner_edit.json +26 -0
  137. data/spec/fixtures/runners.json +16 -0
  138. data/spec/fixtures/runners_all.json +30 -0
  139. data/spec/fixtures/service.json +1 -0
  140. data/spec/fixtures/session.json +1 -0
  141. data/spec/fixtures/shell_history.json +2 -0
  142. data/spec/fixtures/snippet.json +1 -0
  143. data/spec/fixtures/snippet_content.json +3 -0
  144. data/spec/fixtures/snippets.json +1 -0
  145. data/spec/fixtures/system_hook.json +1 -0
  146. data/spec/fixtures/system_hooks.json +1 -0
  147. data/spec/fixtures/tag.json +1 -0
  148. data/spec/fixtures/tag_create.json +1 -0
  149. data/spec/fixtures/tag_create_with_description.json +1 -0
  150. data/spec/fixtures/tag_delete.json +1 -0
  151. data/spec/fixtures/tags.json +1 -0
  152. data/spec/fixtures/team_member.json +1 -0
  153. data/spec/fixtures/team_members.json +1 -0
  154. data/spec/fixtures/tree.json +1 -0
  155. data/spec/fixtures/trigger.json +7 -0
  156. data/spec/fixtures/triggers.json +16 -0
  157. data/spec/fixtures/user.json +1 -0
  158. data/spec/fixtures/user_block_unblock.json +1 -0
  159. data/spec/fixtures/user_email.json +1 -0
  160. data/spec/fixtures/user_emails.json +1 -0
  161. data/spec/fixtures/user_search.json +1 -0
  162. data/spec/fixtures/users.json +1 -0
  163. data/spec/fixtures/variable.json +4 -0
  164. data/spec/fixtures/variables.json +10 -0
  165. data/spec/gitlab/cli_helpers_spec.rb +57 -0
  166. data/spec/gitlab/cli_spec.rb +110 -0
  167. data/spec/gitlab/client/branches_spec.rb +99 -0
  168. data/spec/gitlab/client/build_triggers_spec.rb +67 -0
  169. data/spec/gitlab/client/build_variables_spec.rb +86 -0
  170. data/spec/gitlab/client/builds_spec.rb +148 -0
  171. data/spec/gitlab/client/client_spec.rb +11 -0
  172. data/spec/gitlab/client/commits_spec.rb +137 -0
  173. data/spec/gitlab/client/groups_spec.rb +197 -0
  174. data/spec/gitlab/client/issues_spec.rb +138 -0
  175. data/spec/gitlab/client/labels_spec.rb +68 -0
  176. data/spec/gitlab/client/merge_requests_spec.rb +177 -0
  177. data/spec/gitlab/client/milestones_spec.rb +82 -0
  178. data/spec/gitlab/client/namespaces_spec.rb +22 -0
  179. data/spec/gitlab/client/notes_spec.rb +205 -0
  180. data/spec/gitlab/client/pipelines_spec.rb +95 -0
  181. data/spec/gitlab/client/projects_spec.rb +603 -0
  182. data/spec/gitlab/client/repositories_spec.rb +109 -0
  183. data/spec/gitlab/client/repository_files_spec.rb +62 -0
  184. data/spec/gitlab/client/runners_spec.rb +185 -0
  185. data/spec/gitlab/client/services_spec.rb +55 -0
  186. data/spec/gitlab/client/snippets_spec.rb +100 -0
  187. data/spec/gitlab/client/system_hooks_spec.rb +69 -0
  188. data/spec/gitlab/client/tags_spec.rb +109 -0
  189. data/spec/gitlab/client/users_spec.rb +418 -0
  190. data/spec/gitlab/error_spec.rb +45 -0
  191. data/spec/gitlab/file_response_spec.rb +33 -0
  192. data/spec/gitlab/help_spec.rb +46 -0
  193. data/spec/gitlab/objectified_hash_spec.rb +48 -0
  194. data/spec/gitlab/page_links_spec.rb +16 -0
  195. data/spec/gitlab/paginated_response_spec.rb +60 -0
  196. data/spec/gitlab/request_spec.rb +73 -0
  197. data/spec/gitlab/shell_history_spec.rb +53 -0
  198. data/spec/gitlab/shell_spec.rb +80 -0
  199. data/spec/gitlab_spec.rb +97 -0
  200. data/spec/spec_helper.rb +74 -0
  201. metadata +476 -0
@@ -0,0 +1,68 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to pipelines.
3
+ # @see https://docs.gitlab.com/ce/api/pipelines.html
4
+ module Pipelines
5
+ # Gets a list of project pipelines.
6
+ #
7
+ # @example
8
+ # Gitlab.pipelines(5)
9
+ # Gitlab.pipelines(5, { per_page: 10, page: 2 })
10
+ #
11
+ # @param [Integer] project The ID of a project.
12
+ # @param [Hash] options A customizable set of options.
13
+ # @option options [Integer] :page The page number.
14
+ # @option options [Integer] :per_page The number of results per page.
15
+ # @return [Array<Gitlab::ObjectifiedHash>]
16
+ def pipelines(project, options={})
17
+ get("/projects/#{project}/pipelines", query: options)
18
+ end
19
+
20
+ # Gets a single pipeline.
21
+ #
22
+ # @example
23
+ # Gitlab.pipeline(5, 36)
24
+ #
25
+ # @param [Integer] project The ID of a project.
26
+ # @param [Integer] id The ID of a pipeline.
27
+ # @return [Gitlab::ObjectifiedHash]
28
+ def pipeline(project, id)
29
+ get("/projects/#{project}/pipelines/#{id}")
30
+ end
31
+
32
+ # Create a pipeline.
33
+ #
34
+ # @example
35
+ # Gitlab.create_pipeline(5, 'master')
36
+ #
37
+ # @param [Integer] project The ID of a project.
38
+ # @param [String] ref Reference to commit.
39
+ # @return [Gitlab::ObjectifiedHash] The pipelines changes.
40
+ def create_pipeline(project, ref)
41
+ post("/projects/#{project}/pipeline?ref=#{ref}")
42
+ end
43
+
44
+ # Cancels a pipeline.
45
+ #
46
+ # @example
47
+ # Gitlab.cancel_pipeline(5, 1)
48
+ #
49
+ # @param [Integer] project The ID of a project.
50
+ # @param [Integer] id The ID of a pipeline.
51
+ # @return [Gitlab::ObjectifiedHash] The pipelines changes.
52
+ def cancel_pipeline(project, id)
53
+ post("/projects/#{project}/pipelines/#{id}/cancel")
54
+ end
55
+
56
+ # Retry a pipeline.
57
+ #
58
+ # @example
59
+ # Gitlab.retry_pipeline(5, 1)
60
+ #
61
+ # @param [Integer] project The ID of a project.
62
+ # @param [Integer] id The ID of a pipeline.
63
+ # @return [Array<Gitlab::ObjectifiedHash>] The pipelines changes.
64
+ def retry_pipeline(project, id)
65
+ post("/projects/#{project}/pipelines/#{id}/retry")
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,471 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to projects.
3
+ # @see https://docs.gitlab.com/ce/api/projects.html
4
+ module Projects
5
+ # Gets a list of projects owned by the authenticated user.
6
+ #
7
+ # @example
8
+ # Gitlab.projects
9
+ #
10
+ # @param [Hash] options A customizable set of options.
11
+ # @option options [Integer] :page The page number.
12
+ # @option options [Integer] :per_page The number of results per page.
13
+ # @option options [String] :scope Scope of projects. 'owned' for list of projects owned by the authenticated user, 'all' to get all projects (admin only)
14
+ # @return [Array<Gitlab::ObjectifiedHash>]
15
+ def projects(options={})
16
+ if options[:scope]
17
+ get("/projects/#{options[:scope]}", query: options)
18
+ else
19
+ get("/projects", query: options)
20
+ end
21
+ end
22
+
23
+ # Search for projects by name.
24
+ #
25
+ # @example
26
+ # Gitlab.project_search('gitlab')
27
+ # Gitlab.project_search('gitlab', { order_by: 'last_activity_at' })
28
+ # Gitlab.search_projects('gitlab', { order_by: 'name', sort: 'asc' })
29
+ #
30
+ # @param [Hash] options A customizable set of options.
31
+ # @option options [String] :per_page Number of projects to return per page
32
+ # @option options [String] :page The page to retrieve
33
+ # @option options [String] :order_by Return requests ordered by id, name, created_at or last_activity_at fields
34
+ # @option options [String] :sort Return requests sorted in asc or desc order
35
+ # @return [Array<Gitlab::ObjectifiedHash>]
36
+ def project_search(query, options={})
37
+ get("/projects/search/#{query}", query: options)
38
+ end
39
+ alias_method :search_projects, :project_search
40
+
41
+ # Gets information about a project.
42
+ #
43
+ # @example
44
+ # Gitlab.project(3)
45
+ # Gitlab.project('gitlab')
46
+ #
47
+ # @param [Integer, String] id The ID or name of a project.
48
+ # @return [Gitlab::ObjectifiedHash]
49
+ def project(id)
50
+ get("/projects/#{id}")
51
+ end
52
+
53
+ # Gets a list of project events.
54
+ #
55
+ # @example
56
+ # Gitlab.project_events(42)
57
+ # Gitlab.project_events('gitlab')
58
+ #
59
+ # @param [Integer, String] project The ID or name of a project.
60
+ # @param [Hash] options A customizable set of options.
61
+ # @option options [Integer] :page The page number.
62
+ # @option options [Integer] :per_page The number of results per page.
63
+ # @return [Array<Gitlab::ObjectifiedHash>]
64
+ def project_events(project, options={})
65
+ get("/projects/#{project}/events", query: options)
66
+ end
67
+
68
+ # Creates a new project.
69
+ #
70
+ # @example
71
+ # Gitlab.create_project('gitlab')
72
+ # Gitlab.create_project('viking', { description: 'Awesome project' })
73
+ # Gitlab.create_project('Red', { wall_enabled: false })
74
+ #
75
+ # @param [String] name The name of a project.
76
+ # @param [Hash] options A customizable set of options.
77
+ # @option options [String] :description The description of a project.
78
+ # @option options [String] :default_branch The default branch of a project.
79
+ # @option options [String] :namespace_id The namespace in which to create a project.
80
+ # @option options [Boolean] :wiki_enabled The wiki integration for a project (0 = false, 1 = true).
81
+ # @option options [Boolean] :wall_enabled The wall functionality for a project (0 = false, 1 = true).
82
+ # @option options [Boolean] :issues_enabled The issues integration for a project (0 = false, 1 = true).
83
+ # @option options [Boolean] :snippets_enabled The snippets integration for a project (0 = false, 1 = true).
84
+ # @option options [Boolean] :merge_requests_enabled The merge requests functionality for a project (0 = false, 1 = true).
85
+ # @option options [Boolean] :public The setting for making a project public (0 = false, 1 = true).
86
+ # @option options [Integer] :user_id The user/owner id of a project.
87
+ # @return [Gitlab::ObjectifiedHash] Information about created project.
88
+ def create_project(name, options={})
89
+ url = options[:user_id] ? "/projects/user/#{options[:user_id]}" : "/projects"
90
+ post(url, body: { name: name }.merge(options))
91
+ end
92
+
93
+ # Deletes a project.
94
+ #
95
+ # @example
96
+ # Gitlab.delete_project(4)
97
+ #
98
+ # @param [Integer, String] id The ID or name of a project.
99
+ # @return [Gitlab::ObjectifiedHash] Information about deleted project.
100
+ def delete_project(id)
101
+ delete("/projects/#{id}")
102
+ end
103
+
104
+ # Gets a list of project team members.
105
+ #
106
+ # @example
107
+ # Gitlab.team_members(42)
108
+ # Gitlab.team_members('gitlab')
109
+ #
110
+ # @param [Integer, String] project The ID or name of a project.
111
+ # @param [Hash] options A customizable set of options.
112
+ # @option options [String] :query The search query.
113
+ # @option options [Integer] :page The page number.
114
+ # @option options [Integer] :per_page The number of results per page.
115
+ # @return [Array<Gitlab::ObjectifiedHash>]
116
+ def team_members(project, options={})
117
+ get("/projects/#{project}/members", query: options)
118
+ end
119
+
120
+ # Gets a project team member.
121
+ #
122
+ # @example
123
+ # Gitlab.team_member('gitlab', 2)
124
+ #
125
+ # @param [Integer, String] project The ID or name of a project.
126
+ # @param [Integer] id The ID of a project team member.
127
+ # @return [Gitlab::ObjectifiedHash]
128
+ def team_member(project, id)
129
+ get("/projects/#{project}/members/#{id}")
130
+ end
131
+
132
+ # Adds a user to project team.
133
+ #
134
+ # @example
135
+ # Gitlab.add_team_member('gitlab', 2, 40)
136
+ #
137
+ # @param [Integer, String] project The ID or name of a project.
138
+ # @param [Integer] id The ID of a user.
139
+ # @param [Integer] access_level The access level to project.
140
+ # @param [Hash] options A customizable set of options.
141
+ # @return [Gitlab::ObjectifiedHash] Information about added team member.
142
+ def add_team_member(project, id, access_level)
143
+ post("/projects/#{project}/members", body: { user_id: id, access_level: access_level })
144
+ end
145
+
146
+ # Updates a team member's project access level.
147
+ #
148
+ # @example
149
+ # Gitlab.edit_team_member('gitlab', 3, 20)
150
+ #
151
+ # @param [Integer, String] project The ID or name of a project.
152
+ # @param [Integer] id The ID of a user.
153
+ # @param [Integer] access_level The access level to project.
154
+ # @param [Hash] options A customizable set of options.
155
+ # @return [Array<Gitlab::ObjectifiedHash>] Information about updated team member.
156
+ def edit_team_member(project, id, access_level)
157
+ put("/projects/#{project}/members/#{id}", body: { access_level: access_level })
158
+ end
159
+
160
+ # Removes a user from project team.
161
+ #
162
+ # @example
163
+ # Gitlab.remove_team_member('gitlab', 2)
164
+ #
165
+ # @param [Integer, String] project The ID or name of a project.
166
+ # @param [Integer] id The ID of a user.
167
+ # @param [Hash] options A customizable set of options.
168
+ # @return [Gitlab::ObjectifiedHash] Information about removed team member.
169
+ def remove_team_member(project, id)
170
+ delete("/projects/#{project}/members/#{id}")
171
+ end
172
+
173
+ # Gets a list of project hooks.
174
+ #
175
+ # @example
176
+ # Gitlab.project_hooks(42)
177
+ # Gitlab.project_hooks('gitlab')
178
+ #
179
+ # @param [Integer, String] project The ID or name of a project.
180
+ # @param [Hash] options A customizable set of options.
181
+ # @option options [Integer] :page The page number.
182
+ # @option options [Integer] :per_page The number of results per page.
183
+ # @return [Array<Gitlab::ObjectifiedHash>]
184
+ def project_hooks(project, options={})
185
+ get("/projects/#{project}/hooks", query: options)
186
+ end
187
+
188
+ # Gets a project hook.
189
+ #
190
+ # @example
191
+ # Gitlab.project_hook(42, 5)
192
+ # Gitlab.project_hook('gitlab', 5)
193
+ #
194
+ # @param [Integer, String] project The ID or name of a project.
195
+ # @param [Integer] id The ID of a hook.
196
+ # @return [Gitlab::ObjectifiedHash]
197
+ def project_hook(project, id)
198
+ get("/projects/#{project}/hooks/#{id}")
199
+ end
200
+
201
+ # Adds a new hook to the project.
202
+ #
203
+ # @example
204
+ # Gitlab.add_project_hook(42, 'https://api.example.net/v1/webhooks/ci')
205
+ #
206
+ # @param [Integer, String] project The ID or name of a project.
207
+ # @param [String] url The hook URL.
208
+ # @param [Hash] options A customizable set of options.
209
+ # @param option [Boolean] :push_events Trigger hook on push events (0 = false, 1 = true)
210
+ # @param option [Boolean] :issues_events Trigger hook on issues events (0 = false, 1 = true)
211
+ # @param option [Boolean] :merge_requests_events Trigger hook on merge_requests events (0 = false, 1 = true)
212
+ # @param option [Boolean] :tag_push_events Trigger hook on push_tag events (0 = false, 1 = true)
213
+ # @return [Gitlab::ObjectifiedHash] Information about added hook.
214
+ def add_project_hook(project, url, options={})
215
+ body = { url: url }.merge(options)
216
+ post("/projects/#{project}/hooks", body: body)
217
+ end
218
+
219
+ # Updates a project hook URL.
220
+ #
221
+ # @example
222
+ # Gitlab.edit_project_hook(42, 1, 'https://api.example.net/v1/webhooks/ci')
223
+ #
224
+ # @param [Integer, String] project The ID or name of a project.
225
+ # @param [Integer] id The ID of the hook.
226
+ # @param [String] url The hook URL.
227
+ # @param [Hash] options A customizable set of options.
228
+ # @param option [Boolean] :push_events Trigger hook on push events (0 = false, 1 = true)
229
+ # @param option [Boolean] :issues_events Trigger hook on issues events (0 = false, 1 = true)
230
+ # @param option [Boolean] :merge_requests_events Trigger hook on merge_requests events (0 = false, 1 = true)
231
+ # @param option [Boolean] :tag_push_events Trigger hook on push_tag events (0 = false, 1 = true)
232
+ # @return [Gitlab::ObjectifiedHash] Information about updated hook.
233
+ def edit_project_hook(project, id, url, options={})
234
+ body = { url: url }.merge(options)
235
+ put("/projects/#{project}/hooks/#{id}", body: body)
236
+ end
237
+
238
+ # Deletes a hook from project.
239
+ #
240
+ # @example
241
+ # Gitlab.delete_project_hook('gitlab', 4)
242
+ #
243
+ # @param [Integer, String] project The ID or name of a project.
244
+ # @param [String] id The ID of the hook.
245
+ # @return [Gitlab::ObjectifiedHash] Information about deleted hook.
246
+ def delete_project_hook(project, id)
247
+ delete("/projects/#{project}/hooks/#{id}")
248
+ end
249
+
250
+ # Gets a project git hook.
251
+ # @see https://docs.gitlab.com/ee/api/projects.html#show-project-git-hooks
252
+ #
253
+ # @example
254
+ # Gitlab.git_hook(42)
255
+ #
256
+ # @param [Integer] id The ID of a project.
257
+ # @return [Gitlab::ObjectifiedHash]
258
+ def git_hook(id)
259
+ get("/projects/#{id}/git_hook")
260
+ end
261
+
262
+ # Adds a project git hook.
263
+ # @see https://docs.gitlab.com/ee/api/projects.html#add-project-git-hook
264
+ #
265
+ # @example
266
+ # Gitlab.add_git_hook(42, { deny_delete_tag: false, commit_message_regex: '\\b[A-Z]{3}-[0-9]+\\b' })
267
+ #
268
+ # @param [Integer] id The ID of a project.
269
+ # @param [Hash] options A customizable set of options.
270
+ # @param option [Boolean] :deny_delete_tag Do not allow users to remove git tags with git push (0 = false, 1 = true)
271
+ # @param option [String] :commit_message_regex Commit message regex
272
+ # @return [Gitlab::ObjectifiedHash] Information about added git hook.
273
+ def add_git_hook(id, options={})
274
+ post("/projects/#{id}/git_hook", body: options)
275
+ end
276
+
277
+ # Updates a project git hook.
278
+ # @see https://docs.gitlab.com/ee/api/projects.html#edit-project-git-hook
279
+ #
280
+ # @example
281
+ # Gitlab.edit_git_hook(42, { deny_delete_tag: false, commit_message_regex: '\\b[A-Z]{3}-[0-9]+\\b' })
282
+ #
283
+ # @param [Integer] id The ID of a project.
284
+ # @param [Hash] options A customizable set of options.
285
+ # @param option [Boolean] :deny_delete_tag Do not allow users to remove git tags with git push (0 = false, 1 = true)
286
+ # @param option [String] :commit_message_regex Commit message regex
287
+ # @return [Gitlab::ObjectifiedHash] Information about updated git hook.
288
+ def edit_git_hook(id, options={})
289
+ put("/projects/#{id}/git_hook", body: options)
290
+ end
291
+
292
+ # Deletes a git hook from a project.
293
+ # @see https://docs.gitlab.com/ee/api/projects.html#delete-project-git-hook
294
+ #
295
+ # @example
296
+ # Gitlab.delete_git_hook(42)
297
+ #
298
+ # @param [Integer] id The ID of a project.
299
+ # @return [Gitlab::ObjectifiedHash] Information about deleted git hook.
300
+ def delete_git_hook(id, options={})
301
+ delete("/projects/#{id}/git_hook")
302
+ end
303
+
304
+ # Mark this project as forked from the other
305
+ #
306
+ # @example
307
+ # Gitlab.make_forked(42, 24)
308
+ #
309
+ # @param [Integer, String] project The ID or name of a project.
310
+ # @param [Integer] id The ID of the project it is forked from.
311
+ # @return [Gitlab::ObjectifiedHash] Information about the forked project.
312
+ def make_forked_from(project, id)
313
+ post("/projects/#{project}/fork/#{id}")
314
+ end
315
+
316
+ # Remove a forked_from relationship for a project.
317
+ #
318
+ # @example
319
+ # Gitlab.remove_forked(42)
320
+ #
321
+ # @param [Integer, String] project The ID or name of a project.
322
+ # @param [Integer] project The ID of the project it is forked from
323
+ # @return [Gitlab::ObjectifiedHash] Information about the forked project.
324
+ def remove_forked(project)
325
+ delete("/projects/#{project}/fork")
326
+ end
327
+
328
+ # Gets a project deploy keys.
329
+ #
330
+ # @example
331
+ # Gitlab.deploy_keys(42)
332
+ #
333
+ # @param [Integer] project The ID of a project.
334
+ # @param [Hash] options A customizable set of options.
335
+ # @option options [Integer] :page The page number.
336
+ # @option options [Integer] :per_page The number of results per page.
337
+ # @return [Array<Gitlab::ObjectifiedHash>]
338
+ def deploy_keys(project, options={})
339
+ get("/projects/#{project}/keys", query: options)
340
+ end
341
+
342
+ # Gets a single project deploy key.
343
+ #
344
+ # @example
345
+ # Gitlab.deploy_key(42, 1)
346
+ #
347
+ # @param [Integer, String] project The ID of a project.
348
+ # @param [Integer] id The ID of a deploy key.
349
+ # @return [Gitlab::ObjectifiedHash]
350
+ def deploy_key(project, id)
351
+ get("/projects/#{project}/keys/#{id}")
352
+ end
353
+
354
+ # Creates a new deploy key.
355
+ #
356
+ # @example
357
+ # Gitlab.create_deploy_key(42, 'My Key', 'Key contents')
358
+ #
359
+ # @param [Integer] project The ID of a project.
360
+ # @param [String] title The title of a deploy key.
361
+ # @param [String] key The content of a deploy key.
362
+ # @return [Gitlab::ObjectifiedHash] Information about created deploy key.
363
+ def create_deploy_key(project, title, key)
364
+ post("/projects/#{project}/keys", body: { title: title, key: key })
365
+ end
366
+
367
+ # Enables a deploy key at the project.
368
+ #
369
+ # @example
370
+ # Gitlab.enable_deploy_key(42, 66)
371
+ #
372
+ # @param [Integer] project The ID of a project.
373
+ # @param [Integer] key The ID of a deploy key.
374
+ # @return [Gitlab::ObjectifiedHash] Information about the enabled deploy key.
375
+ def enable_deploy_key(project, key)
376
+ post("/projects/#{project}/deploy_keys/#{key}/enable", body: { id: project, key_id: key })
377
+ end
378
+
379
+ # Disables a deploy key at the project.
380
+ #
381
+ # @example
382
+ # Gitlab.disable_deploy_key(42, 66)
383
+ #
384
+ # @param [Integer] project The ID of a project.
385
+ # @param [Integer] key The ID of a deploy key.
386
+ # @return [Gitlab::ObjectifiedHash] Information about the disabled deploy key.
387
+ def disable_deploy_key(project, key)
388
+ post("/projects/#{project}/deploy_keys/#{key}/disable", body: { id: project, key_id: key })
389
+ end
390
+
391
+ # Deletes a deploy key from project.
392
+ #
393
+ # @example
394
+ # Gitlab.delete_deploy_key(42, 1)
395
+ #
396
+ # @param [Integer] project The ID of a project.
397
+ # @param [Integer] id The ID of a deploy key.
398
+ # @return [Gitlab::ObjectifiedHash] Information about deleted deploy key.
399
+ def delete_deploy_key(project, id)
400
+ delete("/projects/#{project}/keys/#{id}")
401
+ end
402
+
403
+ # Forks a project into the user namespace.
404
+ #
405
+ # @example
406
+ # Gitlab.create_fork(42)
407
+ # Gitlab.create_fork(42, { sudo: 'another_username' })
408
+ #
409
+ # @param [Integer] project The ID of a project.
410
+ # @param [Hash] options A customizable set of options.
411
+ # @option options [String] :sudo The username the project will be forked for
412
+ # @return [Gitlab::ObjectifiedHash] Information about the forked project.
413
+ def create_fork(id, options={})
414
+ post("/projects/fork/#{id}", body: options)
415
+ end
416
+
417
+ # Updates an existing project.
418
+ #
419
+ # @example
420
+ # Gitlab.edit_project(42)
421
+ # Gitlab.edit_project(42, { name: 'project_name' })
422
+ #
423
+ # @param [Integer] project The ID of a project.
424
+ # @param [Hash] options A customizable set of options.
425
+ # @option options [String] :name The name of a project
426
+ # @option options [String] :path The name of a project
427
+ # @option options [String] :description The name of a project
428
+ # @return [Gitlab::ObjectifiedHash] Information about the edited project.
429
+ def edit_project(id, options={})
430
+ put("/projects/#{id}", query: options)
431
+ end
432
+
433
+ # Share project with group.
434
+ #
435
+ # @example
436
+ # Gitlab.share_project_with_group('gitlab', 2, 40)
437
+ #
438
+ # @param [Integer, String] project The ID or name of a project.
439
+ # @param [Integer] id The ID of a group.
440
+ # @param [Integer] group_access The access level to project.
441
+ def share_project_with_group(project, id, group_access)
442
+ post("/projects/#{project}/share", body: { group_id: id, group_access: group_access })
443
+ end
444
+
445
+ # Stars a project.
446
+ # @see https://docs.gitlab.com/ce/api/projects.html#star-a-project
447
+ #
448
+ # @example
449
+ # Gitlab.star_project(42)
450
+ # Gitlab.star_project('gitlab-org/gitlab-ce')
451
+ #
452
+ # @param [Integer, String] id The ID or name of a project.
453
+ # @return [Gitlab::ObjectifiedHash] Information about starred project.
454
+ def star_project(id)
455
+ post("/projects/#{id}/star")
456
+ end
457
+
458
+ # Unstars a project.
459
+ # @see https://docs.gitlab.com/ce/api/projects.html#unstar-a-project
460
+ #
461
+ # @example
462
+ # Gitlab.unstar_project(42)
463
+ # Gitlab.unstar_project('gitlab-org/gitlab-ce')
464
+ #
465
+ # @param [Integer, String] id The ID or name of a project.
466
+ # @return [Gitlab::ObjectifiedHash] Information about unstarred project.
467
+ def unstar_project(id)
468
+ delete("/projects/#{id}/star")
469
+ end
470
+ end
471
+ end