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,65 +1,59 @@
1
1
  class Gitlab::Client
2
2
  # Defines methods related to repositories.
3
+ # @see https://docs.gitlab.com/ce/api/repositories.html
3
4
  module Repositories
4
- # Gets a list of project repository tags.
5
+ # Get file tree project (root level).
5
6
  #
6
7
  # @example
7
- # Gitlab.tags(42)
8
+ # Gitlab.tree(42)
9
+ # Gitlab.tree(42, { path: 'Gemfile' })
8
10
  #
9
- # @param [Integer] project The ID of a project.
11
+ # @param [Integer, String] project The ID or name of a project.
10
12
  # @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
- # @return [Array<Gitlab::ObjectifiedHash>]
14
- def tags(project, options={})
15
- get("/projects/#{project}/repository/tags", :query => options)
13
+ # @option options [String] :path The path inside repository.
14
+ # @option options [String] :ref_name The name of a repository branch or tag.
15
+ # @return [Gitlab::ObjectifiedHash]
16
+ def tree(project, options={})
17
+ get("/projects/#{url_encode project}/repository/tree", query: options)
16
18
  end
17
- alias_method :repo_tags, :tags
19
+ alias_method :repo_tree, :tree
18
20
 
19
- # Gets a list of project repositiory branches.
21
+ # Get project repository archive
20
22
  #
21
23
  # @example
22
- # Gitlab.branches(42)
23
- #
24
- # @param [Integer] project The ID of a project.
25
- # @param [Hash] options A customizable set of options.
26
- # @option options [Integer] :page The page number.
27
- # @option options [Integer] :per_page The number of results per page.
28
- # @return [Array<Gitlab::ObjectifiedHash>]
29
- def branches(project, options={})
30
- get("/projects/#{project}/repository/branches", :query => options)
24
+ # Gitlab.repo_archive(42)
25
+ # Gitlab.repo_archive(42, 'deadbeef')
26
+ #
27
+ # @param [Integer, String] project The ID or name of a project.
28
+ # @param [String] ref The commit sha, branch, or tag to download.
29
+ # @return [Gitlab::FileResponse]
30
+ def repo_archive(project, ref = 'master')
31
+ get("/projects/#{url_encode project}/repository/archive",
32
+ format: nil,
33
+ headers: { Accept: 'application/octet-stream' },
34
+ query: { sha: ref },
35
+ parser: proc { |body, _|
36
+ if body.encoding == Encoding::ASCII_8BIT # binary response
37
+ ::Gitlab::FileResponse.new StringIO.new(body, 'rb+')
38
+ else # error with json response
39
+ ::Gitlab::Request.parse(body)
40
+ end
41
+ })
31
42
  end
32
- alias_method :repo_branches, :branches
33
43
 
34
- # Gets information about a repository branch.
44
+ # Compares branches, tags or commits.
35
45
  #
36
46
  # @example
37
- # Gitlab.branch(3, 'api')
38
- # Gitlab.repo_branch(5, 'master')
47
+ # Gitlab.compare(42, 'master', 'feature/branch')
48
+ # Gitlab.repo_compare(42, 'master', 'feature/branch')
39
49
  #
40
- # @param [Integer] project The ID of a project.
41
- # @param [String] branch The name of the branch.
50
+ # @param [Integer] project The ID of a project.
51
+ # @param [String] from The commit SHA or branch name of from branch.
52
+ # @param [String] to The commit SHA or branch name of to branch.
42
53
  # @return [Gitlab::ObjectifiedHash]
43
- def branch(project, branch)
44
- get("/projects/#{project}/repository/branches/#{branch}")
45
- end
46
- alias_method :repo_branch, :branch
47
-
48
- # Gets a list of project commits.
49
- #
50
- # @example
51
- # Gitlab.commits('viking')
52
- # Gitlab.repo_commits('gitlab', :ref_name => 'api')
53
- #
54
- # @param [Integer] project The ID of a project.
55
- # @param [Hash] options A customizable set of options.
56
- # @option options [String] :ref_name The branch or tag name of a project repository.
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 commits(project, options={})
61
- get("/projects/#{project}/repository/commits", :query => options)
54
+ def compare(project, from, to)
55
+ get("/projects/#{url_encode project}/repository/compare", query: { from: from, to: to })
62
56
  end
