gitlab 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.travis.yml +6 -2
  4. data/CHANGELOG.md +244 -0
  5. data/CONTRIBUTING.md +195 -0
  6. data/LICENSE.txt +1 -1
  7. data/README.md +122 -10
  8. data/Rakefile +1 -1
  9. data/bin/console +10 -0
  10. data/bin/setup +6 -0
  11. data/exe/gitlab +7 -0
  12. data/gitlab.gemspec +9 -3
  13. data/lib/gitlab.rb +18 -2
  14. data/lib/gitlab/api.rb +6 -4
  15. data/lib/gitlab/cli.rb +89 -0
  16. data/lib/gitlab/cli_helpers.rb +241 -0
  17. data/lib/gitlab/client.rb +42 -6
  18. data/lib/gitlab/client/branches.rb +91 -0
  19. data/lib/gitlab/client/build_triggers.rb +51 -0
  20. data/lib/gitlab/client/build_variables.rb +66 -0
  21. data/lib/gitlab/client/builds.rb +106 -0
  22. data/lib/gitlab/client/commits.rb +146 -0
  23. data/lib/gitlab/client/groups.rb +66 -10
  24. data/lib/gitlab/client/issues.rb +61 -16
  25. data/lib/gitlab/client/labels.rb +57 -0
  26. data/lib/gitlab/client/merge_requests.rb +137 -26
  27. data/lib/gitlab/client/milestones.rb +44 -9
  28. data/lib/gitlab/client/namespaces.rb +20 -0
  29. data/lib/gitlab/client/notes.rb +71 -16
  30. data/lib/gitlab/client/pipelines.rb +68 -0
  31. data/lib/gitlab/client/projects.rb +236 -27
  32. data/lib/gitlab/client/repositories.rb +39 -45
  33. data/lib/gitlab/client/repository_files.rb +107 -0
  34. data/lib/gitlab/client/runners.rb +115 -0
  35. data/lib/gitlab/client/services.rb +50 -0
  36. data/lib/gitlab/client/snippets.rb +26 -21
  37. data/lib/gitlab/client/system_hooks.rb +59 -0
  38. data/lib/gitlab/client/tags.rb +96 -0
  39. data/lib/gitlab/client/users.rb +151 -7
  40. data/lib/gitlab/configuration.rb +20 -4
  41. data/lib/gitlab/error.rb +55 -12
  42. data/lib/gitlab/file_response.rb +46 -0
  43. data/lib/gitlab/help.rb +95 -0
  44. data/lib/gitlab/objectified_hash.rb +19 -3
  45. data/lib/gitlab/page_links.rb +33 -0
  46. data/lib/gitlab/paginated_response.rb +97 -0
  47. data/lib/gitlab/request.rb +65 -33
  48. data/lib/gitlab/shell.rb +84 -0
  49. data/lib/gitlab/shell_history.rb +59 -0
  50. data/lib/gitlab/version.rb +1 -1
  51. data/spec/fixtures/{project_branch.json → branch.json} +1 -1
  52. data/spec/fixtures/branch_delete.json +3 -0
  53. data/spec/fixtures/{project_branches.json → branches.json} +0 -0
  54. data/spec/fixtures/build.json +38 -0
  55. data/spec/fixtures/build_artifacts.json +0 -0
  56. data/spec/fixtures/build_cancel.json +24 -0
  57. data/spec/fixtures/build_erase.json +24 -0
  58. data/spec/fixtures/build_retry.json +24 -0
  59. data/spec/fixtures/builds.json +78 -0
  60. data/spec/fixtures/builds_commits.json +64 -0
  61. data/spec/fixtures/compare_merge_request_diff.json +31 -0
  62. data/spec/fixtures/error_project_not_found.json +1 -0
  63. data/spec/fixtures/get_repository_file.json +1 -0
  64. data/spec/fixtures/group_create_with_description.json +1 -0
  65. data/spec/fixtures/group_delete.json +1 -0
  66. data/spec/fixtures/group_member_edit.json +1 -0
  67. data/spec/fixtures/group_projects.json +44 -0
  68. data/spec/fixtures/group_search.json +2 -0
  69. data/spec/fixtures/label.json +1 -0
  70. data/spec/fixtures/labels.json +1 -0
  71. data/spec/fixtures/merge_request_changes.json +1 -0
  72. data/spec/fixtures/merge_request_closes_issues.json +1 -0
  73. data/spec/fixtures/{comment_merge_request.json → merge_request_comment.json} +0 -0
  74. data/spec/fixtures/merge_request_comments.json +1 -0
  75. data/spec/fixtures/merge_request_commits.json +1 -0
  76. data/spec/fixtures/milestone_issues.json +1 -0
  77. data/spec/fixtures/milestone_merge_requests.json +1 -0
  78. data/spec/fixtures/namespaces.json +1 -0
  79. data/spec/fixtures/pipeline.json +23 -0
  80. data/spec/fixtures/pipeline_cancel.json +23 -0
  81. data/spec/fixtures/pipeline_create.json +23 -0
  82. data/spec/fixtures/pipeline_retry.json +23 -0
  83. data/spec/fixtures/pipelines.json +48 -0
  84. data/spec/fixtures/project_commit.json +13 -0
  85. data/spec/fixtures/project_commit_comment.json +1 -0
  86. data/spec/fixtures/project_commit_comments.json +1 -0
  87. data/spec/fixtures/project_commit_create.json +22 -0
  88. data/spec/fixtures/project_commit_diff.json +10 -0
  89. data/spec/fixtures/project_commit_status.json +42 -0
  90. data/spec/fixtures/project_edit.json +21 -0
  91. data/spec/fixtures/project_events.json +1 -0
  92. data/spec/fixtures/project_fork.json +50 -0
  93. data/spec/fixtures/project_forked_for_user.json +50 -0
  94. data/spec/fixtures/project_runner_enable.json +7 -0
  95. data/spec/fixtures/project_runners.json +16 -0
  96. data/spec/fixtures/project_search.json +1 -0
  97. data/spec/fixtures/project_star.json +44 -0
  98. data/spec/fixtures/project_tag_annotated.json +1 -0
  99. data/spec/fixtures/project_tag_lightweight.json +1 -0
  100. data/spec/fixtures/project_unstar.json +44 -0
  101. data/spec/fixtures/project_update_commit_status.json +20 -0
  102. data/spec/fixtures/push_rule.json +1 -0
  103. data/spec/fixtures/raw_file.json +2 -0
  104. data/spec/fixtures/release_create.json +1 -0
  105. data/spec/fixtures/release_update.json +1 -0
  106. data/spec/fixtures/repository_file.json +1 -0
  107. data/spec/fixtures/runner.json +26 -0
  108. data/spec/fixtures/runner_delete.json +7 -0
  109. data/spec/fixtures/runner_edit.json +26 -0
  110. data/spec/fixtures/runners.json +16 -0
  111. data/spec/fixtures/runners_all.json +30 -0
  112. data/spec/fixtures/service.json +1 -0
  113. data/spec/fixtures/shell_history.json +2 -0
  114. data/spec/fixtures/snippet_content.json +3 -0
  115. data/spec/fixtures/system_hook.json +1 -0
  116. data/spec/fixtures/system_hooks.json +1 -0
  117. data/spec/fixtures/tag.json +1 -0
  118. data/spec/fixtures/tag_create.json +1 -0
  119. data/spec/fixtures/tag_create_with_description.json +1 -0
  120. data/spec/fixtures/tag_delete.json +1 -0
  121. data/spec/fixtures/tags.json +1 -0
  122. data/spec/fixtures/tree.json +1 -0
  123. data/spec/fixtures/trigger.json +7 -0
  124. data/spec/fixtures/triggers.json +16 -0
  125. data/spec/fixtures/user.json +1 -1
  126. data/spec/fixtures/user_block_unblock.json +1 -0
  127. data/spec/fixtures/user_email.json +1 -0
  128. data/spec/fixtures/user_emails.json +1 -0
  129. data/spec/fixtures/user_search.json +1 -0
  130. data/spec/fixtures/users.json +1 -1
  131. data/spec/fixtures/variable.json +4 -0
  132. data/spec/fixtures/variables.json +10 -0
  133. data/spec/gitlab/cli_helpers_spec.rb +57 -0
  134. data/spec/gitlab/cli_spec.rb +119 -0
  135. data/spec/gitlab/client/branches_spec.rb +99 -0
  136. data/spec/gitlab/client/build_triggers_spec.rb +67 -0
  137. data/spec/gitlab/client/build_variables_spec.rb +86 -0
  138. data/spec/gitlab/client/builds_spec.rb +148 -0
  139. data/spec/gitlab/client/client_spec.rb +11 -0
  140. data/spec/gitlab/client/commits_spec.rb +168 -0
  141. data/spec/gitlab/client/groups_spec.rb +116 -30
  142. data/spec/gitlab/client/issues_spec.rb +93 -29
  143. data/spec/gitlab/client/labels_spec.rb +68 -0
  144. data/spec/gitlab/client/merge_requests_spec.rb +171 -39
  145. data/spec/gitlab/client/milestones_spec.rb +45 -13
  146. data/spec/gitlab/client/namespaces_spec.rb +22 -0
  147. data/spec/gitlab/client/notes_spec.rb +82 -33
  148. data/spec/gitlab/client/pipelines_spec.rb +95 -0
  149. data/spec/gitlab/client/projects_spec.rb +371 -71
  150. data/spec/gitlab/client/repositories_spec.rb +51 -30
  151. data/spec/gitlab/client/repository_files_spec.rb +77 -0
  152. data/spec/gitlab/client/runners_spec.rb +185 -0
  153. data/spec/gitlab/client/services_spec.rb +55 -0
  154. data/spec/gitlab/client/snippets_spec.rb +35 -20
  155. data/spec/gitlab/client/system_hooks_spec.rb +69 -0
  156. data/spec/gitlab/client/tags_spec.rb +109 -0
  157. data/spec/gitlab/client/users_spec.rb +296 -34
  158. data/spec/gitlab/error_spec.rb +45 -0
  159. data/spec/gitlab/file_response_spec.rb +33 -0
  160. data/spec/gitlab/help_spec.rb +46 -0
  161. data/spec/gitlab/objectified_hash_spec.rb +48 -0
  162. data/spec/gitlab/page_links_spec.rb +16 -0
  163. data/spec/gitlab/paginated_response_spec.rb +60 -0
  164. data/spec/gitlab/request_spec.rb +73 -0
  165. data/spec/gitlab/shell_history_spec.rb +53 -0
  166. data/spec/gitlab/shell_spec.rb +80 -0
  167. data/spec/gitlab_spec.rb +48 -7
  168. data/spec/spec_helper.rb +24 -13
  169. metadata +287 -33
  170. data/spec/fixtures/create_merge_request.json +0 -1
  171. data/spec/fixtures/project_delete_key.json +0 -8
  172. data/spec/fixtures/update_merge_request.json +0 -1
