gitlab 4.5.0 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/stale.yml +18 -0
  3. data/.rubocop_todo.yml +46 -0
  4. data/Gemfile +2 -0
  5. data/README.md +22 -22
  6. data/Rakefile +3 -5
  7. data/bin/console +1 -0
  8. data/exe/gitlab +5 -1
  9. data/gitlab.gemspec +9 -6
  10. data/lib/gitlab.rb +6 -3
  11. data/lib/gitlab/api.rb +5 -3
  12. data/lib/gitlab/cli.rb +11 -5
  13. data/lib/gitlab/cli_helpers.rb +31 -22
  14. data/lib/gitlab/client.rb +7 -8
  15. data/lib/gitlab/client/access_requests.rb +100 -93
  16. data/lib/gitlab/client/award_emojis.rb +127 -127
  17. data/lib/gitlab/client/boards.rb +82 -82
  18. data/lib/gitlab/client/branches.rb +89 -89
  19. data/lib/gitlab/client/build_variables.rb +117 -117
  20. data/lib/gitlab/client/builds.rb +98 -98
  21. data/lib/gitlab/client/commits.rb +154 -154
  22. data/lib/gitlab/client/deployments.rb +29 -29
  23. data/lib/gitlab/client/environments.rb +80 -80
  24. data/lib/gitlab/client/events.rb +54 -54
  25. data/lib/gitlab/client/group_milestones.rb +85 -86
  26. data/lib/gitlab/client/groups.rb +178 -178
  27. data/lib/gitlab/client/issues.rb +195 -196
  28. data/lib/gitlab/client/jobs.rb +150 -150
  29. data/lib/gitlab/client/keys.rb +14 -14
  30. data/lib/gitlab/client/labels.rb +79 -79
  31. data/lib/gitlab/client/merge_request_approvals.rb +102 -102
  32. data/lib/gitlab/client/merge_requests.rb +281 -256
  33. data/lib/gitlab/client/milestones.rb +85 -85
  34. data/lib/gitlab/client/namespaces.rb +18 -18
  35. data/lib/gitlab/client/notes.rb +260 -260
  36. data/lib/gitlab/client/pipeline_schedules.rb +123 -123
  37. data/lib/gitlab/client/pipeline_triggers.rb +93 -93
  38. data/lib/gitlab/client/pipelines.rb +62 -62
  39. data/lib/gitlab/client/projects.rb +526 -505
  40. data/lib/gitlab/client/repositories.rb +68 -55
  41. data/lib/gitlab/client/repository_files.rb +103 -103
  42. data/lib/gitlab/client/runners.rb +113 -115
  43. data/lib/gitlab/client/services.rb +46 -45
  44. data/lib/gitlab/client/sidekiq.rb +32 -32
  45. data/lib/gitlab/client/snippets.rb +86 -86
  46. data/lib/gitlab/client/system_hooks.rb +57 -57
  47. data/lib/gitlab/client/tags.rb +87 -88
  48. data/lib/gitlab/client/todos.rb +41 -41
  49. data/lib/gitlab/client/users.rb +242 -228
  50. data/lib/gitlab/client/versions.rb +16 -0
  51. data/lib/gitlab/configuration.rb +7 -5
  52. data/lib/gitlab/error.rb +3 -1
  53. data/lib/gitlab/file_response.rb +4 -2
  54. data/lib/gitlab/help.rb +9 -9
  55. data/lib/gitlab/objectified_hash.rb +5 -4
  56. data/lib/gitlab/page_links.rb +9 -7
  57. data/lib/gitlab/paginated_response.rb +14 -4
  58. data/lib/gitlab/request.rb +8 -5
  59. data/lib/gitlab/shell.rb +6 -4
  60. data/lib/gitlab/shell_history.rb +7 -5
  61. data/lib/gitlab/version.rb +3 -1
  62. metadata +8 -5
