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,16 +1,52 @@
1
1
  module Gitlab
2
2
  # Wrapper for the Gitlab REST API.
3
3
  class Client < API
4
- Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
4
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f }
5
5
 
6
- include Users
6
+ include Branches
7
+ include Builds
8
+ include BuildTriggers
9
+ include BuildVariables
10
+ include Commits
11
+ include Groups
7
12
  include Issues
8
- include Notes
13
+ include Labels
14
+ include MergeRequests
9
15
  include Milestones
10
- include Snippets
16
+ include Namespaces
17
+ include Notes
18
+ include Pipelines
11
19
  include Projects
12
20
  include Repositories
13
- include MergeRequests
14
- include Groups
21
+ include RepositoryFiles
22
+ include Runners
23
+ include Services
24
+ include Snippets
25
+ include SystemHooks
26
+ include Tags
27
+ include Users
28
+
29
+ # Text representation of the client, masking private token.
30
+ #
31
+ # @return [String]
32
+ def inspect
33
+ inspected = super
34
+
35
+ if @private_token
36
+ inspected = inspected.sub! @private_token, only_show_last_four_chars(@private_token)
37
+ end
38
+
39
+ inspected
40
+ end
41
+
42
+ def url_encode(s)
43
+ ERB::Util.url_encode(s)
44
+ end
45
+
46
+ private
47
+
48
+ def only_show_last_four_chars(token)
49
+ "#{'*'*(token.size - 4)}#{token[-4..-1]}"
50
+ end
15
51
  end
16
52
  end