@@ -1,18 +1,19 @@
1
1
  class Gitlab::Client
2
2
  # Defines methods related to groups.
3
+ # @see https://docs.gitlab.com/ce/api/groups.html
3
4
  module Groups
4
5
  # Gets a list of groups.
5
6
  #
6
7
  # @example
7
8
  # Gitlab.groups
8
- # Gitlab.groups(:per_page => 40)
9
+ # Gitlab.groups({ per_page: 40, page: 2 })
9
10
  #
10
11
  # @param [Hash] options A customizable set of options.
11
12
  # @option options [Integer] :page The page number.
12
13
  # @option options [Integer] :per_page The number of results per page.
13
14
  # @return [Array<Gitlab::ObjectifiedHash>]
14
15
  def groups(options={})
15
- get("/groups", :query => options)
16
+ get("/groups", query: options)
16
17
  end
17
18
 
18
19
  # Gets a single group.
@@ -28,19 +29,33 @@ class Gitlab::Client
28
29
 
29
30
  # Creates a new group.
30
31
  #
32
+ # @example
33
+ # Gitlab.create_group('new-group', 'group-path')
34
+ # Gitlab.create_group('gitlab', 'gitlab-path', { description: 'New Gitlab project' })
35
+ #
31
36
  # @param [String] name The name of a group.