@@ -1,96 +1,95 @@
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
1
+ # frozen_string_literal: true
19
2
 
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, release_description: description })
34
- end
35
- alias_method :repo_create_tag, :create_tag
3
+ # Defines methods related to tags.
4
+ # @see https://docs.gitlab.com/ce/api/tags.html
5
+ module Tags
6
+ # Gets a list of project repository tags.
7
+ #
8
+ # @example
9
+ # Gitlab.tags(42)
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
+ # @return [Array<Gitlab::ObjectifiedHash>]
16
+ def tags(project, options = {})
17
+ get("/projects/#{url_encode project}/repository/tags", query: options)
18
+ end
19
+ alias repo_tags tags
36
20
 
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/#{url_encode tag}")
48
- end
49
- alias_method :repo_tag, :tag
21
+ # Creates a new project repository tag.
22
+ #
23
+ # @example
24
+ # Gitlab.create_tag(42, 'new_tag', 'master')
25
+ # Gitlab.create_tag(42, 'v1.0', 'master', 'Release 1.0')
26
+ #
27
+ # @param [Integer, String] project The ID or name of a project.
28
+ # @param [String] tag_name The name of the new tag.
29
+ # @param [String] ref The ref (commit sha, branch name, or another tag) the tag will point to.
30
+ # @param [String] message Optional message for tag, creates annotated tag if specified.
31
+ # @param [String] description Optional release notes for tag.
32
+ # @return [Gitlab::ObjectifiedHash]
33
+ def create_tag(project, tag_name, ref, message = '', description = nil)
34
+ post("/projects/#{url_encode project}/repository/tags", body: { tag_name: tag_name, ref: ref, message: message, release_description: description })
35
+ end
36
+ alias repo_create_tag create_tag
50
37
 
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/#{url_encode tag}")
62
- end
63
- alias_method :repo_delete_tag, :delete_tag
38
+ # Gets information about a repository tag.
39
+ #
40
+ # @example
41
+ # Gitlab.tag(3, 'api')
42
+ # Gitlab.repo_tag(5, 'master')
43
+ #
44
+ # @param [Integer, String] project The ID or name of a project.
45
+ # @param [String] tag The name of the tag.
46
+ # @return [Gitlab::ObjectifiedHash]
47
+ def tag(project, tag)
48
+ get("/projects/#{url_encode project}/repository/tags/#{url_encode tag}")
49
+ end
50
+ alias repo_tag tag
64
51
 
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/#{url_encode tag}/release", body: { description: description })
77
- end
78
- alias_method :repo_create_release, :create_release
52
+ # Deletes a repository tag. Requires Gitlab >= 6.8.x
53
+ #
54
+ # @example
55
+ # Gitlab.delete_tag(3, 'api')
56
+ # Gitlab.repo_delete_tag(5, 'master')
57
+ #
58
+ # @param [Integer, String] project The ID or name of a project.
59
+ # @param [String] tag The name of the tag to delete
60
+ # @return [Gitlab::ObjectifiedHash]
61
+ def delete_tag(project, tag)
62
+ delete("/projects/#{url_encode project}/repository/tags/#{url_encode tag}")
63
+ end
64
+ alias repo_delete_tag delete_tag
79
65
 
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/#{url_encode tag}/release", body: { description: description })
92
- end
93
- alias_method :repo_update_release, :update_release
66
+ # Adds release notes to an existing repository tag. Requires Gitlab >= 8.2.0
67
+ #
68
+ # @example
69
+ # Gitlab.create_release(3, '1.0.0', 'This is ready for production')
70
+ # Gitlab.repo_create_release(5, '1.0.0', 'This is ready for production')
71
+ #
72
+ # @param [Integer, String] project The ID or name of a project.
73
+ # @param [String] tag The name of the new tag.
74
+ # @param [String] description Release notes with markdown support
75
+ # @return [Gitlab::ObjectifiedHash]
76
+ def create_release(project, tag, description)
77
+ post("/projects/#{url_encode project}/repository/tags/#{url_encode tag}/release", body: { description: description })
78
+ end
79
+ alias repo_create_release create_release
94
80
 
81
+ # Updates the release notes of a given release. Requires Gitlab >= 8.2.0
82
+ #
83
+ # @example
84
+ # Gitlab.update_release(3, '1.0.0', 'This is even more ready for production')
85
+ # Gitlab.repo_update_release(5, '1.0.0', 'This is even more ready for production')
86
+ #
87
+ # @param [Integer, String] project The ID or name of a project.
88
+ # @param [String] tag The name of the new tag.
89
+ # @param [String] description Release notes with markdown support
90
+ # @return [Gitlab::ObjectifiedHash]
91
+ def update_release(project, tag, description)
92
+ put("/projects/#{url_encode project}/repository/tags/#{url_encode tag}/release", body: { description: description })
95
93
  end
94
+ alias repo_update_release update_release
96
95
  end