63
- alias_method :repo_commits, :commits
57
+ alias_method :repo_compare, :compare
64
58
  end
65
59
  end
@@ -0,0 +1,107 @@
1
+ require 'base64'
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to repository files.
5
+ # @see https://docs.gitlab.com/ce/api/repository_files.html
6
+ module RepositoryFiles
7
+ # Get the contents of a file
8
+ #
9
+ # @example
10
+ # Gitlab.file_contents(42, 'Gemfile')
11
+ # Gitlab.repo_file_contents(3, 'Gemfile', 'ed899a2f4b50b4370feeea94676502b42383c746')
12
+ #
13
+ # @param [Integer, String] project The ID or name of a project.
14
+ # @param [String] filepath The relative path of the file in the repository
15
+ # @param [String] ref The name of a repository branch or tag or if not given the default branch.
16
+ # @return [String]
17
+ def file_contents(project, filepath, ref='master')
18
+ ref = URI.encode(ref, /\W/)
19
+ get "/projects/#{url_encode project}/repository/files/#{url_encode filepath}/raw",
20
+ query: { ref: ref},
21
+ format: nil,
22
+ headers: { Accept: 'text/plain' },
23
+ parser: ::Gitlab::Request::Parser
24
+ end
25
+ alias_method :repo_file_contents, :file_contents
26
+
27
+ # Gets a repository file.
28
+ #
29
+ # @example
30
+ # Gitlab.get_file(42, "README.md", "master")
31
+ #
32
+ # @param [Integer, String] project The ID or name of a project.
33
+ # @param [String] file_path The full path of the file.
34
+ # @param [String] ref The name of branch, tag or commit.
35
+ # @return [Gitlab::ObjectifiedHash]
36
+ def get_file(project, file_path, ref)
37
+ get("/projects/#{url_encode project}/repository/files/#{url_encode file_path}", query: {
38
+ ref: ref
39
+ })
40
+ end
41
+
42
+ # Creates a new repository file.
43
+ #
44
+ # @example
45
+ # Gitlab.create_file(42, "path", "branch", "content", "commit message")
46
+ #
47
+ # @param [Integer, String] project The ID or name of a project.
48
+ # @param [String] full path to new file.
49
+ # @param [String] the name of the branch.
50
+ # @param [String] file content.
51
+ # @param [String] commit message.
52
+ # @return [Gitlab::ObjectifiedHash]
53
+ def create_file(project, path, branch, content, commit_message)
54
+ post("/projects/#{url_encode project}/repository/files", body: {
55
+ file_path: path,
56
+ branch_name: branch,
57
+ commit_message: commit_message
58
+ }.merge(encoded_content_attributes(content)))
59
+ end
60
+
61
+ # Edits an existing repository file.
62
+ #
63
+ # @example
64
+ # Gitlab.edit_file(42, "path", "branch", "content", "commit message")
65
+ #
66
+ # @param [Integer, String] project The ID or name of a project.
67
+ # @param [String] full path to new file.
68
+ # @param [String] the name of the branch.
69
+ # @param [String] file content.
70
+ # @param [String] commit message.
71
+ # @return [Gitlab::ObjectifiedHash]
72
+ def edit_file(project, path, branch, content, commit_message)
73
+ put("/projects/#{url_encode project}/repository/files", body: {
74
+ file_path: path,
75
+ branch_name: branch,
76
+ commit_message: commit_message
77
+ }.merge(encoded_content_attributes(content)))
78
+ end
79
+
80
+ # Removes an existing repository file.
81
+ #
82
+ # @example
83
+ # Gitlab.remove_file(42, "path", "branch", "commit message")
84
+ #
85
+ # @param [Integer, String] project The ID or name of a project.
86
+ # @param [String] full path to new file.
87
+ # @param [String] the name of the branch.
88
+ # @param [String] commit message.
89
+ # @return [Gitlab::ObjectifiedHash]
90
+ def remove_file(project, path, branch, commit_message)
91
+ delete("/projects/#{url_encode project}/repository/files", body: {
92
+ file_path: path,
93
+ branch_name: branch,
94
+ commit_message: commit_message
95
+ })
96
+ end
97
+
98
+ private
99
+
100
+ def encoded_content_attributes(content)
101
+ {
102
+ encoding: 'base64',
103
+ content: Base64.encode64(content)
104
+ }
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,115 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to runners.
3
+ # @see https://docs.gitlab.com/ce/api/runners.html
4
+ module Runners
5
+
6
+ # Get a list of specific runners available to the user.
7
+ # @see https://docs.gitlab.com/ce/api/runners.html#list-owned-runners
8
+ #
9
+ # @example
10
+ # Gitlab.runners
11
+ # Gitlab.runners(:active)
12
+ # Gitlab.runners(:paused)
13
+ #
14
+ # @param [Hash] options A customizable set of options.
15
+ # @option options [String] :scope The scope of specific runners to show, one of: active, paused, online; showing all runners if none provided
16
+ # @return [Array<Gitlab::ObjectifiedHash>]
17
+ def runners(options = {})
18
+ get("/runners", query: options)
19
+ end
20
+
21
+ # Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges.
22
+ # @see https://docs.gitlab.com/ce/api/runners.html#list-all-runners
23
+ #
24
+ # @example
25
+ # Gitlab.all_runners
26
+ #
27
+ # @param [Hash] options A customizable set of options.
28
+ # @option options [String] :scope The scope of runners to show, one of: specific, shared, active, paused, online; showing all runners if none provided
29
+ # @return [Array<Gitlab::ObjectifiedHash>]
30
+ def all_runners(options = {})
31
+ get("/runners/all", query: options)
32
+ end
33
+
34
+ # Get details of a runner..
35
+ # @see https://docs.gitlab.com/ce/api/runners.html#get-runners-details
36
+ #
37
+ # @example
38
+ # Gitlab.runner(42)
39
+ #
40
+ # @param [Integer, String] id The ID of a runner
41
+ # @return <Gitlab::ObjectifiedHash>
42
+ def runner(id)
43
+ get("/runners/#{id}")
44
+ end
45
+
46
+ # Update details of a runner.
47
+ # @see https://docs.gitlab.com/ce/api/runners.html#update-runners-details
48
+ #
49
+ # @example
50
+ # Gitlab.update_runner(42, { description: 'Awesome runner' })
51
+ # Gitlab.update_runner(42, { active: false })
52
+ # Gitlab.update_runner(42, { tag_list: [ 'awesome', 'runner' ] })
53
+ #
54
+ # @param [Integer, String] id The ID of a runner
55
+ # @param [Hash] options A customizable set of options.
56
+ # @option options [String] :active The state of a runner; can be set to true or false.
57
+ # @option options [String] :tag_list The list of tags for a runner; put array of tags, that should be finally assigned to a runner
58
+ # @return <Gitlab::ObjectifiedHash>
59
+ def update_runner(id, options={})
60
+ put("/runners/#{id}", query: options)
61
+ end
62
+
63
+ # Remove a runner.
64
+ # @see https://docs.gitlab.com/ce/api/runners.html#remove-a-runner
65
+ #
66
+ # @example
67
+ # Gitlab.delete_runner(42)
68
+ #
69
+ # @param [Integer, String] id The ID of a runner
70
+ # @return <Gitlab::ObjectifiedHash>
71
+ def delete_runner(id)
72
+ delete("/runners/#{id}")
73
+ end
74
+
75
+ # List all runners (specific and shared) available in the project. Shared runners are listed if at least one shared runner is defined and shared runners usage is enabled in the project's settings.
76
+ # @see https://docs.gitlab.com/ce/api/runners.html#list-projects-runners
77
+ #
78
+ # @example
79
+ # Gitlab.project_runners(42)
80
+ #
81
+ # @param [Integer, String] id The ID or name of a project.
82
+ # @return [Array<Gitlab::ObjectifiedHash>]
83
+ def project_runners(project_id)
84
+ get("/projects/#{url_encode project_id}/runners")
85
+ end
86
+
87
+ # Enable an available specific runner in the project.
88
+ # @see https://docs.gitlab.com/ce/api/runners.html#enable-a-runner-in-project
89
+ #
90
+ # @example
91
+ # Gitlab.project_enable_runner(2, 42)
92
+ #
93
+ # @param [Integer, String] id The ID or name of a project.
94
+ # @param [Integer, String] id The ID of a runner.
95
+ # @return <Gitlab::ObjectifiedHash>
96
+ def project_enable_runner(project_id, id)
97
+ body = { runner_id: id }
98
+ post("/projects/#{url_encode project_id}/runners", body: body)
99
+ end
100
+
101
+ # Disable a specific runner from the project. It works only if the project isn't the only project associated with the specified runner.
102
+ # @see https://docs.gitlab.com/ce/api/runners.html#disable-a-runner-from-project
103
+ #
104
+ # @example
105
+ # Gitlab.project_disable_runner(2, 42)
106
+ #
107
+ # @param [Integer, String] id The ID or name of a project.
108
+ # @param [Integer, String] runner_id The ID of a runner.
109
+ # @return <Gitlab::ObjectifiedHash>
110
+ def project_disable_runner(id, runner_id)
111
+ delete("/projects/#{url_encode id}/runners/#{runner_id}")
112
+ end
113
+
114
+ end
115
+ end
@@ -0,0 +1,50 @@
1
+ class Gitlab::Client
2
+ # Third party services connected to a project.
3
+ # @see https://docs.gitlab.com/ce/api/services.html
4
+ module Services
5
+ # Create/Edit service
6
+ # Full service params documentation: https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/services.md
7
+ #
8
+ # @example
9
+ # Gitlab.change_service(42, :redmine, { new_issue_url: 'https://example.com/projects/test_project/issues/new',
10
+ # project_url: 'https://example.com/projects/test_project/issues',
11
+ # issues_url: 'https://example.com/issues/:id' })
12
+ #
13
+ # @param [Integer, String] project The ID or name of a project.
14
+ # @param [String] service A service code name.
15
+ # @param [Hash] params A service parameters.
16
+ # @return [Boolean]
17
+ def change_service(project, service, params)
18
+ put("/projects/#{url_encode project}/services/#{correct_service_name(service)}", body: params)
19
+ end
20
+
21
+ # Delete service
22
+ #
23
+ # @example
24
+ # Gitlab.delete_service(42, :redmine)
25
+ #
26
+ # @param [Integer, String] project The ID or name of a project.
27
+ # @param [String] service A service code name.
28
+ # @return [Boolean]
29
+ def delete_service(project, service)
30
+ delete("/projects/#{url_encode project}/services/#{correct_service_name(service)}")
31
+ end
32
+
33
+ # Get service
34
+ #
35
+ # @example
36
+ # Gitlab.service(42, :redmine)
37
+ #
38
+ # @param [Integer, String] project The ID or name of a project.
39
+ # @param [String] service A service code name.
40
+ # @return [Gitlab::ObjectifiedHash]
41
+ def service(project, service)
42
+ get("/projects/#{url_encode project}/services/#{correct_service_name(service)}")
43
+ end
44
+
45
+ private
46
+ def correct_service_name(service)
47
+ service.to_s.gsub('_', '-')
48
+ end
49
+ end
50
+ end
@@ -1,18 +1,19 @@
1
1
  class Gitlab::Client