32
37
  # @param [String] path The path of a group.
33
38
  # @return [Gitlab::ObjectifiedHash] Information about created group.
34
- def create_group(name, path)
35
- body = {:name => name, :path => path}
36
- post("/groups", :body => body)
39
+ def create_group(name, path, options={})
40
+ body = { name: name, path: path }.merge(options)
41
+ post("/groups", body: body)
42
+ end
43
+
44
+ # Delete's a group.
45
+ #
46
+ # @example
47
+ # Gitlab.delete_group(42)
48
+ # @param [Integer] id The ID of a group
49
+ # @return [Gitlab::ObjectifiedHash] Information about the deleted group.
50
+ def delete_group(id)
51
+ delete("/groups/#{id}")
37
52
  end
38
53
 
39
54
  # Get a list of group members.
40
55
  #
41
56
  # @example
42
57
  # Gitlab.group_members(1)
43
- # Gitlab.group_members(1, :per_page => 40)
58
+ # Gitlab.group_members(1, { per_page: 40 })
44
59
  #
45
60
  # @param [Integer] id The ID of a group.
46
61
  # @param [Hash] options A customizable set of options.
@@ -48,7 +63,7 @@ class Gitlab::Client
48
63
  # @option options [Integer] :per_page The number of results per page.
49
64
  # @return [Array<Gitlab::ObjectifiedHash>]
50
65
  def group_members(id, options={})
51
- get("/groups/#{id}/members", :query => options)
66
+ get("/groups/#{id}/members", query: options)
52
67
  end
53
68
 
54
69
  # Adds a user to group.
@@ -61,7 +76,20 @@ class Gitlab::Client
61
76
  # @param [Integer] access_level Project access level.
62
77
  # @return [Gitlab::ObjectifiedHash] Information about added team member.
63
78
  def add_group_member(team_id, user_id, access_level)