@@ -0,0 +1,91 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to repositories.
3
+ # @see https://docs.gitlab.com/ce/api/branches.html
4
+ module Branches
5
+ # Gets a list of project repositiory branches.
6
+ #
7
+ # @example
8
+ # Gitlab.branches(42)
9
+ #
10
+ # @param [Integer, String] project The ID or name of a project.
11
+ # @param [Hash] options A customizable set of options.
12
+ # @option options [Integer] :page The page number.
13
+ # @option options [Integer] :per_page The number of results per page.
14
+ # @return [Array<Gitlab::ObjectifiedHash>]
15
+ def branches(project, options={})
16
+ get("/projects/#{url_encode project}/repository/branches", query: options)
17
+ end
18
+ alias_method :repo_branches, :branches
19
+
20
+ # Gets information about a repository branch.
21
+ #
22
+ # @example
23
+ # Gitlab.branch(3, 'api')
24
+ # Gitlab.repo_branch(5, 'master')
25
+ #
26
+ # @param [Integer, String] project The ID or name of a project.
27
+ # @param [String] branch The name of the branch.
28
+ # @return [Gitlab::ObjectifiedHash]
29
+ def branch(project, branch)
30
+ get("/projects/#{url_encode project}/repository/branches/#{branch}")
31
+ end
32
+ alias_method :repo_branch, :branch
33
+
34
+ # Protects a repository branch.
35
+ #
36
+ # @example
37
+ # Gitlab.protect_branch(3, 'api')
38
+ # Gitlab.repo_protect_branch(5, 'master')
39
+ #
40
+ # @param [Integer, String] project The ID or name of a project.
41
+ # @param [String] branch The name of the branch.
42
+ # @return [Gitlab::ObjectifiedHash]
43
+ def protect_branch(project, branch)
44
+ put("/projects/#{url_encode project}/repository/branches/#{branch}/protect")
45
+ end
46
+ alias_method :repo_protect_branch, :protect_branch
47
+
48
+ # Unprotects a repository branch.
49
+ #
50
+ # @example
51
+ # Gitlab.unprotect_branch(3, 'api')
52
+ # Gitlab.repo_unprotect_branch(5, 'master')
53
+ #
54
+ # @param [Integer, String] project The ID or name of a project.
55
+ # @param [String] branch The name of the branch.
56
+ # @return [Gitlab::ObjectifiedHash]
57
+ def unprotect_branch(project, branch)
58
+ put("/projects/#{url_encode project}/repository/branches/#{branch}/unprotect")
59
+ end
60
+ alias_method :repo_unprotect_branch, :unprotect_branch
61
+
62
+ # Creates a repository branch. Requires Gitlab >= 6.8.x
63
+ #
64
+ # @example
65
+ # Gitlab.create_branch(3, 'api')
66
+ # Gitlab.repo_create_branch(5, 'master')
67
+ #
68
+ # @param [Integer, String] project The ID or name of a project.
69
+ # @param [String] branch The name of the new branch.
70
+ # @param [String] ref Create branch from commit sha or existing branch
71
+ # @return [Gitlab::ObjectifiedHash]
72
+ def create_branch(project, branch, ref)
73
+ post("/projects/#{url_encode project}/repository/branches", body: { branch_name: branch, ref: ref })
74
+ end
75
+ alias_method :repo_create_branch, :create_branch
76
+
77
+ # Deletes a repository branch. Requires Gitlab >= 6.8.x
78
+ #
79
+ # @example
80
+ # Gitlab.delete_branch(3, 'api')
81
+ # Gitlab.repo_delete_branch(5, 'master')
82
+ #
83
+ # @param [Integer, String] project The ID or name of a project.
84
+ # @param [String] branch The name of the branch to delete
85
+ # @return [Gitlab::ObjectifiedHash]
86
+ def delete_branch(project, branch)
87
+ delete("/projects/#{url_encode project}/repository/branches/#{branch}")
88
+ end
89
+ alias_method :repo_delete_branch, :delete_branch
90
+ end
91
+ end
@@ -0,0 +1,51 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to builds.
3
+ # @see https://docs.gitlab.com/ce/api/build_triggers.html
4
+ module BuildTriggers
5
+ # Gets a list of the project's build triggers
6
+ #
7
+ # @example
8
+ # Gitlab.triggers(5)
9
+ #
10
+ # @param [Integer, String] project The ID or name of a project.
11
+ # @return [Array<Gitlab::ObjectifiedHash>] The list of triggers.
12
+ def triggers(project)
13
+ get("/projects/#{url_encode project}/triggers")
14
+ end
15
+
16
+ # Gets details of project's build trigger.
17
+ #
18
+ # @example
19
+ # Gitlab.trigger(5, '7b9148c158980bbd9bcea92c17522d')
20
+ #
21
+ # @param [Integer, String] project The ID or name of a project.
22
+ # @param [String] token The token of a trigger.
23
+ # @return [Gitlab::ObjectifiedHash] The trigger.
24
+ def trigger(project, token)
25
+ get("/projects/#{url_encode project}/triggers/#{token}")
26
+ end
27
+
28
+ # Create a build trigger for a project.
29
+ #
30
+ # @example
31
+ # Gitlab.create_trigger(5)
32
+ #
33
+ # @param [Integer, String] project The ID or name of a project.
34
+ # @return [Gitlab::ObjectifiedHash] The trigger.
35
+ def create_trigger(project)
36
+ post("/projects/#{url_encode project}/triggers")
37
+ end
38
+
39
+ # Remove a project's build trigger.
40
+ #
41
+ # @example
42
+ # Gitlab.remove_trigger(5, '7b9148c158980bbd9bcea92c17522d')
43
+ #
44
+ # @param [Integer, String] project The ID or name of a project.
45
+ # @param [String] token The token of a trigger.
46
+ # @return [Gitlab::ObjectifiedHash] The trigger.
47
+ def remove_trigger(project, token)
48
+ delete("/projects/#{url_encode project}/triggers/#{token}")
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,66 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to builds.
3
+ # @see https://docs.gitlab.com/ce/api/build_variables.html
4
+ module BuildVariables
5
+ # Gets a list of the project's build variables
6
+ #
7
+ # @example
8
+ # Gitlab.variables(5)
9
+ #
10
+ # @param [Integer, String] project The ID or name of a project.
11
+ # @return [Array<Gitlab::ObjectifiedHash>] The list of variables.
12
+ def variables(project)
13
+ get("/projects/#{url_encode project}/variables")
14
+ end
15
+
16
+ # Gets details of a project's specific build variable.
17
+ #
18
+ # @example
19
+ # Gitlab.build(5, "TEST_VARIABLE_1")
20
+ #
21
+ # @param [Integer, String] project The ID or name of a project.
22
+ # @param [String] key The key of a variable.
23
+ # @return [Gitlab::ObjectifiedHash] The variable.
24
+ def variable(project, key)
25
+ get("/projects/#{url_encode project}/variables/#{key}")
26
+ end
27
+
28
+ # Create a build variable for a project.
29
+ #
30
+ # @example
31
+ # Gitlab.create_variable(5, "NEW_VARIABLE", "new value")
32
+ #
33
+ # @param [Integer, String] project The ID or name of a project.
34
+ # @param [String] key The key of a variable; must have no more than 255 characters; only `A-Z`, `a-z`, `0-9` and `_` are allowed
35
+ # @param [String] value The value of a variable
36
+ # @return [Gitlab::ObjectifiedHash] The variable.
37
+ def create_variable(project, key, value)
38
+ post("/projects/#{url_encode project}/variables", body: { key: key, value: value })
39
+ end
40
+
41
+ # Update a project's build variable.
42
+ #
43
+ # @example
44
+ # Gitlab.create_variable(5, "NEW_VARIABLE", "updated value")
45
+ #
46
+ # @param [Integer, String] project The ID or name of a project.
47
+ # @param [String] key The key of a variable
48
+ # @param [String] value The value of a variable
49
+ # @return [Gitlab::ObjectifiedHash] The variable.
50
+ def update_variable(project, key, value)
51
+ put("/projects/#{url_encode project}/variables/#{key}", body: { value: value })
52
+ end
53
+
54
+ # Remove a project's build variable.
55
+ #
56
+ # @example
57
+ # Gitlab.remove_variable(5, "VARIABLE_1")
58
+ #
59
+ # @param [Integer, String] project The ID or name of a project.
60
+ # @param [String] key The key of a variable.
61
+ # @return [Gitlab::ObjectifiedHash] The variable.
62
+ def remove_variable(project, key)
63
+ delete("/projects/#{url_encode project}/variables/#{key}")
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,106 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to builds.
3
+ # @see https://docs.gitlab.com/ce/api/builds.html
4
+ module Builds
5
+ # Gets a list of project builds.
6
+ #
7
+ # @example
8
+ # Gitlab.builds(5)
9
+ # Gitlab.builds(5, { per_page: 10, page: 2 })
10
+ #
11
+ # @param [Integer, String] project The ID or name 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
+ # @param [Integer, String] project The ID or name of a project.
16
+ # @return [Array<Gitlab::ObjectifiedHash>]
17
+ def builds(project, options={})
18
+ get("/projects/#{url_encode project}/builds", query: options)
19
+ end
20
+
21
+ # Gets a single build.
22
+ #
23
+ # @example
24
+ # Gitlab.build(5, 36)
25
+ #
26
+ # @param [Integer, String] project The ID or name of a project.
27
+ # @param [Integer] id The ID of a build.
28
+ # @return [Gitlab::ObjectifiedHash]
29
+ def build(project, id)
30
+ get("/projects/#{url_encode project}/builds/#{id}")
31
+ end
32
+
33
+ # Gets build artifacts.
34
+ #
35
+ # @example
36
+ # Gitlab.build_artifacts(1, 8)
37
+ #
38
+ # @param [Integer, String] project The ID or name of a project.
39
+ # @param [Integer] id The ID of a build.
40
+ # @return [Gitlab::FileResponse]
41
+ def build_artifacts(project, id)
42
+ get("/projects/#{url_encode project}/builds/#{id}/artifacts",
43
+ format: nil,
44
+ headers: { Accept: 'application/octet-stream' },
45
+ parser: proc { |body, _|
46
+ if body.encoding == Encoding::ASCII_8BIT # binary response
47
+ ::Gitlab::FileResponse.new StringIO.new(body, 'rb+')
48
+ else # error with json response
49
+ ::Gitlab::Request.parse(body)
50
+ end
51
+ })
52
+ end
53
+
54
+ # Gets a list of builds for specific commit in a project.
55
+ #
56
+ # @example
57
+ # Gitlab.commit_builds(5, 'asdf')
58
+ # Gitlab.commit_builds(5, 'asdf', { per_page: 10, page: 2 })
59
+ #
60
+ # @param [Integer, String] project The ID or name of a project.
61
+ # @param [String] sha The SHA checksum of a commit.
62
+ # @param [Hash] options A customizable set of options.
63
+ # @option options [Integer] :page The page number.
64
+ # @option options [Integer] :per_page The number of results per page.
65
+ # @return [Array<Gitlab::ObjectifiedHash>] The list of builds.
66
+ def commit_builds(project, sha, options={})
67
+ get("/projects/#{url_encode project}/repository/commits/#{sha}/builds", query: options)
68
+ end
69
+
70
+ # Cancels a build.
71
+ #
72
+ # @example
73
+ # Gitlab.build_cancel(5, 1)
74
+ #
75
+ # @param [Integer, String] project The ID or name of a project.
76
+ # @param [Integer] id The ID of a build.
77
+ # @return [Gitlab::ObjectifiedHash] The builds changes.
78
+ def build_cancel(project, id)
79
+ post("/projects/#{url_encode project}/builds/#{id}/cancel")
80
+ end
81
+
82
+ # Retry a build.
83
+ #
84
+ # @example
85
+ # Gitlab.build_retry(5, 1)
86
+ #
87
+ # @param [Integer, String] project The ID or name of a project.
88
+ # @param [Integer] id The ID of a build.
89
+ # @return [Array<Gitlab::ObjectifiedHash>] The builds changes.
90
+ def build_retry(project, id)
91
+ post("/projects/#{url_encode project}/builds/#{id}/retry")
92
+ end
93
+
94
+ # Erase a single build of a project (remove build artifacts and a build trace)
95
+ #
96
+ # @example
97
+ # Gitlab.build_erase(5, 1)
98
+ #
99
+ # @param [Integer, String] project The ID or name of a project.
100
+ # @param [Integer] id The ID of a build.
101
+ # @return [Gitlab::ObjectifiedHash] The build's changes.
102
+ def build_erase(project, id)
103
+ post("/projects/#{url_encode project}/builds/#{id}/erase")
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,146 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to repository commits.
3
+ # @see https://docs.gitlab.com/ce/api/commits.html
4
+ module Commits
5
+ # Gets a list of project commits.
6
+ #
7
+ # @example
8
+ # Gitlab.commits('viking')
9
+ # Gitlab.repo_commits('gitlab', { ref_name: 'api' })
10
+ #
11
+ # @param [Integer, String] project The ID or name of a project.
12
+ # @param [Hash] options A customizable set of options.
13
+ # @option options [String] :ref_name The branch or tag name of a project repository.
14
+ # @option options [Integer] :page The page number.
15
+ # @option options [Integer] :per_page The number of results per page.
16
+ # @return [Array<Gitlab::ObjectifiedHash>]
17
+ def commits(project, options={})
18
+ get("/projects/#{url_encode project}/repository/commits", query: options)
19
+ end
20
+ alias_method :repo_commits, :commits
21
+
22
+ # Gets a specific commit identified by the commit hash or name of a branch or tag.
23
+ #
24
+ # @example
25
+ # Gitlab.commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
26
+ # Gitlab.repo_commit(3, 'ed899a2f4b50b4370feeea94676502b42383c746')
27
+ #
28
+ # @param [Integer, String] project The ID or name of a project.
29
+ # @param [String] sha The commit hash or name of a repository branch or tag
30
+ # @return [Gitlab::ObjectifiedHash]
31
+ def commit(project, sha)
32
+ get("/projects/#{url_encode project}/repository/commits/#{sha}")
33
+ end
34
+ alias_method :repo_commit, :commit
35
+
36
+ # Get the diff of a commit in a project.
37
+ #
38
+ # @example
39
+ # Gitlab.commit_diff(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
40
+ # Gitlab.repo_commit_diff(3, 'ed899a2f4b50b4370feeea94676502b42383c746')
41
+ #
42
+ # @param [Integer, String] project The ID or name of a project.
43
+ # @param [String] sha The name of a repository branch or tag or if not given the default branch.
44
+ # @return [Gitlab::ObjectifiedHash]
45
+ def commit_diff(project, sha)
46
+ get("/projects/#{url_encode project}/repository/commits/#{sha}/diff")
47
+ end
48
+ alias_method :repo_commit_diff, :commit_diff
49
+
50
+ # Gets a list of comments for a commit.
51
+ #
52
+ # @example
53
+ # Gitlab.commit_comments(5, 'c9f9662a9b1116c838b523ed64c6abdb4aae4b8b')
54
+ #
55
+ # @param [Integer] project The ID of a project.
56
+ # @param [String] sha The commit hash or name of a repository branch or tag.
57
+ # @option options [Integer] :page The page number.
58
+ # @option options [Integer] :per_page The number of results per page.
59
+ # @return [Array<Gitlab::ObjectifiedHash>]
60
+ def commit_comments(project, commit, options={})
61
+ get("/projects/#{url_encode project}/repository/commits/#{commit}/comments", query: options)
62
+ end
63
+ alias_method :repo_commit_comments, :commit_comments
64
+
65
+ # Creates a new comment for a commit.
66
+ #
67
+ # @example
68
+ # Gitlab.create_commit_comment(5, 'c9f9662a9b1116c838b523ed64c6abdb4aae4b8b', 'Nice work on this commit!')
69
+ #
70
+ # @param [Integer, String] project The ID or name of a project.
71
+ # @param [String] sha The commit hash or name of a repository branch or tag.
72
+ # @param [String] note The text of a comment.
73
+ # @param [Hash] options A customizable set of options.
74
+ # @option options [String] :path The file path.
75
+ # @option options [Integer] :line The line number.
76
+ # @option options [String] :line_type The line type (new or old).
77
+ # @return [Gitlab::ObjectifiedHash] Information about created comment.
78
+ def create_commit_comment(project, commit, note, options={})
79
+ post("/projects/#{url_encode project}/repository/commits/#{commit}/comments", body: options.merge(note: note))
80
+ end
81
+ alias_method :repo_create_commit_comment, :create_commit_comment
82
+
83
+ # Get the status of a commit
84
+ #
85
+ # @example
86
+ # Gitlab.commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
87
+ # Gitlab.commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', { name: 'jenkins' })
88
+ # Gitlab.commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', { name: 'jenkins', all: true })
89
+ #
90
+ # @param [Integer, String] project The ID or name of a project.
91
+ # @param [String] sha The commit hash
92
+ # @param [Hash] options A customizable set of options.
93
+ # @option options [String] :ref Filter by ref name, it can be branch or tag
94
+ # @option options [String] :stage Filter by stage
95
+ # @option options [String] :name Filter by status name, eg. jenkins
96
+ # @option options [Boolean] :all The flag to return all statuses, not only latest ones
97
+ def commit_status(id, sha, options={})
98
+ get("/projects/#{id}/repository/commits/#{sha}/statuses", query: options)
99
+ end
100
+ alias_method :repo_commit_status, :commit_status
101
+
102
+ # Adds or updates a status of a commit.
103
+ #
104
+ # @example
105
+ # Gitlab.update_commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'success')
106
+ # Gitlab.update_commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'failed', { name: 'jenkins' })
107
+ # Gitlab.update_commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'canceled', { name: 'jenkins', target_url: 'http://example.com/builds/1' })
108
+ #
109
+ # @param [Integer, String] project The ID or name of a project.
110
+ # @param [String] sha The commit hash
111
+ # @param [String] state of the status. Can be: pending, running, success, failed, canceled
112
+ # @param [Hash] options A customizable set of options.
113
+ # @option options [String] :ref The ref (branch or tag) to which the status refers
114
+ # @option options [String] :name Filter by status name, eg. jenkins
115
+ # @option options [String] :target_url The target URL to associate with this status
116
+ def update_commit_status(id, sha, state, options={})
117
+ post("/projects/#{id}/statuses/#{sha}", query: options.merge(state: state))
118
+ end
119
+ alias_method :repo_update_commit_status, :update_commit_status
120
+
121
+ # Creates a single commit with one or more changes
122
+ #
123
+ # @see https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
124
+ # Introduced in Gitlab 8.13
125
+ #
126
+ # @example
127
+ # Gitlab.create_commit(2726132, 'master', 'refactors everything', [{action: 'create', file_path: '/foo.txt', content: 'bar'}])
128
+ # Gitlab.create_commit(2726132, 'master', 'refactors everything', [{action: 'delete', file_path: '/foo.txt'}])
129
+ #
130
+ # @param [Integer, String] project The ID or name of a project.
131
+ # @param [String] branch the branch name you wish to commit to
132
+ # @param [String] message the commit message
133
+ # @param [Array[Hash]] An array of action hashes to commit as a batch. See the next table for what attributes it can take.
134
+ # @option options [String] :author_email the email address of the author
135
+ # @option options [String] :author_name the name of the author
136
+ # @return [Gitlab::ObjectifiedHash] hash of commit related data
137
+ def create_commit(project, branch, message, actions, options={})
138
+ payload = {
139
+ branch_name: branch,
140
+ commit_message: message,
141
+ actions: actions,
142
+ }.merge(options)
143
+ post("/projects/#{url_encode project}/repository/commits", query: payload)
144
+ end
145
+ end
146
+ end