2
2
  # Defines methods related to snippets.
3
+ # @see https://docs.gitlab.com/ce/api/project_snippets.html
3
4
  module Snippets
4
5
  # Gets a list of project's snippets.
5
6
  #
6
7
  # @example
7
8
  # Gitlab.snippets(42)
8
9
  #
9
- # @param [Integer] project The ID of a project.
10
+ # @param [Integer, String] project The ID or name of a project.
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 [Gitlab::ObjectifiedHash]
14
15
  def snippets(project, options={})
15
- get("/projects/#{project}/snippets", :query => options)
16
+ get("/projects/#{url_encode project}/snippets", query: options)
16
17
  end
17
18
 
18
19
  # Gets information about a snippet.
@@ -20,19 +21,19 @@ class Gitlab::Client
20
21
  # @example
21
22
  # Gitlab.snippet(2, 14)
22
23
  #
23
- # @param [Integer] project The ID of a project.
24
+ # @param [Integer, String] project The ID or name of a project.
24
25
  # @param [Integer] id The ID of a snippet.
25
26
  # @return [Gitlab::ObjectifiedHash]
26
27
  def snippet(project, id)
27
- get("/projects/#{project}/snippets/#{id}")
28
+ get("/projects/#{url_encode project}/snippets/#{id}")
28
29
  end