64
- post("/groups/#{team_id}/members", :body => {:user_id => user_id, :access_level => access_level})
79
+ post("/groups/#{team_id}/members", body: { user_id: user_id, access_level: access_level })
80
+ end
81
+
82
+ # Edit a user of a group.
83
+ #
84
+ # @example
85
+ # Gitlab.edit_group_member(1, 2, 40)
86
+ #
87
+ # @param [Integer] team_id The group id of member to edit.
88
+ # @param [Integer] user_id The user id of the user to edit.
89
+ # @param [Integer] access_level Project access level.
90
+ # @return [Gitlab::ObjectifiedHash] Information about edited team member.
91
+ def edit_group_member(team_id, user_id, access_level)
92
+ put("/groups/#{team_id}/members/#{user_id}", body: { access_level: access_level })
65
93
  end
66
94
 
67
95
  # Removes user from user group.
@@ -78,11 +106,39 @@ class Gitlab::Client
78
106
 
79
107
  # Transfers a project to a group
80
108
  #
109
+ # @example
110
+ # Gitlab.transfer_project_to_group(3, 50)
111
+ #
81
112
  # @param [Integer] id The ID of a group.
82
113
  # @param [Integer] project_id The ID of a project.
83
114
  def transfer_project_to_group(id, project_id)
84
- body = {:id => id, :project_id => project_id}
85
- post("/groups/#{id}/projects/#{project_id}", :body => body)
115
+ body = { id: id, project_id: project_id }
116
+ post("/groups/#{id}/projects/#{project_id}", body: body)
117
+ end
118
+
119
+ # Search for groups by name
120
+ #
121
+ # @example
122
+ # Gitlab.group_search('gitlab')
123
+ #
124
+ # @param [String] search A string to search for in group names and paths.
125
+ # @param [Hash] options A customizable set of options.
126
+ # @option options [String] :per_page Number of projects to return per page
127
+ # @option options [String] :page The page to retrieve
128
+ # @return [Array<Gitlab::ObjectifiedHash>]
129
+ def group_search(search, options={})
130
+ options[:search] = search
131
+ get("/groups", query: options)
132
+ end
133
+
134
+ # Get a list of projects under a group
135
+ # @example
136
+ # Gitlab.group_projects(1)
137
+ #
138
+ # @param [Integer] id The ID of a group
139
+ # @return [Array<Gitlab::ObjectifiedHash>] List of projects under a group
140
+ def group_projects(id, options={})
141
+ get("/groups/#{id}/projects", query: options)
86
142
  end
87
143
  end
88
144
  end
@@ -1,5 +1,6 @@
1
1
  class Gitlab::Client
2
2
  # Defines methods related to issues.
3
+ # @see https://docs.gitlab.com/ce/api/issues.html
3
4
  module Issues
4
5
  # Gets a list of user's issues.
5
6
  # Will return a list of project's issues if project ID passed.
@@ -7,18 +8,18 @@ class Gitlab::Client
7
8
  # @example
8
9
  # Gitlab.issues
9
10
  # Gitlab.issues(5)
10
- # Gitlab.issues(:per_page => 40)
11
+ # Gitlab.issues({ per_page: 40 })
11
12
  #
12
- # @param [Integer] project The ID of a project.
13
+ # @param [Integer, String] project The ID or name of a project.
13
14
  # @param [Hash] options A customizable set of options.
14
15
  # @option options [Integer] :page The page number.
15
16
  # @option options [Integer] :per_page The number of results per page.
16
17
  # @return [Array<Gitlab::ObjectifiedHash>]
17
18
  def issues(project=nil, options={})
18
- if project.to_i.zero?
19
- get("/issues", :query => options)
19
+ if project.to_s.empty? && project.to_i.zero?
20
+ get("/issues", query: options)
20
21
  else
21
- get("/projects/#{project}/issues", :query => options)
22
+ get("/projects/#{url_encode project}/issues", query: options)
22
23
  end
23
24
  end
24
25
 
@@ -27,16 +28,20 @@ class Gitlab::Client
27
28
  # @example
28
29
  # Gitlab.issue(5, 42)
29
30
  #
30
- # @param [Integer] project The ID of a project.
31
+ # @param [Integer, String] project The ID or name of a project.
31
32
  # @param [Integer] id The ID of an issue.
32
33
  # @return [Gitlab::ObjectifiedHash]
33
34
  def issue(project, id)
34
- get("/projects/#{project}/issues/#{id}")
35
+ get("/projects/#{url_encode project}/issues/#{id}")
35
36
  end
36
37
 
37
38
  # Creates a new issue.
38
39
  #