@@ -1,44 +1,44 @@
1
- class Gitlab::Client
2
- # Defines methods related to todos
3
- # @see https://docs.gitlab.com/ce/api/todos.html
4
- module Todos
5
- # Gets a list of todos.
6
- #
7
- # @example
8
- # Gitlab.todos
9
- # Gitlab.todos({ action: 'assigned' })
10
- # Gitlab.todos({ state: 'pending' })
11
- #
12
- # @param [Hash] options A customizable set of options.
13
- # @option options [Integer] :action The action to be filtered. Can be `assigned`, `mentioned`, `build_failed`, `marked`, or `approval_required`.
14
- # @option options [Integer] :author_id The ID of an author
15
- # @option options [Integer] :project_id The ID of a project
16
- # @option options [Integer] :state The state of the todo. Can be either `pending` or `done`
17
- # @option options [Integer] :type The type of a todo. Can be either `Issue` or `MergeRequest`
18
- # @return [Array<Gitlab::ObjectifiedHash>]
19
- def todos(options={})
20
- get("/todos", query: options)
21
- end
1
+ # frozen_string_literal: true
22
2
 
23
- # Marks a single pending todo for the current user as done.
24
- #
25
- # @example
26
- # Gitlab.mark_todo_as_done(42)
27
- #
28
- # @param [Integer] id The ID of the todo.
29
- # @return [Gitlab::ObjectifiedHash]
30
- def mark_todo_as_done(id)
31
- post("/todos/#{id}/mark_as_done")
32
- end
3
+ # Defines methods related to todos
4
+ # @see https://docs.gitlab.com/ce/api/todos.html
5
+ module Todos
6
+ # Gets a list of todos.
7
+ #
8
+ # @example
9
+ # Gitlab.todos
10
+ # Gitlab.todos({ action: 'assigned' })
11
+ # Gitlab.todos({ state: 'pending' })
12
+ #
13
+ # @param [Hash] options A customizable set of options.
14
+ # @option options [Integer] :action The action to be filtered. Can be `assigned`, `mentioned`, `build_failed`, `marked`, or `approval_required`.
15
+ # @option options [Integer] :author_id The ID of an author
16
+ # @option options [Integer] :project_id The ID of a project
17
+ # @option options [Integer] :state The state of the todo. Can be either `pending` or `done`
18
+ # @option options [Integer] :type The type of a todo. Can be either `Issue` or `MergeRequest`
19
+ # @return [Array<Gitlab::ObjectifiedHash>]
20
+ def todos(options = {})
21
+ get('/todos', query: options)
22
+ end
23
+
24
+ # Marks a single pending todo for the current user as done.
25
+ #
26
+ # @example
27
+ # Gitlab.mark_todo_as_done(42)
28
+ #
29
+ # @param [Integer] id The ID of the todo.
30
+ # @return [Gitlab::ObjectifiedHash]
31
+ def mark_todo_as_done(id)
32
+ post("/todos/#{id}/mark_as_done")
33
+ end
33
34
 
34
- # Marks all todos for the current user as done
35
- #
36
- # @example
37
- # Gitlab.mark_all_todos_as_done
38
- #
39
- # @return [void] This API call returns an empty response body.
40
- def mark_all_todos_as_done
41
- post("/todos/mark_as_done")
42
- end
35
+ # Marks all todos for the current user as done
36
+ #
37
+ # @example
38
+ # Gitlab.mark_all_todos_as_done
39
+ #
40
+ # @return [void] This API call returns an empty response body.
41
+ def mark_all_todos_as_done
42
+ post('/todos/mark_as_done')
43
43
  end
44
- end
44
+ end
@@ -1,250 +1,264 @@
1
- class Gitlab::Client
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
5
- module Users
6
- # Gets a list of users.
7
- #
8
- # @example
9
- # Gitlab.users
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 users(options={})
16
- get("/users", query: options)
17
- end
1
+ # frozen_string_literal: true
18
2
 