29
30
 
30
31
  # Creates a new snippet.
31
32
  #
32
33
  # @example
33
- # Gitlab.create_snippet(42, {:title => 'REST', :file_name => 'api.rb', :code => 'some code'})
34
+ # Gitlab.create_snippet(42, { title: 'REST', file_name: 'api.rb', code: 'some code' })
34
35
  #
35
- # @param [Integer] project The ID of a project.
36
+ # @param [Integer, String] project The ID or name of a project.
36
37
  # @param [Hash] options A customizable set of options.
37
38
  # @option options [String] :title (required) The title of a snippet.
38
39
  # @option options [String] :file_name (required) The name of a snippet file.
@@ -40,16 +41,15 @@ class Gitlab::Client
40
41
  # @option options [String] :lifetime (optional) The expiration date of a snippet.
41
42
  # @return [Gitlab::ObjectifiedHash] Information about created snippet.
42
43
  def create_snippet(project, options={})
43
- check_attributes!(options, [:title, :file_name, :code])
44
- post("/projects/#{project}/snippets", :body => options)
44
+ post("/projects/#{url_encode project}/snippets", body: options)
45
45
  end
46
46
 
47
47
  # Updates a snippet.
48
48
  #
49
49
  # @example
50
- # Gitlab.edit_snippet(42, 34, :file_name => 'README.txt')
50
+ # Gitlab.edit_snippet(42, 34, { file_name: 'README.txt' })
51
51
  #