39
- # @param [Integer] project The ID of a project.
40
+ # @example
41
+ # Gitlab.create_issue(5, 'New issue')
42
+ # Gitlab.create_issue(5, 'New issue', { description: 'This is a new issue', assignee_id: 42 })
43
+ #
44
+ # @param [Integer, String] project The ID or name of a project.
40
45
  # @param [String] title The title of an issue.
41
46
  # @param [Hash] options A customizable set of options.
42
47
  # @option options [String] :description The description of an issue.
@@ -45,13 +50,16 @@ class Gitlab::Client
45
50
  # @option options [String] :labels Comma-separated label names for an issue.
46
51
  # @return [Gitlab::ObjectifiedHash] Information about created issue.
47
52
  def create_issue(project, title, options={})
48
- body = {:title => title}.merge(options)
49
- post("/projects/#{project}/issues", :body => body)
53
+ body = { title: title }.merge(options)
54
+ post("/projects/#{url_encode project}/issues", body: body)
50
55
  end
51
56
 
52
57
  # Updates an issue.
53
58
  #
54
- # @param [Integer] project The ID of a project.
59
+ # @example
60
+ # Gitlab.edit_issue(6, 1, { title: 'Updated title' })
61
+ #
62
+ # @param [Integer, String] project The ID or name of a project.
55
63
  # @param [Integer] id The ID of an issue.
56
64
  # @param [Hash] options A customizable set of options.
57
65
  # @option options [String] :title The title of an issue.
@@ -62,7 +70,7 @@ class Gitlab::Client
62
70
  # @option options [String] :state_event The state event of an issue ('close' or 'reopen').
63
71
  # @return [Gitlab::ObjectifiedHash] Information about updated issue.
64
72
  def edit_issue(project, id, options={})
65
- put("/projects/#{project}/issues/#{id}", :body => options)
73
+ put("/projects/#{url_encode project}/issues/#{id}", body: options)
66
74
  end
67
75
 
68
76
  # Closes an issue.
@@ -70,11 +78,11 @@ class Gitlab::Client
70
78
  # @example
71
79
  # Gitlab.close_issue(3, 42)
72
80
  #
73
- # @param [Integer] project The ID of a project.
81
+ # @param [Integer, String] project The ID or name of a project.
74
82
  # @param [Integer] id The ID of an issue.
75
83
  # @return [Gitlab::ObjectifiedHash] Information about closed issue.
76
84
  def close_issue(project, id)
77
- put("/projects/#{project}/issues/#{id}", :body => {:state_event => 'close'})
85
+ put("/projects/#{url_encode project}/issues/#{id}", body: { state_event: 'close' })
78
86
  end
79
87
 
80
88
  # Reopens an issue.
@@ -82,11 +90,48 @@ class Gitlab::Client
82
90
  # @example
83
91
  # Gitlab.reopen_issue(3, 42)
84
92
  #
85
- # @param [Integer] project The ID of a project.
93
+ # @param [Integer, String] project The ID or name of a project.
86
94
  # @param [Integer] id The ID of an issue.
87
95
  # @return [Gitlab::ObjectifiedHash] Information about reopened issue.
88
96
  def reopen_issue(project, id)
89
- put("/projects/#{project}/issues/#{id}", :body => {:state_event => 'reopen'})
97
+ put("/projects/#{url_encode project}/issues/#{id}", body: { state_event: 'reopen' })
98
+ end
99
+
100
+ # Subscribe to an issue.
101
+ #
102
+ # @example
103
+ # Gitlab.subscribe_to_issue(3, 42)
104
+ #
105
+ # @param [Integer, String] project The ID or name of a project.
106
+ # @param [Integer] id The ID of an issue.
107
+ # @return [Gitlab::ObjectifiedHash] Information about subscribed issue.
108
+ def subscribe_to_issue(project, id)
109
+ post("/projects/#{url_encode project}/issues/#{id}/subscribe")
110
+ end
111
+
112
+ # Unsubscribe from an issue.
113
+ #
114
+ # @example
115
+ # Gitlab.unsubscribe_from_issue(3, 42)
116
+ #
117
+ # @param [Integer, String] project The ID or name of a project.
118
+ # @param [Integer] id The ID of an issue.
119
+ # @return [Gitlab::ObjectifiedHash] Information about unsubscribed issue.
120
+ def unsubscribe_from_issue(project, id)
121
+ post("/projects/#{url_encode project}/issues/#{id}/unsubscribe")
122
+ end
123
+
124
+ # Deletes an issue.
125
+ # Only for admins and project owners
126
+ #
127
+ # @example
128
+ # Gitlab.delete_issue(3, 42)
129
+ #
130
+ # @param [Integer, String] project The ID or name of a project.
131
+ # @param [Integer] id The ID of an issue.
132
+ # @return [Gitlab::ObjectifiedHash] Information about deleted issue.
133
+ def delete_issue(project, id)
134
+ delete("/projects/#{url_encode project}/issues/#{id}")
90
135
  end