19
- # Gets information about a user.
20
- # Will return information about an authorized user if no ID passed.
21
- #
22
- # @example
23
- # Gitlab.user
24
- # Gitlab.user(2)
25
- #
26
- # @param [Integer] id The ID of a user.
27
- # @return [Gitlab::ObjectifiedHash]
28
- def user(id=nil)
29
- id.to_i.zero? ? get("/user") : get("/users/#{id}")
30
- end
3
+ # Defines methods related to users.
4
+ # @see https://docs.gitlab.com/ce/api/users.html
5
+ # @see https://docs.gitlab.com/ce/api/session.html
6
+ module Users
7
+ # Gets a list of users.
8
+ #
9
+ # @example
10
+ # Gitlab.users
11
+ #
12
+ # @param [Hash] options A customizable set of options.
13
+ # @option options [Integer] :page The page number.
14
+ # @option options [Integer] :per_page The number of results per page.
15
+ # @return [Array<Gitlab::ObjectifiedHash>]
16
+ def users(options = {})
17
+ get('/users', query: options)
18
+ end
31
19
 
32
- # Creates a new user.
33
- # Requires authentication from an admin account.
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
- #
40
- # @param [String] email The email of a user.
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
- body = if args[2]
53
- { email: args[0], password: args[1], username: args[2] }
54
- else
55
- { email: args[0], password: args[1], name: args[0] }
56
- end
57
- body.merge!(options)
58
- post('/users', body: body)
59
- end
20
+ # Gets information about a user.
21
+ # Will return information about an authorized user if no ID passed.
22
+ #
23
+ # @example
24
+ # Gitlab.user
25
+ # Gitlab.user(2)
26
+ #
27
+ # @param [Integer] id The ID of a user.
28
+ # @return [Gitlab::ObjectifiedHash]
29
+ def user(id = nil)
30
+ id.to_i.zero? ? get('/user') : get("/users/#{id}")
31
+ end
60
32
 
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.
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.
70
- # @option options [String] :name The name of a user. Defaults to email.
71
- # @option options [String] :skype The skype of a user.
72
- # @option options [String] :linkedin The linkedin of a user.
73
- # @option options [String] :twitter The twitter of a user.
74
- # @option options [Integer] :projects_limit The limit of projects for a user.
75
- # @return [Gitlab::ObjectifiedHash] Information about created user.
76
- def edit_user(user_id, options={})
77
- put("/users/#{user_id}", body: options)
78
- end
33
+ # Creates a new user.
34
+ # Requires authentication from an admin account.
35
+ #
36
+ # @example
37
+ # Gitlab.create_user('joe@foo.org', 'secret', 'joe', { name: 'Joe Smith' })
38
+ # or
39
+ # Gitlab.create_user('joe@foo.org', 'secret')
40
+ #
41
+ # @param [String] email The email of a user.
42
+ # @param [String] password The password of a user.
43
+ # @param [String] username The username of a user.
44
+ # @param [Hash] options A customizable set of options.
45
+ # @option options [String] :name The name of a user. Defaults to email.
46
+ # @option options [String] :skype The skype of a user.
47
+ # @option options [String] :linkedin The linkedin of a user.
48
+ # @option options [String] :twitter The twitter of a user.
49
+ # @option options [Integer] :projects_limit The limit of projects for a user.
50
+ # @return [Gitlab::ObjectifiedHash] Information about created user.
51
+ def create_user(*args)
52
+ options = args.last.is_a?(Hash) ? args.pop : {}
53
+ body = if args[2]
54
+ { email: args[0], password: args[1], username: args[2] }
55
+ else
56
+ { email: args[0], password: args[1], name: args[0] }
57
+ end
58
+ body.merge!(options)
59
+ post('/users', body: body)
60
+ end
79
61
 
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
62
+ # Updates a user.
63
+ #
64
+ # @example
65
+ # Gitlab.edit_user(15, { email: 'joe.smith@foo.org', projects_limit: 20 })
66
+ #
67
+ # @param [Integer] id The ID of a user.
68
+ # @param [Hash] options A customizable set of options.
69
+ # @option options [String] :email The email of a user.
70
+ # @option options [String] :password The password of a user.
71
+ # @option options [String] :name The name of a user. Defaults to email.
72
+ # @option options [String] :skype The skype of a user.
73
+ # @option options [String] :linkedin The linkedin of a user.
74
+ # @option options [String] :twitter The twitter of a user.
75
+ # @option options [Integer] :projects_limit The limit of projects for a user.
76
+ # @return [Gitlab::ObjectifiedHash] Information about created user.
77
+ def edit_user(user_id, options = {})
78
+ put("/users/#{user_id}", body: options)
79
+ end
90
80
 
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
81
+ # Deletes a user.
82
+ #
83
+ # @example
84
+ # Gitlab.delete_user(1)
85
+ #
86
+ # @param [Integer] id The ID of a user.
87
+ # @return [Gitlab::ObjectifiedHash] Information about deleted user.
88
+ def delete_user(user_id)
89
+ delete("/users/#{user_id}")
90
+ end
101
91
 
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")
111
- end
92
+ # Blocks the specified user. Available only for admin.
93
+ #
94
+ # @example
95
+ # Gitlab.block_user(15)
96
+ #
97
+ # @param [Integer] user_id The Id of user
98
+ # @return [Boolean] success or not
99
+ def block_user(user_id)
100
+ post("/users/#{user_id}/block")
101
+ end
112
102
 