52
- # @param [Integer] project The ID of a project.
52
+ # @param [Integer, String] project The ID or name of a project.
53
53
  # @param [Integer] id The ID of a snippet.
54
54
  # @param [Hash] options A customizable set of options.
55
55
  # @option options [String] :title The title of a snippet.
@@ -58,7 +58,7 @@ class Gitlab::Client
58
58
  # @option options [String] :lifetime The expiration date of a snippet.
59
59
  # @return [Gitlab::ObjectifiedHash] Information about updated snippet.
60
60
  def edit_snippet(project, id, options={})
61
- put("/projects/#{project}/snippets/#{id}", :body => options)
61
+ put("/projects/#{url_encode project}/snippets/#{id}", body: options)
62
62
  end
63
63
 
64
64
  # Deletes a snippet.
@@ -66,21 +66,26 @@ class Gitlab::Client
66
66
  # @example
67
67
  # Gitlab.delete_snippet(2, 14)
68
68
  #
69
- # @param [Integer] project The ID of a project.
69
+ # @param [Integer, String] project The ID or name of a project.
70
70
  # @param [Integer] id The ID of a snippet.
71
71
  # @return [Gitlab::ObjectifiedHash] Information about deleted snippet.
72
72
  def delete_snippet(project, id)
73
- delete("/projects/#{project}/snippets/#{id}")
73
+ delete("/projects/#{url_encode project}/snippets/#{id}")
74
74
  end
75
75
 
76
- private
77
-
78
- def check_attributes!(options, attrs)
79
- attrs.each do |attr|
80
- unless options.has_key?(attr) || options.has_key?(attr.to_s)
81
- raise Gitlab::Error::MissingAttributes.new("Missing '#{attr}' parameter")
82
- end
83
- end
76
+ # Returns raw project snippet content as plain text.
77
+ #
78
+ # @example
79
+ # Gitlab.snippet_content(2, 14)
80
+ #
81
+ # @param [Integer, String] project The ID or name of a project.
82
+ # @param [Integer] id The ID of a snippet.
83
+ # @return [Gitlab::ObjectifiedHash] Information about deleted snippet.
84
+ def snippet_content(project, id)
85
+ get("/projects/#{url_encode project}/snippets/#{id}/raw",
86
+ format: nil,
87
+ headers: { Accept: 'text/plain' },
88
+ parser: ::Gitlab::Request::Parser)
84
89
  end
85
90
  end
86
91
  end