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.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.travis.yml +6 -2
- data/CHANGELOG.md +244 -0
- data/CONTRIBUTING.md +195 -0
- data/LICENSE.txt +1 -1
- data/README.md +122 -10
- data/Rakefile +1 -1
- data/bin/console +10 -0
- data/bin/setup +6 -0
- data/exe/gitlab +7 -0
- data/gitlab.gemspec +9 -3
- data/lib/gitlab.rb +18 -2
- data/lib/gitlab/api.rb +6 -4
- data/lib/gitlab/cli.rb +89 -0
- data/lib/gitlab/cli_helpers.rb +241 -0
- data/lib/gitlab/client.rb +42 -6
- data/lib/gitlab/client/branches.rb +91 -0
- data/lib/gitlab/client/build_triggers.rb +51 -0
- data/lib/gitlab/client/build_variables.rb +66 -0
- data/lib/gitlab/client/builds.rb +106 -0
- data/lib/gitlab/client/commits.rb +146 -0
- data/lib/gitlab/client/groups.rb +66 -10
- data/lib/gitlab/client/issues.rb +61 -16
- data/lib/gitlab/client/labels.rb +57 -0
- data/lib/gitlab/client/merge_requests.rb +137 -26
- data/lib/gitlab/client/milestones.rb +44 -9
- data/lib/gitlab/client/namespaces.rb +20 -0
- data/lib/gitlab/client/notes.rb +71 -16
- data/lib/gitlab/client/pipelines.rb +68 -0
- data/lib/gitlab/client/projects.rb +236 -27
- data/lib/gitlab/client/repositories.rb +39 -45
- data/lib/gitlab/client/repository_files.rb +107 -0
- data/lib/gitlab/client/runners.rb +115 -0
- data/lib/gitlab/client/services.rb +50 -0
- data/lib/gitlab/client/snippets.rb +26 -21
- data/lib/gitlab/client/system_hooks.rb +59 -0
- data/lib/gitlab/client/tags.rb +96 -0
- data/lib/gitlab/client/users.rb +151 -7
- data/lib/gitlab/configuration.rb +20 -4
- data/lib/gitlab/error.rb +55 -12
- data/lib/gitlab/file_response.rb +46 -0
- data/lib/gitlab/help.rb +95 -0
- data/lib/gitlab/objectified_hash.rb +19 -3
- data/lib/gitlab/page_links.rb +33 -0
- data/lib/gitlab/paginated_response.rb +97 -0
- data/lib/gitlab/request.rb +65 -33
- data/lib/gitlab/shell.rb +84 -0
- data/lib/gitlab/shell_history.rb +59 -0
- data/lib/gitlab/version.rb +1 -1
- data/spec/fixtures/{project_branch.json → branch.json} +1 -1
- data/spec/fixtures/branch_delete.json +3 -0
- data/spec/fixtures/{project_branches.json → branches.json} +0 -0
- data/spec/fixtures/build.json +38 -0
- data/spec/fixtures/build_artifacts.json +0 -0
- data/spec/fixtures/build_cancel.json +24 -0
- data/spec/fixtures/build_erase.json +24 -0
- data/spec/fixtures/build_retry.json +24 -0
- data/spec/fixtures/builds.json +78 -0
- data/spec/fixtures/builds_commits.json +64 -0
- data/spec/fixtures/compare_merge_request_diff.json +31 -0
- data/spec/fixtures/error_project_not_found.json +1 -0
- data/spec/fixtures/get_repository_file.json +1 -0
- data/spec/fixtures/group_create_with_description.json +1 -0
- data/spec/fixtures/group_delete.json +1 -0
- data/spec/fixtures/group_member_edit.json +1 -0
- data/spec/fixtures/group_projects.json +44 -0
- data/spec/fixtures/group_search.json +2 -0
- data/spec/fixtures/label.json +1 -0
- data/spec/fixtures/labels.json +1 -0
- data/spec/fixtures/merge_request_changes.json +1 -0
- data/spec/fixtures/merge_request_closes_issues.json +1 -0
- data/spec/fixtures/{comment_merge_request.json → merge_request_comment.json} +0 -0
- data/spec/fixtures/merge_request_comments.json +1 -0
- data/spec/fixtures/merge_request_commits.json +1 -0
- data/spec/fixtures/milestone_issues.json +1 -0
- data/spec/fixtures/milestone_merge_requests.json +1 -0
- data/spec/fixtures/namespaces.json +1 -0
- data/spec/fixtures/pipeline.json +23 -0
- data/spec/fixtures/pipeline_cancel.json +23 -0
- data/spec/fixtures/pipeline_create.json +23 -0
- data/spec/fixtures/pipeline_retry.json +23 -0
- data/spec/fixtures/pipelines.json +48 -0
- data/spec/fixtures/project_commit.json +13 -0
- data/spec/fixtures/project_commit_comment.json +1 -0
- data/spec/fixtures/project_commit_comments.json +1 -0
- data/spec/fixtures/project_commit_create.json +22 -0
- data/spec/fixtures/project_commit_diff.json +10 -0
- data/spec/fixtures/project_commit_status.json +42 -0
- data/spec/fixtures/project_edit.json +21 -0
- data/spec/fixtures/project_events.json +1 -0
- data/spec/fixtures/project_fork.json +50 -0
- data/spec/fixtures/project_forked_for_user.json +50 -0
- data/spec/fixtures/project_runner_enable.json +7 -0
- data/spec/fixtures/project_runners.json +16 -0
- data/spec/fixtures/project_search.json +1 -0
- data/spec/fixtures/project_star.json +44 -0
- data/spec/fixtures/project_tag_annotated.json +1 -0
- data/spec/fixtures/project_tag_lightweight.json +1 -0
- data/spec/fixtures/project_unstar.json +44 -0
- data/spec/fixtures/project_update_commit_status.json +20 -0
- data/spec/fixtures/push_rule.json +1 -0
- data/spec/fixtures/raw_file.json +2 -0
- data/spec/fixtures/release_create.json +1 -0
- data/spec/fixtures/release_update.json +1 -0
- data/spec/fixtures/repository_file.json +1 -0
- data/spec/fixtures/runner.json +26 -0
- data/spec/fixtures/runner_delete.json +7 -0
- data/spec/fixtures/runner_edit.json +26 -0
- data/spec/fixtures/runners.json +16 -0
- data/spec/fixtures/runners_all.json +30 -0
- data/spec/fixtures/service.json +1 -0
- data/spec/fixtures/shell_history.json +2 -0
- data/spec/fixtures/snippet_content.json +3 -0
- data/spec/fixtures/system_hook.json +1 -0
- data/spec/fixtures/system_hooks.json +1 -0
- data/spec/fixtures/tag.json +1 -0
- data/spec/fixtures/tag_create.json +1 -0
- data/spec/fixtures/tag_create_with_description.json +1 -0
- data/spec/fixtures/tag_delete.json +1 -0
- data/spec/fixtures/tags.json +1 -0
- data/spec/fixtures/tree.json +1 -0
- data/spec/fixtures/trigger.json +7 -0
- data/spec/fixtures/triggers.json +16 -0
- data/spec/fixtures/user.json +1 -1
- data/spec/fixtures/user_block_unblock.json +1 -0
- data/spec/fixtures/user_email.json +1 -0
- data/spec/fixtures/user_emails.json +1 -0
- data/spec/fixtures/user_search.json +1 -0
- data/spec/fixtures/users.json +1 -1
- data/spec/fixtures/variable.json +4 -0
- data/spec/fixtures/variables.json +10 -0
- data/spec/gitlab/cli_helpers_spec.rb +57 -0
- data/spec/gitlab/cli_spec.rb +119 -0
- data/spec/gitlab/client/branches_spec.rb +99 -0
- data/spec/gitlab/client/build_triggers_spec.rb +67 -0
- data/spec/gitlab/client/build_variables_spec.rb +86 -0
- data/spec/gitlab/client/builds_spec.rb +148 -0
- data/spec/gitlab/client/client_spec.rb +11 -0
- data/spec/gitlab/client/commits_spec.rb +168 -0
- data/spec/gitlab/client/groups_spec.rb +116 -30
- data/spec/gitlab/client/issues_spec.rb +93 -29
- data/spec/gitlab/client/labels_spec.rb +68 -0
- data/spec/gitlab/client/merge_requests_spec.rb +171 -39
- data/spec/gitlab/client/milestones_spec.rb +45 -13
- data/spec/gitlab/client/namespaces_spec.rb +22 -0
- data/spec/gitlab/client/notes_spec.rb +82 -33
- data/spec/gitlab/client/pipelines_spec.rb +95 -0
- data/spec/gitlab/client/projects_spec.rb +371 -71
- data/spec/gitlab/client/repositories_spec.rb +51 -30
- data/spec/gitlab/client/repository_files_spec.rb +77 -0
- data/spec/gitlab/client/runners_spec.rb +185 -0
- data/spec/gitlab/client/services_spec.rb +55 -0
- data/spec/gitlab/client/snippets_spec.rb +35 -20
- data/spec/gitlab/client/system_hooks_spec.rb +69 -0
- data/spec/gitlab/client/tags_spec.rb +109 -0
- data/spec/gitlab/client/users_spec.rb +296 -34
- data/spec/gitlab/error_spec.rb +45 -0
- data/spec/gitlab/file_response_spec.rb +33 -0
- data/spec/gitlab/help_spec.rb +46 -0
- data/spec/gitlab/objectified_hash_spec.rb +48 -0
- data/spec/gitlab/page_links_spec.rb +16 -0
- data/spec/gitlab/paginated_response_spec.rb +60 -0
- data/spec/gitlab/request_spec.rb +73 -0
- data/spec/gitlab/shell_history_spec.rb +53 -0
- data/spec/gitlab/shell_spec.rb +80 -0
- data/spec/gitlab_spec.rb +48 -7
- data/spec/spec_helper.rb +24 -13
- metadata +287 -33
- data/spec/fixtures/create_merge_request.json +0 -1
- data/spec/fixtures/project_delete_key.json +0 -8
- data/spec/fixtures/update_merge_request.json +0 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
class Gitlab::Client
|
|
2
|
+
# Defines methods related to system hooks.
|
|
3
|
+
# @see https://docs.gitlab.com/ce/api/system_hooks.html
|
|
4
|
+
module SystemHooks
|
|
5
|
+
# Gets a list of system hooks.
|
|
6
|
+
#
|
|
7
|
+
# @example
|
|
8
|
+
# Gitlab.hooks
|
|
9
|
+
# Gitlab.system_hooks
|
|
10
|
+
#
|
|
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 hooks(options={})
|
|
16
|
+
get("/hooks", query: options)
|
|
17
|
+
end
|
|
18
|
+
alias_method :system_hooks, :hooks
|
|
19
|
+
|
|
20
|
+
# Adds a new system hook.
|
|
21
|
+
#
|
|
22
|
+
# @example
|
|
23
|
+
# Gitlab.add_hook('http://example.com/hook')
|
|
24
|
+
# Gitlab.add_system_hook('https://api.example.net/v1/hook')
|
|
25
|
+
#
|
|
26
|
+
# @param [String] url The hook URL.
|
|
27
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
28
|
+
def add_hook(url)
|
|
29
|
+
post("/hooks", body: { url: url })
|
|
30
|
+
end
|
|
31
|
+
alias_method :add_system_hook, :add_hook
|
|
32
|
+
|
|
33
|
+
# Tests a system hook.
|
|
34
|
+
#
|
|
35
|
+
# @example
|
|
36
|
+
# Gitlab.hook(3)
|
|
37
|
+
# Gitlab.system_hook(12)
|
|
38
|
+
#
|
|
39
|
+
# @param [Integer] id The ID of a system hook.
|
|
40
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
|
41
|
+
def hook(id)
|
|
42
|
+
get("/hooks/#{id}")
|
|
43
|
+
end
|
|
44
|
+
alias_method :system_hook, :hook
|
|
45
|
+
|
|
46
|
+
# Deletes a new system hook.
|
|
47
|
+
#
|
|
48
|
+
# @example
|
|
49
|
+
# Gitlab.delete_hook(3)
|
|
50
|
+
# Gitlab.delete_system_hook(12)
|
|
51
|
+
#
|
|
52
|
+
# @param [Integer] id The ID of a system hook.
|
|
53
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
54
|
+
def delete_hook(id)
|
|
55
|
+
delete("/hooks/#{id}")
|
|
56
|
+
end
|
|
57
|
+
alias_method :delete_system_hook, :delete_hook
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
class Gitlab::Client
|
|
2
|
+
# Defines methods related to tags.
|
|
3
|
+
# @see https://docs.gitlab.com/ce/api/tags.html
|
|
4
|
+
module Tags
|
|
5
|
+
# Gets a list of project repository tags.
|
|
6
|
+
#
|
|
7
|
+
# @example
|
|
8
|
+
# Gitlab.tags(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 tags(project, options={})
|
|
16
|
+
get("/projects/#{url_encode project}/repository/tags", query: options)
|
|
17
|
+
end
|
|
18
|
+
alias_method :repo_tags, :tags
|
|
19
|
+
|
|
20
|
+
# Creates a new project repository tag.
|
|
21
|
+
#
|
|
22
|
+
# @example
|
|
23
|
+
# Gitlab.create_tag(42, 'new_tag', 'master')
|
|
24
|
+
# Gitlab.create_tag(42, 'v1.0', 'master', 'Release 1.0')
|
|
25
|
+
#
|
|
26
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
27
|
+
# @param [String] tag_name The name of the new tag.
|
|
28
|
+
# @param [String] ref The ref (commit sha, branch name, or another tag) the tag will point to.
|
|
29
|
+
# @param [String] message Optional message for tag, creates annotated tag if specified.
|
|
30
|
+
# @param [String] description Optional release notes for tag.
|
|
31
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
32
|
+
def create_tag(project, tag_name, ref, message='', description=nil)
|
|
33
|
+
post("/projects/#{url_encode project}/repository/tags", body: { tag_name: tag_name, ref: ref, message: message, description: description })
|
|
34
|
+
end
|
|
35
|
+
alias_method :repo_create_tag, :create_tag
|
|
36
|
+
|
|
37
|
+
# Gets information about a repository tag.
|
|
38
|
+
#
|
|
39
|
+
# @example
|
|
40
|
+
# Gitlab.tag(3, 'api')
|
|
41
|
+
# Gitlab.repo_tag(5, 'master')
|
|
42
|
+
#
|
|
43
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
44
|
+
# @param [String] tag The name of the tag.
|
|
45
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
46
|
+
def tag(project, tag)
|
|
47
|
+
get("/projects/#{url_encode project}/repository/tags/#{tag}")
|
|
48
|
+
end
|
|
49
|
+
alias_method :repo_tag, :tag
|
|
50
|
+
|
|
51
|
+
# Deletes a repository tag. Requires Gitlab >= 6.8.x
|
|
52
|
+
#
|
|
53
|
+
# @example
|
|
54
|
+
# Gitlab.delete_tag(3, 'api')
|
|
55
|
+
# Gitlab.repo_delete_tag(5, 'master')
|
|
56
|
+
#
|
|
57
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
58
|
+
# @param [String] tag The name of the tag to delete
|
|
59
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
60
|
+
def delete_tag(project, tag)
|
|
61
|
+
delete("/projects/#{url_encode project}/repository/tags/#{tag}")
|
|
62
|
+
end
|
|
63
|
+
alias_method :repo_delete_tag, :delete_tag
|
|
64
|
+
|
|
65
|
+
# Adds release notes to an existing repository tag. Requires Gitlab >= 8.2.0
|
|
66
|
+
#
|
|
67
|
+
# @example
|
|
68
|
+
# Gitlab.create_release(3, '1.0.0', 'This is ready for production')
|
|
69
|
+
# Gitlab.repo_create_release(5, '1.0.0', 'This is ready for production')
|
|
70
|
+
#
|
|
71
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
72
|
+
# @param [String] tag The name of the new tag.
|
|
73
|
+
# @param [String] description Release notes with markdown support
|
|
74
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
75
|
+
def create_release(project, tag, description)
|
|
76
|
+
post("/projects/#{url_encode project}/repository/tags/#{tag}/release", body: { description: description })
|
|
77
|
+
end
|
|
78
|
+
alias_method :repo_create_release, :create_release
|
|
79
|
+
|
|
80
|
+
# Updates the release notes of a given release. Requires Gitlab >= 8.2.0
|
|
81
|
+
#
|
|
82
|
+
# @example
|
|
83
|
+
# Gitlab.update_release(3, '1.0.0', 'This is even more ready for production')
|
|
84
|
+
# Gitlab.repo_update_release(5, '1.0.0', 'This is even more ready for production')
|
|
85
|
+
#
|
|
86
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
87
|
+
# @param [String] tag The name of the new tag.
|
|
88
|
+
# @param [String] description Release notes with markdown support
|
|
89
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
90
|
+
def update_release(project, tag, description)
|
|
91
|
+
put("/projects/#{url_encode project}/repository/tags/#{tag}/release", body: { description: description })
|
|
92
|
+
end
|
|
93
|
+
alias_method :repo_update_release, :update_release
|
|
94
|
+
|
|
95
|
+
end
|
|
96
|
+
end
|
data/lib/gitlab/client/users.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
class Gitlab::Client
|
|
2
2
|
# Defines methods related to users.
|
|
3
|
+
# @see https://docs.gitlab.com/ce/api/users.html
|
|
4
|
+
# @see https://docs.gitlab.com/ce/api/session.html
|
|
3
5
|
module Users
|
|
4
6
|
# Gets a list of users.
|
|
5
7
|
#
|
|
@@ -11,7 +13,7 @@ class Gitlab::Client
|
|
|
11
13
|
# @option options [Integer] :per_page The number of results per page.
|
|
12
14
|
# @return [Array<Gitlab::ObjectifiedHash>]
|
|
13
15
|
def users(options={})
|
|
14
|
-
get("/users", :
|
|
16
|
+
get("/users", query: options)
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
# Gets information about a user.
|
|
@@ -30,18 +32,82 @@ class Gitlab::Client
|
|
|
30
32
|
# Creates a new user.
|
|
31
33
|
# Requires authentication from an admin account.
|
|
32
34
|
#
|
|
35
|
+
# @example
|
|
36
|
+
# Gitlab.create_user('joe@foo.org', 'secret', 'joe', { name: 'Joe Smith' })
|
|
37
|
+
# or
|
|
38
|
+
# Gitlab.create_user('joe@foo.org', 'secret')
|
|
39
|
+
#
|
|
33
40
|
# @param [String] email The email of a user.
|
|
34
41
|
# @param [String] password The password of a user.
|
|
42
|
+
# @param [String] username The username of a user.
|
|
43
|
+
# @param [Hash] options A customizable set of options.
|
|
44
|
+
# @option options [String] :name The name of a user. Defaults to email.
|
|
45
|
+
# @option options [String] :skype The skype of a user.
|
|
46
|
+
# @option options [String] :linkedin The linkedin of a user.
|
|
47
|
+
# @option options [String] :twitter The twitter of a user.
|
|
48
|
+
# @option options [Integer] :projects_limit The limit of projects for a user.
|
|
49
|
+
# @return [Gitlab::ObjectifiedHash] Information about created user.
|
|
50
|
+
def create_user(*args)
|
|
51
|
+
options = Hash === args.last ? args.pop : {}
|
|
52
|
+
if args[2]
|
|
53
|
+
body = { email: args[0], password: args[1], username: args[2] }
|
|
54
|
+
else
|
|
55
|
+
body = { email: args[0], password: args[1], name: args[0] }
|
|
56
|
+
end
|
|
57
|
+
body.merge!(options)
|
|
58
|
+
post('/users', body: body)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Updates a user.
|
|
62
|
+
#
|
|
63
|
+
# @example
|
|
64
|
+
# Gitlab.edit_user(15, { email: 'joe.smith@foo.org', projects_limit: 20 })
|
|
65
|
+
#
|
|
66
|
+
# @param [Integer] id The ID of a user.
|
|
35
67
|
# @param [Hash] options A customizable set of options.
|
|
68
|
+
# @option options [String] :email The email of a user.
|
|
69
|
+
# @option options [String] :password The password of a user.
|
|
36
70
|
# @option options [String] :name The name of a user. Defaults to email.
|
|
37
71
|
# @option options [String] :skype The skype of a user.
|
|
38
72
|
# @option options [String] :linkedin The linkedin of a user.
|
|
39
73
|
# @option options [String] :twitter The twitter of a user.
|
|
40
74
|
# @option options [Integer] :projects_limit The limit of projects for a user.
|
|
41
75
|
# @return [Gitlab::ObjectifiedHash] Information about created user.
|
|
42
|
-
def
|
|
43
|
-
|
|
44
|
-
|
|
76
|
+
def edit_user(user_id, options={})
|
|
77
|
+
put("/users/#{user_id}", body: options)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Deletes a user.
|
|
81
|
+
#
|
|
82
|
+
# @example
|
|
83
|
+
# Gitlab.delete_user(1)
|
|
84
|
+
#
|
|
85
|
+
# @param [Integer] id The ID of a user.
|
|
86
|
+
# @return [Gitlab::ObjectifiedHash] Information about deleted user.
|
|
87
|
+
def delete_user(user_id)
|
|
88
|
+
delete("/users/#{user_id}")
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Blocks the specified user. Available only for admin.
|
|
92
|
+
#
|
|
93
|
+
# @example
|
|
94
|
+
# Gitlab.block_user(15)
|
|
95
|
+
#
|
|
96
|
+
# @param [Integer] user_id The Id of user
|
|
97
|
+
# @return [Boolean] success or not
|
|
98
|
+
def block_user(user_id)
|
|
99
|
+
post("/users/#{user_id}/block")
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Unblocks the specified user. Available only for admin.
|
|
103
|
+
#
|
|
104
|
+
# @example
|
|
105
|
+
# Gitlab.unblock_user(15)
|
|
106
|
+
#
|
|
107
|
+
# @param [Integer] user_id The Id of user
|
|
108
|
+
# @return [Boolean] success or not
|
|
109
|
+
def unblock_user(user_id)
|
|
110
|
+
post("/users/#{user_id}/unblock")
|
|
45
111
|
end
|
|
46
112
|
|
|
47
113
|
# Creates a new user session.
|
|
@@ -52,21 +118,29 @@ class Gitlab::Client
|
|
|
52
118
|
# @param [String] email The email of a user.
|
|
53
119
|
# @param [String] password The password of a user.
|
|
54
120
|
# @return [Gitlab::ObjectifiedHash]
|
|
121
|
+
# @note This method doesn't require private_token to be set.
|
|
55
122
|
def session(email, password)
|
|
56
|
-
post("/session", :
|
|
123
|
+
post("/session", body: { email: email, password: password })
|
|
57
124
|
end
|
|
58
125
|
|
|
59
126
|
# Gets a list of user's SSH keys.
|
|
60
127
|
#
|
|
61
128
|
# @example
|
|
62
129
|
# Gitlab.ssh_keys
|
|
130
|
+
# Gitlab.ssh_keys({ user_id: 2 })
|
|
63
131
|
#
|
|
64
132
|
# @param [Hash] options A customizable set of options.
|
|
65
133
|
# @option options [Integer] :page The page number.
|
|
66
134
|
# @option options [Integer] :per_page The number of results per page.
|
|
135
|
+
# @option options [Integer] :user_id The ID of the user to retrieve the keys for.
|
|
67
136
|
# @return [Array<Gitlab::ObjectifiedHash>]
|
|
68
137
|
def ssh_keys(options={})
|
|
69
|
-
|
|
138
|
+
user_id = options.delete :user_id
|
|
139
|
+
if user_id.to_i.zero?
|
|
140
|
+
get("/user/keys", query: options)
|
|
141
|
+
else
|
|
142
|
+
get("/users/#{user_id}/keys", query: options)
|
|
143
|
+
end
|
|
70
144
|
end
|
|
71
145
|
|
|
72
146
|
# Gets information about SSH key.
|
|
@@ -89,7 +163,7 @@ class Gitlab::Client
|
|
|
89
163
|
# @param [String] key The SSH key body.
|
|
90
164
|
# @return [Gitlab::ObjectifiedHash] Information about created SSH key.
|
|
91
165
|
def create_ssh_key(title, key)
|
|
92
|
-
post("/user/keys", :
|
|
166
|
+
post("/user/keys", body: { title: title, key: key })
|
|
93
167
|
end
|
|
94
168
|
|
|
95
169
|
# Deletes an SSH key.
|
|
@@ -102,5 +176,75 @@ class Gitlab::Client
|
|
|
102
176
|
def delete_ssh_key(id)
|
|
103
177
|
delete("/user/keys/#{id}")
|
|
104
178
|
end
|
|
179
|
+
|
|
180
|
+
# Gets user emails.
|
|
181
|
+
# Will return emails an authorized user if no user ID passed.
|
|
182
|
+
#
|
|
183
|
+
# @example
|
|
184
|
+
# Gitlab.emails
|
|
185
|
+
# Gitlab.emails(2)
|
|
186
|
+
#
|
|
187
|
+
# @param [Integer] user_id The ID of a user.
|
|
188
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
189
|
+
def emails(user_id=nil)
|
|
190
|
+
url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails"
|
|
191
|
+
get(url)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Get a single email.
|
|
195
|
+
#
|
|
196
|
+
# @example
|
|
197
|
+
# Gitlab.email(3)
|
|
198
|
+
#
|
|
199
|
+
# @param [Integer] id The ID of a email.
|
|
200
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
201
|
+
def email(id)
|
|
202
|
+
get("/user/emails/#{id}")
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
# Creates a new email
|
|
206
|
+
# Will create a new email an authorized user if no user ID passed.
|
|
207
|
+
#
|
|
208
|
+
# @example
|
|
209
|
+
# Gitlab.add_email('email@example.com')
|
|
210
|
+
# Gitlab.add_email('email@example.com', 2)
|
|
211
|
+
#
|
|
212
|
+
# @param [String] email Email address
|
|
213
|
+
# @param [Integer] user_id The ID of a user.
|
|
214
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
215
|
+
def add_email(email, user_id=nil)
|
|
216
|
+
url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails"
|
|
217
|
+
post(url, body: {email: email})
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# Delete email
|
|
221
|
+
# Will delete a email an authorized user if no user ID passed.
|
|
222
|
+
#
|
|
223
|
+
# @example
|
|
224
|
+
# Gitlab.delete_email(2)
|
|
225
|
+
# Gitlab.delete_email(3, 2)
|
|
226
|
+
#
|
|
227
|
+
# @param [Integer] id Email address ID
|
|
228
|
+
# @param [Integer] user_id The ID of a user.
|
|
229
|
+
# @return [Boolean]
|
|
230
|
+
def delete_email(id, user_id=nil)
|
|
231
|
+
url = user_id.to_i.zero? ? "/user/emails/#{id}" : "/users/#{user_id}/emails/#{id}"
|
|
232
|
+
delete(url)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
# Search for groups by name
|
|
236
|
+
#
|
|
237
|
+
# @example
|
|
238
|
+
# Gitlab.user_search('gitlab')
|
|
239
|
+
#
|
|
240
|
+
# @param [String] search A string to search for in user names and paths.
|
|
241
|
+
# @param [Hash] options A customizable set of options.
|
|
242
|
+
# @option options [String] :per_page Number of user to return per page
|
|
243
|
+
# @option options [String] :page The page to retrieve
|
|
244
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
|
245
|
+
def user_search(search, options={})
|
|
246
|
+
options[:search] = search
|
|
247
|
+
get("/users", query: options)
|
|
248
|
+
end
|
|
105
249
|
end
|
|
106
250
|
end
|
data/lib/gitlab/configuration.rb
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
require 'gitlab/cli_helpers'
|
|
1
2
|
module Gitlab
|
|
2
3
|
# Defines constants and methods related to configuration.
|
|
3
4
|
module Configuration
|
|
4
5
|
# An array of valid keys in the options hash when configuring a Gitlab::API.
|
|
5
|
-
VALID_OPTIONS_KEYS = [:endpoint, :private_token, :user_agent, :sudo].freeze
|
|
6
|
+
VALID_OPTIONS_KEYS = [:endpoint, :private_token, :user_agent, :sudo, :httparty].freeze
|
|
6
7
|
|
|
7
8
|
# The user agent that will be sent to the API endpoint if none is set.
|
|
8
9
|
DEFAULT_USER_AGENT = "Gitlab Ruby Gem #{Gitlab::VERSION}".freeze
|
|
9
10
|
|
|
10
11
|
# @private
|
|
11
|
-
attr_accessor
|
|
12
|
+
attr_accessor(*VALID_OPTIONS_KEYS)
|
|
13
|
+
# @private
|
|
14
|
+
alias_method :auth_token=, :private_token=
|
|
12
15
|
|
|
13
16
|
# Sets all configuration options to their default values
|
|
14
17
|
# when this module is extended.
|
|
@@ -30,10 +33,23 @@ module Gitlab
|
|
|
30
33
|
|
|
31
34
|
# Resets all configuration options to the defaults.
|
|
32
35
|
def reset
|
|
33
|
-
self.endpoint =
|
|
34
|
-
self.private_token =
|
|
36
|
+
self.endpoint = ENV['GITLAB_API_ENDPOINT']
|
|
37
|
+
self.private_token = ENV['GITLAB_API_PRIVATE_TOKEN'] || ENV['GITLAB_API_AUTH_TOKEN']
|
|
38
|
+
self.httparty = get_httparty_config(ENV['GITLAB_API_HTTPARTY_OPTIONS'])
|
|
35
39
|
self.sudo = nil
|
|
36
40
|
self.user_agent = DEFAULT_USER_AGENT
|
|
37
41
|
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
# Allows HTTParty config to be specified in ENV using YAML hash.
|
|
46
|
+
def get_httparty_config(options)
|
|
47
|
+
return options if options.nil?
|
|
48
|
+
|
|
49
|
+
httparty = Gitlab::CLI::Helpers.yaml_load(options)
|
|
50
|
+
|
|
51
|
+
raise ArgumentError, "HTTParty config should be a Hash." unless httparty.is_a? Hash
|
|
52
|
+
Gitlab::CLI::Helpers.symbolize_keys httparty
|
|
53
|
+
end
|
|
38
54
|
end
|
|
39
55
|
end
|
data/lib/gitlab/error.rb
CHANGED
|
@@ -3,40 +3,83 @@ module Gitlab
|
|
|
3
3
|
# Custom error class for rescuing from all Gitlab errors.
|
|
4
4
|
class Error < StandardError; end
|
|
5
5
|
|
|
6
|
-
# Raise when attributes are missing.
|
|
7
|
-
class MissingAttributes < Error; end
|
|
8
|
-
|
|
9
6
|
# Raised when API endpoint credentials not configured.
|
|
10
7
|
class MissingCredentials < Error; end
|
|
11
8
|
|
|
12
9
|
# Raised when impossible to parse response body.
|
|
13
10
|
class Parsing < Error; end
|
|
14
11
|
|
|
12
|
+
# Custom error class for rescuing from HTTP response errors.
|
|
13
|
+
class ResponseError < Error
|
|
14
|
+
def initialize(response)
|
|
15
|
+
@response = response
|
|
16
|
+
super(build_error_message)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Status code returned in the http response.
|
|
20
|
+
#
|
|
21
|
+
# @return [Integer]
|
|
22
|
+
def response_status
|
|
23
|
+
@response.code
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
# Human friendly message.
|
|
29
|
+
#
|
|
30
|
+
# @return [String]
|
|
31
|
+
def build_error_message
|
|
32
|
+
parsed_response = @response.parsed_response
|
|
33
|
+
message = parsed_response.message || parsed_response.error
|
|
34
|
+
|
|
35
|
+
"Server responded with code #{@response.code}, message: " \
|
|
36
|
+
"#{handle_message(message)}. " \
|
|
37
|
+
"Request URI: #{@response.request.base_uri}#{@response.request.path}"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Handle error response message in case of nested hashes
|
|
41
|
+
def handle_message(message)
|
|
42
|
+
case message
|
|
43
|
+
when Gitlab::ObjectifiedHash
|
|
44
|
+
message.to_h.sort.map do |key, val|
|
|
45
|
+
"'#{key}' #{(val.is_a?(Hash) ? val.sort.map { |k, v| "(#{k}: #{v.join(' ')})" } : val).join(' ')}"
|
|
46
|
+
end.join(', ')
|
|
47
|
+
when Array
|
|
48
|
+
message.join(' ')
|
|
49
|
+
else
|
|
50
|
+
message
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
15
55
|
# Raised when API endpoint returns the HTTP status code 400.
|
|
16
|
-
class BadRequest <
|
|
56
|
+
class BadRequest < ResponseError; end
|
|
17
57
|
|
|
18
58
|
# Raised when API endpoint returns the HTTP status code 401.
|
|
19
|
-
class Unauthorized <
|
|
59
|
+
class Unauthorized < ResponseError; end
|
|
20
60
|
|
|
21
61
|
# Raised when API endpoint returns the HTTP status code 403.
|
|
22
|
-
class Forbidden <
|
|
62
|
+
class Forbidden < ResponseError; end
|
|
23
63
|
|
|
24
64
|
# Raised when API endpoint returns the HTTP status code 404.
|
|
25
|
-
class NotFound <
|
|
65
|
+
class NotFound < ResponseError; end
|
|
26
66
|
|
|
27
67
|
# Raised when API endpoint returns the HTTP status code 405.
|
|
28
|
-
class MethodNotAllowed <
|
|
68
|
+
class MethodNotAllowed < ResponseError; end
|
|
29
69
|
|
|
30
70
|
# Raised when API endpoint returns the HTTP status code 409.
|
|
31
|
-
class Conflict <
|
|
71
|
+
class Conflict < ResponseError; end
|
|
72
|
+
|
|
73
|
+
# Raised when API endpoint returns the HTTP status code 422.
|
|
74
|
+
class Unprocessable < ResponseError; end
|
|
32
75
|
|
|
33
76
|
# Raised when API endpoint returns the HTTP status code 500.
|
|
34
|
-
class InternalServerError <
|
|
77
|
+
class InternalServerError < ResponseError; end
|
|
35
78
|
|
|
36
79
|
# Raised when API endpoint returns the HTTP status code 502.
|
|
37
|
-
class BadGateway <
|
|
80
|
+
class BadGateway < ResponseError; end
|
|
38
81
|
|
|
39
82
|
# Raised when API endpoint returns the HTTP status code 503.
|
|
40
|
-
class ServiceUnavailable <
|
|
83
|
+
class ServiceUnavailable < ResponseError; end
|
|
41
84
|
end
|
|
42
85
|
end
|