113
- # Creates a new user session.
114
- #
115
- # @example
116
- # Gitlab.session('jack@example.com', 'secret12345')
117
- #
118
- # @param [String] email The email of a user.
119
- # @param [String] password The password of a user.
120
- # @return [Gitlab::ObjectifiedHash]
121
- # @note This method doesn't require private_token to be set.
122
- def session(email, password)
123
- post("/session", body: { email: email, password: password }, unauthenticated: true)
124
- end
103
+ # Unblocks the specified user. Available only for admin.
104
+ #
105
+ # @example
106
+ # Gitlab.unblock_user(15)
107
+ #
108
+ # @param [Integer] user_id The Id of user
109
+ # @return [Boolean] success or not
110
+ def unblock_user(user_id)
111
+ post("/users/#{user_id}/unblock")
112
+ end
125
113
 
126
- # Gets a list of user's SSH keys.
127
- #
128
- # @example
129
- # Gitlab.ssh_keys
130
- # Gitlab.ssh_keys({ user_id: 2 })
131
- #
132
- # @param [Hash] options A customizable set of options.
133
- # @option options [Integer] :page The page number.
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.
136
- # @return [Array<Gitlab::ObjectifiedHash>]
137
- def ssh_keys(options={})
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
144
- end
114
+ # Creates a new user session.
115
+ #
116
+ # @example
117
+ # Gitlab.session('jack@example.com', 'secret12345')
118
+ #
119
+ # @param [String] email The email of a user.
120
+ # @param [String] password The password of a user.
121
+ # @return [Gitlab::ObjectifiedHash]
122
+ # @note This method doesn't require private_token to be set.
123
+ def session(email, password)
124
+ post('/session', body: { email: email, password: password }, unauthenticated: true)
125
+ end
145
126
 
146
- # Gets information about SSH key.
147
- #
148
- # @example
149
- # Gitlab.ssh_key(1)
150
- #
151
- # @param [Integer] id The ID of a user's SSH key.
152
- # @return [Gitlab::ObjectifiedHash]
153
- def ssh_key(id)
154
- get("/user/keys/#{id}")
127
+ # Gets a list of user's SSH keys.
128
+ #
129
+ # @example
130
+ # Gitlab.ssh_keys
131
+ # Gitlab.ssh_keys({ user_id: 2 })
132
+ #
133
+ # @param [Hash] options A customizable set of options.
134
+ # @option options [Integer] :page The page number.
135
+ # @option options [Integer] :per_page The number of results per page.
136
+ # @option options [Integer] :user_id The ID of the user to retrieve the keys for.
137
+ # @return [Array<Gitlab::ObjectifiedHash>]
138
+ def ssh_keys(options = {})
139
+ user_id = options.delete :user_id
140
+ if user_id.to_i.zero?
141
+ get('/user/keys', query: options)
142
+ else
143
+ get("/users/#{user_id}/keys", query: options)
155
144
  end
145
+ end
146
+
147
+ # Gets information about SSH key.
148
+ #
149
+ # @example
150
+ # Gitlab.ssh_key(1)
151
+ #
152
+ # @param [Integer] id The ID of a user's SSH key.
153
+ # @return [Gitlab::ObjectifiedHash]
154
+ def ssh_key(id)
155
+ get("/user/keys/#{id}")
156
+ end
156
157
 