91
136
  end
92
137
  end
@@ -0,0 +1,57 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to labels.
3
+ # @see https://docs.gitlab.com/ce/api/labels.html
4
+ module Labels
5
+ # Gets a list of project's labels.
6
+ #
7
+ # @example
8
+ # Gitlab.labels(5)
9
+ #
10
+ # @param [Integer, String] project The ID or name of a project.
11
+ # @return [Array<Gitlab::ObjectifiedHash>]
12
+ def labels(project)
13
+ get("/projects/#{url_encode project}/labels")
14
+ end
15
+
16
+ # Creates a new label.
17
+ #
18
+ # @example
19
+ # Gitlab.create_label(42, "Backlog", '#DD10AA')
20
+ #
21
+ # @param [Integer, String] project The ID or name of a project.
22
+ # @option [String] name The name of a label.
23
+ # @option [String] color The color of a label.
24
+ # @return [Gitlab::ObjectifiedHash] Information about created label.
25
+ def create_label(project, name, color)
26
+ post("/projects/#{url_encode project}/labels", body: { name: name, color: color })
27
+ end
28
+
29
+ # Updates a label.
30
+ #
31
+ # @example
32
+ # Gitlab.edit_label(42, "Backlog", { new_name: 'TODO' })
33
+ # Gitlab.edit_label(42, "Backlog", { new_name: 'TODO', color: '#DD10AA' })
34
+ #
35
+ # @param [Integer, String] project The ID or name of a project.
36
+ # @param [String] name The name of a label.
37
+ # @param [Hash] options A customizable set of options.
38
+ # @option options [String] :new_name The new name of a label.
39
+ # @option options [String] :color The color of a label.
40
+ # @return [Gitlab::ObjectifiedHash] Information about updated label.
41
+ def edit_label(project, name, options={})
42
+ put("/projects/#{url_encode project}/labels", body: options.merge(name: name))
43
+ end
44
+
45
+ # Deletes a label.
46
+ #
47
+ # @example
48
+ # Gitlab.delete_label(2, 'Backlog')
49
+ #
50
+ # @param [Integer, String] project The ID or name of a project.
51
+ # @param [String] name The name of a label.
52
+ # @return [Gitlab::ObjectifiedHash] Information about deleted label.
53
+ def delete_label(project, name)
54
+ delete("/projects/#{url_encode project}/labels", body: { name: name })
55
+ end
56
+ end
57
+ end
@@ -1,19 +1,20 @@
1
1
  class Gitlab::Client
2
2
  # Defines methods related to merge requests.
3
+ # @see https://docs.gitlab.com/ce/api/merge_requests.html
3
4
  module MergeRequests
4
5
  # Gets a list of project merge requests.
5
6
  #
6
7
  # @example
7
8
  # Gitlab.merge_requests(5)
8
- # Gitlab.merge_requests(:per_page => 40)
9
+ # Gitlab.merge_requests({ per_page: 40 })
9
10
  #
10
- # @param [Integer] project The ID of a project.
11
+ # @param [Integer, String] project The ID or name of a project.
11
12
  # @param [Hash] options A customizable set of options.
12
13
  # @option options [Integer] :page The page number.
13
14
  # @option options [Integer] :per_page The number of results per page.
14
15
  # @return [Array<Gitlab::ObjectifiedHash>]
15
16
  def merge_requests(project, options={})
16
- get("/projects/#{project}/merge_requests", :query => options)
17
+ get("/projects/#{url_encode project}/merge_requests", query: options)
17
18
  end
18
19
 
19
20
  # Gets a single merge request.
@@ -21,74 +22,184 @@ class Gitlab::Client
21
22
  # @example
22
23
  # Gitlab.merge_request(5, 36)
23
24
  #
24
- # @param [Integer] project The ID of a project.
25
+ # @param [Integer, String] project The ID or name of a project.
25
26
  # @param [Integer] id The ID of a merge request.
26
27
  # @return <Gitlab::ObjectifiedHash]
27
28
  def merge_request(project, id)
28
- get("/projects/#{project}/merge_request/#{id}")
29
+ get("/projects/#{url_encode project}/merge_requests/#{id}")
29
30
  end
30
31
 
31
32
  # Creates a merge request.
32
33
  #
33
34
  # @example
34
35
  # Gitlab.create_merge_request(5, 'New merge request',
35
- # :source_branch => 'source_branch', :target_branch => 'target_branch')
36
+ # { source_branch: 'source_branch', target_branch: 'target_branch' })
36
37
  # Gitlab.create_merge_request(5, 'New merge request',
37
- # :source_branch => 'source_branch', :target_branch => 'target_branch', :assignee_id => 42)
38
+ # { source_branch: 'source_branch', target_branch: 'target_branch', assignee_id: 42 })
38
39
  #