157
- # Creates a new SSH key.
158
- #
159
- # @example
160
- # Gitlab.create_ssh_key('key title', 'key body')
161
- #
162
- # @param [String] title The title of an SSH key.
163
- # @param [String] key The SSH key body.
164
- # @return [Gitlab::ObjectifiedHash] Information about created SSH key.
165
- def create_ssh_key(title, key)
166
- post("/user/keys", body: { title: title, key: key })
158
+ # Creates a new SSH key.
159
+ #
160
+ # @example
161
+ # Gitlab.create_ssh_key('key title', 'key body')
162
+ #
163
+ # @param [String] title The title of an SSH key.
164
+ # @param [String] key The SSH key body.
165
+ # @param [Hash] options A customizable set of options.
166
+ # @option options [Integer] :user_id id of the user to associate the key with
167
+ # @return [Gitlab::ObjectifiedHash] Information about created SSH key.
168
+ def create_ssh_key(title, key, options = {})
169
+ user_id = options.delete :user_id
170
+ if user_id.to_i.zero?
171
+ post('/user/keys', body: { title: title, key: key })
172
+ else
173
+ post("/users/#{user_id}/keys", body: { title: title, key: key })
167
174
  end
175
+ end
168
176
 
169
- # Deletes an SSH key.
170
- #
171
- # @example
172
- # Gitlab.delete_ssh_key(1)
173
- #
174
- # @param [Integer] id The ID of a user's SSH key.
175
- # @return [Gitlab::ObjectifiedHash] Information about deleted SSH key.
176
- def delete_ssh_key(id)
177
+ # Deletes an SSH key.
178
+ #
179
+ # @example
180
+ # Gitlab.delete_ssh_key(1)
181
+ #
182
+ # @param [Integer] id The ID of a user's SSH key.
183
+ # @param [Hash] options A customizable set of options.
184
+ # @option options [Integer] :user_id id of the user to associate the key with
185
+ # @return [Gitlab::ObjectifiedHash] Information about deleted SSH key.
186
+ def delete_ssh_key(id, options = {})
187
+ user_id = options.delete :user_id
188
+ if user_id.to_i.zero?
177
189
  delete("/user/keys/#{id}")
190
+ else
191
+ delete("/users/#{user_id}/keys/#{id}")
178
192
  end
193
+ end
179
194
 
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
195
+ # Gets user emails.
196
+ # Will return emails an authorized user if no user ID passed.
197
+ #
198
+ # @example
199
+ # Gitlab.emails
200
+ # Gitlab.emails(2)
201
+ #
202
+ # @param [Integer] user_id The ID of a user.
203
+ # @return [Gitlab::ObjectifiedHash]
204
+ def emails(user_id = nil)
205
+ url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails"
206
+ get(url)
207
+ end
193
208
 
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
209
+ # Get a single email.
210
+ #
211
+ # @example
212
+ # Gitlab.email(3)
213
+ #
214
+ # @param [Integer] id The ID of a email.
215
+ # @return [Gitlab::ObjectifiedHash]
216
+ def email(id)
217
+ get("/user/emails/#{id}")
218
+ end
204
219
 
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
220
+ # Creates a new email
221
+ # Will create a new email an authorized user if no user ID passed.
222
+ #
223
+ # @example
224
+ # Gitlab.add_email('email@example.com')
225
+ # Gitlab.add_email('email@example.com', 2)
226
+ #
227
+ # @param [String] email Email address
228
+ # @param [Integer] user_id The ID of a user.
229
+ # @return [Gitlab::ObjectifiedHash]
230
+ def add_email(email, user_id = nil)
231
+ url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails"
232
+ post(url, body: { email: email })
233
+ end
219
234
 
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
235
+ # Delete email
236
+ # Will delete a email an authorized user if no user ID passed.
237
+ #
238
+ # @example
239
+ # Gitlab.delete_email(2)
240
+ # Gitlab.delete_email(3, 2)
241
+ #
242
+ # @param [Integer] id Email address ID
243
+ # @param [Integer] user_id The ID of a user.
244
+ # @return [Boolean]
245
+ def delete_email(id, user_id = nil)
246
+ url = user_id.to_i.zero? ? "/user/emails/#{id}" : "/users/#{user_id}/emails/#{id}"
247
+ delete(url)
248
+ end
234
249
 
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
250
+ # Search for groups by name
251
+ #
252
+ # @example
253
+ # Gitlab.user_search('gitlab')
254
+ #
255
+ # @param [String] search A string to search for in user names and paths.
256
+ # @param [Hash] options A customizable set of options.
257
+ # @option options [String] :per_page Number of user to return per page
258
+ # @option options [String] :page The page to retrieve
259
+ # @return [Array<Gitlab::ObjectifiedHash>]
260
+ def user_search(search, options = {})
261
+ options[:search] = search
262
+ get('/users', query: options)
249
263
  end
250
264
  end