39
- # @param [Integer] project The ID of a project.
40
+ # @param [Integer, String] project The ID or name of a project.
40
41
  # @param [String] title The title of a merge request.
41
42
  # @param [Hash] options A customizable set of options.
42
43
  # @option options [String] :source_branch (required) The source branch name.
43
44
  # @option options [String] :target_branch (required) The target branch name.
44
45
  # @option options [Integer] :assignee_id (optional) The ID of a user to assign merge request.
46
+ # @option options [Integer] :target_project_id (optional) The target project ID.
45
47
  # @return [Gitlab::ObjectifiedHash] Information about created merge request.
46
48
  def create_merge_request(project, title, options={})
47
- check_attributes!(options, [:source_branch, :target_branch])
48
-
49
- body = {:title => title}.merge(options)
50
- post("/projects/#{project}/merge_requests", :body => body)
49
+ body = { title: title }.merge(options)
50
+ post("/projects/#{url_encode project}/merge_requests", body: body)
51
51
  end
52
52
 
53
53
  # Updates a merge request.
54
54
  #
55
55
  # @example
56
- # Gitlab.update_merge_request(5, 42, :title => 'New title')
56
+ # Gitlab.update_merge_request(5, 42, { title: 'New title' })
57
57
  #
58
- # @param [Integer] project The ID of a project.
58
+ # @param [Integer, String] project The ID or name of a project.
59
59
  # @param [Integer] id The ID of a merge request.
60
60
  # @param [Hash] options A customizable set of options.
61
61
  # @option options [String] :title The title of a merge request.
62
62
  # @option options [String] :source_branch The source branch name.
63
63
  # @option options [String] :target_branch The target branch name.
64
64
  # @option options [Integer] :assignee_id The ID of a user to assign merge request.
65
+ # @option options [String] :state_event New state (close|reopen|merge).
65
66
  # @return [Gitlab::ObjectifiedHash] Information about updated merge request.
66
67
  def update_merge_request(project, id, options={})
67
- put("/projects/#{project}/merge_request/#{id}", :body => options)
68
+ put("/projects/#{url_encode project}/merge_requests/#{id}", body: options)
69
+ end
70
+
71
+ # Accepts a merge request.
72
+ #
73
+ # @example
74
+ # Gitlab.accept_merge_request(5, 42, { merge_commit_message: 'Nice!' })
75
+ #
76
+ # @param [Integer, String] project The ID or name of a project.
77
+ # @param [Integer] id The ID of a merge request.
78
+ # @param [Hash] options A customizable set of options.
79
+ # @option options [String] :merge_commit_message Custom merge commit message
80
+ # @return [Gitlab::ObjectifiedHash] Information about updated merge request.
81
+ def accept_merge_request(project, id, options={})
82
+ put("/projects/#{url_encode project}/merge_requests/#{id}/merge", body: options)
68
83
  end
69
84
 
70
85
  # Adds a comment to a merge request.
71
86
  #
72
87
  # @example
73
- # Gitlab.comment_merge_request(5, 1, "Awesome merge!")
74
- # Gitlab.comment_merge_request('gitlab', 1, "Awesome merge!")
88
+ # Gitlab.create_merge_request_comment(5, 1, "Awesome merge!")
89
+ # Gitlab.create_merge_request_comment('gitlab', 1, "Awesome merge!")
75
90
  #
76
- # @param [Integer] project The ID of a project.
91
+ # @param [Integer, String] project The ID or name of a project.
77
92
  # @param [Integer] id The ID of a merge request.
78
93
  # @param [String] note The content of a comment.
79
94
  # @return [Gitlab::ObjectifiedHash] Information about created merge request comment.
80
95
  def create_merge_request_comment(project, id, note)
81
- post("/projects/#{project}/merge_request/#{id}/comments", :body => {:note => note})
96
+ post("/projects/#{url_encode project}/merge_requests/#{id}/notes", body: { body: note })
97
+ end
98
+
99
+ # Adds a comment to a merge request.
100
+ #
101
+ # @example
102
+ # Gitlab.edit_merge_request_comment(5, 1,2, "Awesome merge!")
103
+ # Gitlab.edit_merge_request_comment('gitlab', 1, 2, "Awesome merge!")
104
+ #
105
+ # @param [Integer, String] project The ID or name of a project.
106
+ # @param [Integer] id The ID of a merge request.
107
+ # @param [Integer] id The ID of the merge-request comment
108
+ # @param [String] note The content of a comment.
109
+ # @return [Gitlab::ObjectifiedHash] Information about created merge request comment.
110
+ def edit_merge_request_comment(project, id, note_id , note)
111
+ put("/projects/#{url_encode project}/merge_requests/#{id}/notes/#{note_id}", body: { body: note })
112
+ end
113
+
114
+ # Deletes a comment from a merge request.
115
+ #
116
+ # @example
117
+ # Gitlab.delete_merge_request_comment(5, 1,2)
118
+ # Gitlab.delete_merge_request_comment('gitlab', 1, 2)
119
+ #
120
+ # @param [Integer, String] project The ID or name of a project.
121
+ # @param [Integer] id The ID of a merge request.
122
+ # @param [Integer] id The ID of the merge-request comment
123
+ # @return [Gitlab::ObjectifiedHash] Information about created merge request comment.
124
+ def delete_merge_request_comment(project, id, note_id)
125
+ delete("/projects/#{url_encode project}/merge_requests/#{id}/notes/#{note_id}")
126
+ end
127
+
128
+ # Gets the comments on a merge request.
129
+ #
130
+ # @example
131
+ # Gitlab.merge_request_comments(5, 1)
132
+ # Gitlab.merge_request_comments(5, 1, { per_page: 10, page: 2 })
133
+ #
134
+ # @param [Integer, String] project The ID or name of a project.
135
+ # @param [Integer] id The ID of a merge request.
136
+ # @param [Hash] options A customizable set of options.
137
+ # @option options [Integer] :page The page number.
138
+ # @option options [Integer] :per_page The number of results per page.
139
+ # @return [Gitlab::ObjectifiedHash] The merge request's comments.
140
+ def merge_request_comments(project, id, options={})
141
+ get("/projects/#{url_encode project}/merge_requests/#{id}/notes", query: options)
142
+ end
143
+
144
+ # Gets the changes of a merge request.
145
+ #
146
+ # @example
147
+ # Gitlab.merge_request_changes(5, 1)
148
+ #
149
+ # @param [Integer, String] project The ID or name of a project.
150
+ # @param [Integer] id The ID of a merge request.
151
+ # @return [Gitlab::ObjectifiedHash] The merge request's changes.
152
+ def merge_request_changes(project, id)
153
+ get("/projects/#{url_encode project}/merge_requests/#{id}/changes")
154
+ end
155
+
156
+ # Gets the commits of a merge request.
157
+ #
158
+ # @example
159
+ # Gitlab.merge_request_commits(5, 1)
160
+ #
161
+ # @param [Integer, String] project The ID or name of a project.
162
+ # @param [Integer] id The ID of a merge request.
163
+ # @return [Array<Gitlab::ObjectifiedHash>] The merge request's commits.
164
+ def merge_request_commits(project, id)
165
+ get("/projects/#{url_encode project}/merge_requests/#{id}/commits")
82
166
  end
83
167
 
84
- private
168
+ # List issues that will close on merge
169
+ #
170
+ # @example
171
+ # Gitlab.merge_request_closes_issues(5, 1)
172
+ #
173
+ # @param [Integer] project The ID of a project
174
+ # @param [Integer] iid The internal ID of a merge request
175
+ def merge_request_closes_issues(project_id, merge_request_iid)
176
+ get("/projects/#{project_id}/merge_requests/#{merge_request_iid}/closes_issues")
177
+ end
85
178
 
86
- def check_attributes!(options, attrs)
87
- attrs.each do |attr|
88
- unless options.has_key?(attr) || options.has_key?(attr.to_s)
89
- raise Gitlab::Error::MissingAttributes.new("Missing '#{attr}' parameter")
90
- end
91
- end
179
+ # Subscribes to a merge request.
180
+ #
181
+ # @example
182
+ # Gitlab.subscribe_to_merge_request(5, 1)
183
+ # Gitlab.subscribe_to_merge_request('gitlab', 1)
184
+ #
185
+ # @param [Integer, String] project The ID or name of a project.
186
+ # @param [Integer] id The ID of a merge request.
187
+ # @return [Gitlab::ObjectifiedHash] Information about subscribed merge request.
188
+ def subscribe_to_merge_request(project, id)
189
+ post("/projects/#{url_encode project}/merge_requests/#{id}/subscribe")
190
+ end
191
+
192
+ # Unsubscribes from a merge request.
193
+ #
194
+ # @example
195
+ # Gitlab.unsubscribe_from_merge_request(5, 1)
196
+ # Gitlab.unsubscribe_from_merge_request('gitlab', 1)
197
+ #
198
+ # @param [Integer, String] project The ID or name of a project.
199
+ # @param [Integer] id The ID of a merge request.
200
+ # @return [Gitlab::ObjectifiedHash] Information about unsubscribed merge request.
201
+ def unsubscribe_from_merge_request(project, id)
202
+ post("/projects/#{url_encode project}/merge_requests/#{id}/unsubscribe")
92
203
  end
93
204
  end
94
205
  end