diff --git a/CHANGELOG.md b/CHANGELOG.md index f2e059f..62637f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,23 @@ ## Change Log ### Unreleased + +### 4.2.0 (13/07/2017) +- Use `url_encode` in all `Commit` resources (@grodowski) +- Fix `project_search` path for APIv4 (@edaubert) +- Add options to `Labels#create_label` (@hlidotbe) +- Add `Board` API support (@hlidotbe) +- `Award Emoji` API (@akkee) +- Subscribe and unsubscribe actions for labels (@akkee) +- Add `options` hash to `add_hook` method (@mltsy) +- Update repository files endpoint APIv4 (@mltsy) +- Update `Branch` docs and add `options` param to `protect_branch` (@mltsy) +- Fix and clarify `edit_project` option docs (@mltsy) +- Add `TODO` API (@akkee) +- Use `body` parameter to send POST data (@sr189) +- Add `Environments` module (@mltsy) +- Edit and Delete methods for `Notes` API (@akkee) +- Rename `branch_name` parameter to `branch` in `create_branch` & `create_commit` methods (@sr189) ### 4.1.0 (26/05/2017) - Add appropriate Content-Type header (@mltsy) diff --git a/lib/gitlab/client/award_emojis.rb b/lib/gitlab/client/award_emojis.rb new file mode 100644 index 0000000..931ae64 --- /dev/null +++ b/lib/gitlab/client/award_emojis.rb @@ -0,0 +1,135 @@ +class Gitlab::Client + # Defines methods related to Award Emojis. + # @see https://docs.gitlab.com/ce/api/award_emoji.html + module AwardEmojis + # Gets a list of all award emoji for an awardable(issue, merge request or snippet) + # + # @example + # Gitlab.award_emojis(1, 80, 'issue') + # Gitlab.award_emojis(1, 60, 'merge_request') + # Gitlab.award_emojis(1, 40, 'snippet') + # + # @param [Integer] project The ID of a project. + # @param [Integer] awardable_id The ID of an awardable(issue, merge request or snippet). + # @param [String] awardable_type The type of the awardable(can be 'issue', 'merge_request' or 'snippet') + # @return [Array] + def award_emojis(project, awardable_id, awardable_type) + get("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/award_emoji") + end + + # Gets a list of all award emoji for a single note on an awardable(issue, merge request or snippet) + # + # @example + # Gitlab.note_award_emojis(1, 80, 'issue', 1) + # Gitlab.note_award_emojis(1, 60, 'merge_request', 1) + # Gitlab.note_award_emojis(1, 40, 'snippet', 1) + # + # @param [Integer] project The ID of a project. + # @param [Integer] awardable_id The ID of an awardable(issue, merge request or snippet). + # @param [String] awardable_type The type of the awardable(can be 'issue', 'merge_request' or 'snippet') + # @param [Integer] note_id The ID of a note. + # @return [Array] + def note_award_emojis(project, awardable_id, awardable_type, note_id) + get("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji") + end + + # Gets a single award emoji for an awardable(issue, merge request or snippet) + # + # @example + # Gitlab.award_emoji(1, 80, 'issue', 4) + # Gitlab.award_emoji(1, 60, 'merge_request', 4) + # Gitlab.award_emoji(1, 40, 'snippet', 4) + # + # @param [Integer] project The ID of a project. + # @param [Integer] awardable_id The ID of an awardable(issue, merge request or snippet). + # @param [String] awardable_type The type of the awardable(can be 'issue', 'merge_request' or 'snippet') + # @param [Integer] award_id The ID of an award emoji. + # @return [Gitlab::ObjectifiedHash] + def award_emoji(project, awardable_id, awardable_type, award_id) + get("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/award_emoji/#{award_id}") + end + + # Gets a single award emoji from a single note on an awardable(issue, merge request or snippet) + # + # @example + # Gitlab.note_award_emoji(1, 80, 'issue', 1, 4) + # Gitlab.note_award_emoji(1, 60, 'merge_request', 1, 4) + # Gitlab.note_award_emoji(1, 40, 'snippet', 1, 4) + # + # @param [Integer] project The ID of a project. + # @param [Integer] awardable_id The ID of an awardable(issue, merge request or snippet). + # @param [String] awardable_type The type of the awardable(can be 'issue', 'merge_request' or 'snippet') + # @param [Integer] note_id The ID of a note. + # @param [Integer] award_id The ID of an award emoji. + # @return [Gitlab::ObjectifiedHash] + def note_award_emoji(project, awardable_id, awardable_type, note_id, award_id) + get("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji/#{award_id}") + end + + # Awards a new emoji to an awardable(issue, merge request or snippet) + # + # @example + # Gitlab.create_award_emoji(1, 80, 'issue', 'blowfish') + # Gitlab.create_award_emoji(1, 80, 'merge_request', 'blowfish') + # Gitlab.create_award_emoji(1, 80, 'snippet', 'blowfish') + # + # @param [Integer] project The ID of a project. + # @param [Integer] awardable_id The ID of an awardable(issue, merge request or snippet). + # @param [String] awardable_type The type of the awardable(can be 'issue', 'merge_request' or 'snippet') + # @param [String] emoji_name The name of the emoji, without colons. + # @return [Gitlab::ObjectifiedHash] + def create_award_emoji(project, awardable_id, awardable_type, emoji_name) + post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/award_emoji", body: {name: emoji_name}) + end + + # Awards a new emoji to a note on an awardable(issue, merge request or snippet) + # + # @example + # Gitlab.create_note_award_emoji(1, 80, 'issue', 1, 'blowfish') + # Gitlab.create_note_award_emoji(1, 80, 'merge_request', 1, 'blowfish') + # Gitlab.create_note_award_emoji(1, 80, 'snippet', 1, 'blowfish') + # + # @param [Integer] project The ID of a project. + # @param [Integer] awardable_id The ID of an awardable(issue, merge request or snippet). + # @param [String] awardable_type The type of the awardable(can be 'issue', 'merge_request' or 'snippet') + # @param [Integer] note_id The ID of a note. + # @param [String] emoji_name The name of the emoji, without colons. + # @return [Gitlab::ObjectifiedHash] + def create_note_award_emoji(project, awardable_id, awardable_type, note_id, emoji_name) + post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji", body: {name: emoji_name}) + end + + # Deletes a single award emoji from an awardable(issue, merge request or snippet) + # + # @example + # Gitlab.delete_award_emoji(1, 80, 'issue', 4) + # Gitlab.delete_award_emoji(1, 60, 'merge_request', 4) + # Gitlab.delete_award_emoji(1, 40, 'snippet', 4) + # + # @param [Integer] project The ID of a project. + # @param [Integer] awardable_id The ID of an awardable(issue, merge request or snippet). + # @param [String] awardable_type The type of the awardable(can be 'issue', 'merge_request' or 'snippet') + # @param [Integer] award_id The ID of an award emoji. + # @return [void] This API call returns an empty response body. + def delete_award_emoji(project, awardable_id, awardable_type, award_id) + delete("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/award_emoji/#{award_id}") + end + + # Deletes a single award emoji from a single note on an awardable(issue, merge request or snippet) + # + # @example + # Gitlab.delete_note_award_emoji(1, 80, 'issue', 1, 4) + # Gitlab.delete_note_award_emoji(1, 60, 'merge_request', 1, 4) + # Gitlab.delete_note_award_emoji(1, 40, 'snippet', 1, 4) + # + # @param [Integer] project The ID of a project. + # @param [Integer] awardable_id The ID of an awardable(issue, merge request or snippet). + # @param [String] awardable_type The type of the awardable(can be 'issue', 'merge_request' or 'snippet') + # @param [Integer] note_id The ID of a note. + # @param [Integer] award_id The ID of an award emoji. + # @return [void] This API call returns an empty response body. + def delete_note_award_emoji(project, awardable_id, awardable_type, note_id, award_id) + delete("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji/#{award_id}") + end + end +end \ No newline at end of file diff --git a/lib/gitlab/client/boards.rb b/lib/gitlab/client/boards.rb new file mode 100644 index 0000000..3886dcf --- /dev/null +++ b/lib/gitlab/client/boards.rb @@ -0,0 +1,88 @@ +class Gitlab::Client + # Defines methods related to issue boards. + # @see https://docs.gitlab.com/ce/api/boards.html + module Boards + # Gets a list of project's boards. + # + # @example + # Gitlab.boards(5) + # Gitlab.boards({ per_page: 40 }) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Hash] options A customizable set of options. + # @option options [Integer] :page The page number. + # @option options [Integer] :per_page The number of results per page. + # @return [Array] + def boards(project, options={}) + get("/projects/#{url_encode project}/boards", query: options) + end + + # Gets a board lists + # + # @example + # Gitlab.board_lists(5, 42) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of a board. + # @return [Gitlab::ObjectifiedHash] + def board_lists(project, id) + get("/projects/#{url_encode project}/boards/#{id}/lists") + end + # + # Gets a single board list + # + # @example + # Gitlab.board_list(5, 42, 25) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] board_id The ID of a board. + # @param [Integer] id The ID of a list. + # @return [Gitlab::ObjectifiedHash] + def board_list(project, board_id, id) + get("/projects/#{url_encode project}/boards/#{board_id}/lists/#{id}") + end + + # Creates a new board list. + # Only for admins and project owners + # + # @example + # Gitlab.create_board_list(5, 42, 25) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of a board. + # @param [Integer] label_id The ID of a label. + # @return [Gitlab::ObjectifiedHash] Information about created list. + def create_board_list(project, board_id, label_id) + post("/projects/#{url_encode project}/boards/#{board_id}/lists", body: {label_id: label_id}) + end + + # Updates a board list. + # Only for admins and project owners + # + # @example + # Gitlab.edit_board_list(6, 1, 12, 5) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] board_id The ID of a board. + # @param [Integer] id The ID of a list. + # @return [Gitlab::ObjectifiedHash] Information about updated board list. + def edit_board_list(project, board_id, id, position) + put("/projects/#{url_encode project}/boards/#{board_id}/lists/#{id}", body: {position: position}) + end + + # Deletes a board list. + # Only for admins and project owners + # + # @example + # Gitlab.delete_board_list(3, 42, 32) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] board_id The ID of a board. + # @param [Integer] id The ID of a list. + # @return [Gitlab::ObjectifiedHash] Information about deleted board list. + def delete_board_list(project, board_id, id) + delete("/projects/#{url_encode project}/boards/#{board_id}/lists/#{id}") + end + end +end + diff --git a/lib/gitlab/client/branches.rb b/lib/gitlab/client/branches.rb index 1249a86..ef50140 100644 --- a/lib/gitlab/client/branches.rb +++ b/lib/gitlab/client/branches.rb @@ -36,12 +36,18 @@ # @example # Gitlab.protect_branch(3, 'api') # Gitlab.repo_protect_branch(5, 'master') + # Gitlab.protect_branch(5, 'api', developers_can_push: true) + # + # To update options, call `protect_branch` again with new options (i.e. `developers_can_push: false`) # # @param [Integer, String] project The ID or name of a project. # @param [String] branch The name of the branch. - # @return [Gitlab::ObjectifiedHash] - def protect_branch(project, branch) - put("/projects/#{url_encode project}/repository/branches/#{branch}/protect") + # @param [Hash] options A customizable set of options. + # @option options [Boolean] :developers_can_push True to allow developers to push to the branch (default = false) + # @option options [Boolean] :developers_can_merge True to allow developers to merge into the branch (default = false) + # @return [Gitlab::ObjectifiedHash] Details about the branch + def protect_branch(project, branch, options = {}) + put("/projects/#{url_encode project}/repository/branches/#{branch}/protect", body: options) end alias_method :repo_protect_branch, :protect_branch @@ -53,7 +59,7 @@ # # @param [Integer, String] project The ID or name of a project. # @param [String] branch The name of the branch. - # @return [Gitlab::ObjectifiedHash] + # @return [Gitlab::ObjectifiedHash] Details about the branch def unprotect_branch(project, branch) put("/projects/#{url_encode project}/repository/branches/#{branch}/unprotect") end @@ -68,9 +74,9 @@ # @param [Integer, String] project The ID or name of a project. # @param [String] branch The name of the new branch. # @param [String] ref Create branch from commit sha or existing branch - # @return [Gitlab::ObjectifiedHash] + # @return [Gitlab::ObjectifiedHash] Details about the branch def create_branch(project, branch, ref) - post("/projects/#{url_encode project}/repository/branches", body: { branch_name: branch, ref: ref }) + post("/projects/#{url_encode project}/repository/branches", body: { branch: branch, ref: ref }) end alias_method :repo_create_branch, :create_branch @@ -82,7 +88,6 @@ # # @param [Integer, String] project The ID or name of a project. # @param [String] branch The name of the branch to delete - # @return [Gitlab::ObjectifiedHash] def delete_branch(project, branch) delete("/projects/#{url_encode project}/repository/branches/#{branch}") end diff --git a/lib/gitlab/client/commits.rb b/lib/gitlab/client/commits.rb index 97fba7c..367c6f2 100644 --- a/lib/gitlab/client/commits.rb +++ b/lib/gitlab/client/commits.rb @@ -94,8 +94,8 @@ # @option options [String] :stage Filter by stage # @option options [String] :name Filter by status name, eg. jenkins # @option options [Boolean] :all The flag to return all statuses, not only latest ones - def commit_status(id, sha, options={}) - get("/projects/#{id}/repository/commits/#{sha}/statuses", query: options) + def commit_status(project, sha, options={}) + get("/projects/#{url_encode project}/repository/commits/#{sha}/statuses", query: options) end alias_method :repo_commit_status, :commit_status @@ -113,8 +113,8 @@ # @option options [String] :ref The ref (branch or tag) to which the status refers # @option options [String] :name Filter by status name, eg. jenkins # @option options [String] :target_url The target URL to associate with this status - def update_commit_status(id, sha, state, options={}) - post("/projects/#{id}/statuses/#{sha}", query: options.merge(state: state)) + def update_commit_status(project, sha, state, options={}) + post("/projects/#{url_encode project}/statuses/#{sha}", query: options.merge(state: state)) end alias_method :repo_update_commit_status, :update_commit_status @@ -136,11 +136,11 @@ # @return [Gitlab::ObjectifiedHash] hash of commit related data def create_commit(project, branch, message, actions, options={}) payload = { - branch_name: branch, + branch: branch, commit_message: message, actions: actions, }.merge(options) - post("/projects/#{url_encode project}/repository/commits", query: payload) + post("/projects/#{url_encode project}/repository/commits", body: payload) end end end diff --git a/lib/gitlab/client/environments.rb b/lib/gitlab/client/environments.rb new file mode 100644 index 0000000..a790b81 --- /dev/null +++ b/lib/gitlab/client/environments.rb @@ -0,0 +1,87 @@ +class Gitlab::Client + # Defines methods related to environments. + # @see https://docs.gitlab.com/ce/api/environments.html + module Environments + # Gets a list of project environments. + # + # @example + # Gitlab.environments(5) + # Gitlab.environments(5, { per_page: 10, page: 2 }) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Hash] options A customizable set of options. + # @option options [Integer] :page The page number. + # @option options [Integer] :per_page The number of results per page. + # @return [Array] + def environments(project, options={}) + get("/projects/#{url_encode project}/environments", query: options) + end + + # Gets a single environment. + # + # @example + # Gitlab.environment(5, 36) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of an environment. + # @return [Gitlab::ObjectifiedHash] + def environment(project, id) + get("/projects/#{url_encode project}/environments/#{id}") + end + + # Create an environment. + # + # @examples + # Gitlab.create_environment(5, 'test-branch') + # Gitlab.create_environment(5, 'test-branch', external_url: 'https://test-branch.example.host.com') + # + # @param [Integer, String] project The ID or name of a project. + # @param [String] env_name Name for the environment + # @option options [String] :external_url Optional URL for viewing the deployed project in this environment + # @return [Gitlab::ObjectifiedHash] The updated environment. + def create_environment(project, env_name, options = {}) + body = {name: env_name}.merge(options) + post("/projects/#{url_encode project}/environments", body: body) + end + + # Update an environment. + # + # @examples + # Gitlab.edit_environment(5, 36, name: 'test-branch') + # Gitlab.edit_environment(5, 36, external_url: 'https://test-branch.example.host.com') + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of an environment. + # @param [Hash] options A hash of the attribute keys & values to update. + # @option options [String] env_name Name for the environment + # @option options [String] external_url Optional URL for viewing the deployed project in this environment + # @return [Gitlab::ObjectifiedHash] The updated environment. + def edit_environment(project, id, options={}) + put("/projects/#{url_encode project}/environments/#{id}", body: options) + end + + # Deletes an environment. + # + # @example + # Gitlab.delete_environment(5, 36) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of an environment. + # @return [Gitlab::ObjectifiedHash] Information about the deleted environment. + def delete_environment(project, id) + delete("/projects/#{url_encode project}/environments/#{id}") + end + + # Stop an environment. + # + # @example + # Gitlab.stop_environment(5, 36) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of an environment. + # @return [Array] The stopped environment. + def stop_environment(project, id) + post("/projects/#{url_encode project}/environments/#{id}/stop") + end + end +end diff --git a/lib/gitlab/client/labels.rb b/lib/gitlab/client/labels.rb index 97e2c27..2d82301 100644 --- a/lib/gitlab/client/labels.rb +++ b/lib/gitlab/client/labels.rb @@ -19,11 +19,14 @@ # Gitlab.create_label(42, "Backlog", '#DD10AA') # # @param [Integer, String] project The ID or name of a project. - # @option [String] name The name of a label. - # @option [String] color The color of a label. + # @param [String] name The name of a label. + # @param [String] color The color of a label. + # @param [Hash] options A customizable set of options. + # @option options [String] :description The description of the label. + # @option options [String] :priority The priority of the label. Must be greater or equal than zero or null to remove the priority. # @return [Gitlab::ObjectifiedHash] Information about created label. - def create_label(project, name, color) - post("/projects/#{url_encode project}/labels", body: { name: name, color: color }) + def create_label(project, name, color, options = {}) + post("/projects/#{url_encode project}/labels", body: options.merge(name: name, color: color)) end # Updates a label. @@ -37,6 +40,8 @@ # @param [Hash] options A customizable set of options. # @option options [String] :new_name The new name of a label. # @option options [String] :color The color of a label. + # @option options [String] :description The description of the label. + # @option options [String] :priority The priority of the label. Must be greater or equal than zero or null to remove the priority. # @return [Gitlab::ObjectifiedHash] Information about updated label. def edit_label(project, name, options={}) put("/projects/#{url_encode project}/labels", body: options.merge(name: name)) @@ -53,5 +58,29 @@ def delete_label(project, name) delete("/projects/#{url_encode project}/labels", body: { name: name }) end + + # Subscribes the user to a label to receive notifications + # + # @example + # Gitlab.subscribe_to_label(2, 'Backlog') + # + # @param [Integer, String] project The ID or name of a project. + # @param [String] name The name of a label. + # @return [Gitlab::ObjectifiedHash] Information about the label subscribed to. + def subscribe_to_label(project, name) + post("/projects/#{url_encode project}/labels/#{url_encode name}/subscribe") + end + + # Unsubscribes the user from a label to not receive notifications from it + # + # @example + # Gitlab.unsubscribe_from_label(2, 'Backlog') + # + # @param [Integer, String] project The ID or name of a project. + # @param [String] name The name of a label. + # @return [Gitlab::ObjectifiedHash] Information about the label unsubscribed from. + def unsubscribe_from_label(project, name) + post("/projects/#{url_encode project}/labels/#{url_encode name}/unsubscribe") + end end end diff --git a/lib/gitlab/client/merge_requests.rb b/lib/gitlab/client/merge_requests.rb index eea4cb9..dd6df91 100644 --- a/lib/gitlab/client/merge_requests.rb +++ b/lib/gitlab/client/merge_requests.rb @@ -82,65 +82,6 @@ put("/projects/#{url_encode project}/merge_requests/#{id}/merge", body: options) end - # Adds a comment to a merge request. - # - # @example - # Gitlab.create_merge_request_comment(5, 1, "Awesome merge!") - # Gitlab.create_merge_request_comment('gitlab', 1, "Awesome merge!") - # - # @param [Integer, String] project The ID or name of a project. - # @param [Integer] id The ID of a merge request. - # @param [String] note The content of a comment. - # @return [Gitlab::ObjectifiedHash] Information about created merge request comment. - def create_merge_request_comment(project, id, note) - post("/projects/#{url_encode project}/merge_requests/#{id}/notes", body: { body: note }) - end - - # Adds a comment to a merge request. - # - # @example - # Gitlab.edit_merge_request_comment(5, 1,2, "Awesome merge!") - # Gitlab.edit_merge_request_comment('gitlab', 1, 2, "Awesome merge!") - # - # @param [Integer, String] project The ID or name of a project. - # @param [Integer] id The ID of a merge request. - # @param [Integer] id The ID of the merge-request comment - # @param [String] note The content of a comment. - # @return [Gitlab::ObjectifiedHash] Information about created merge request comment. - def edit_merge_request_comment(project, id, note_id , note) - put("/projects/#{url_encode project}/merge_requests/#{id}/notes/#{note_id}", body: { body: note }) - end - - # Deletes a comment from a merge request. - # - # @example - # Gitlab.delete_merge_request_comment(5, 1,2) - # Gitlab.delete_merge_request_comment('gitlab', 1, 2) - # - # @param [Integer, String] project The ID or name of a project. - # @param [Integer] id The ID of a merge request. - # @param [Integer] id The ID of the merge-request comment - # @return [Gitlab::ObjectifiedHash] Information about created merge request comment. - def delete_merge_request_comment(project, id, note_id) - delete("/projects/#{url_encode project}/merge_requests/#{id}/notes/#{note_id}") - end - - # Gets the comments on a merge request. - # - # @example - # Gitlab.merge_request_comments(5, 1) - # Gitlab.merge_request_comments(5, 1, { per_page: 10, page: 2 }) - # - # @param [Integer, String] project The ID or name of a project. - # @param [Integer] id The ID of a merge request. - # @param [Hash] options A customizable set of options. - # @option options [Integer] :page The page number. - # @option options [Integer] :per_page The number of results per page. - # @return [Gitlab::ObjectifiedHash] The merge request's comments. - def merge_request_comments(project, id, options={}) - get("/projects/#{url_encode project}/merge_requests/#{id}/notes", query: options) - end - # Gets the changes of a merge request. # # @example diff --git a/lib/gitlab/client/notes.rb b/lib/gitlab/client/notes.rb index 495d372..529fc79 100644 --- a/lib/gitlab/client/notes.rb +++ b/lib/gitlab/client/notes.rb @@ -56,6 +56,7 @@ def merge_request_notes(project, merge_request, options={}) get("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes", query: options) end + alias_method :merge_request_comments, :merge_request_notes # Gets a single wall note. # @@ -157,5 +158,110 @@ def create_merge_request_note(project, merge_request, body) post("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes", body: { body: body }) end + alias_method :create_merge_request_comment, :create_merge_request_note + + # Deletes a wall note. + # + # @example + # Gitlab.delete_note(5, 15) + # + # @param [Integer] project The ID of a project. + # @param [Integer] id The ID of a note. + # @return [Gitlab::ObjectifiedHash] + def delete_note(project, id) + delete("/projects/#{url_encode project}/notes/#{id}") + end + + # Deletes an issue note. + # + # @example + # Gitlab.delete_issue_note(5, 10, 1) + # + # @param [Integer] project The ID of a project. + # @param [Integer] issue The ID of an issue. + # @param [Integer] id The ID of a note. + # @return [Gitlab::ObjectifiedHash] + def delete_issue_note(project, issue, id) + delete("/projects/#{url_encode project}/issues/#{issue}/notes/#{id}") + end + + # Deletes a snippet note. + # + # @example + # Gitlab.delete_snippet_note(5, 11, 3) + # + # @param [Integer] project The ID of a project. + # @param [Integer] snippet The ID of a snippet. + # @param [Integer] id The ID of a note. + # @return [Gitlab::ObjectifiedHash] + def delete_snippet_note(project, snippet, id) + delete("/projects/#{url_encode project}/snippets/#{snippet}/notes/#{id}") + end + + # Deletes a merge_request note. + # + # @example + # Gitlab.delete_merge_request_note(5, 11, 3) + # + # @param [Integer] project The ID of a project. + # @param [Integer] merge_request The ID of a merge_request. + # @param [Integer] id The ID of a note. + # @return [Gitlab::ObjectifiedHash] + def delete_merge_request_note(project, merge_request, id) + delete("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes/#{id}") + end + alias_method :delete_merge_request_comment, :delete_merge_request_note + + # Modifies a wall note. + # + # @example + # Gitlab.edit_note(5, 15, 'This is an edited note') + # + # @param [Integer] project The ID of a project. + # @param [Integer] id The ID of a note. + # @return [Gitlab::ObjectifiedHash] + def edit_note(project, id, body) + put("/projects/#{url_encode project}/notes/#{id}", body: body) + end + + # Modifies an issue note. + # + # @example + # Gitlab.edit_issue_note(5, 10, 1, 'This is an edited issue note') + # + # @param [Integer] project The ID of a project. + # @param [Integer] issue The ID of an issue. + # @param [Integer] id The ID of a note. + # @return [Gitlab::ObjectifiedHash] + def edit_issue_note(project, issue, id, body) + put("/projects/#{url_encode project}/issues/#{issue}/notes/#{id}", body: body) + end + + # Modifies a snippet note. + # + # @example + # Gitlab.edit_snippet_note(5, 11, 3, 'This is an edited snippet note') + # + # @param [Integer] project The ID of a project. + # @param [Integer] snippet The ID of a snippet. + # @param [Integer] id The ID of a note. + # @return [Gitlab::ObjectifiedHash] + def edit_snippet_note(project, snippet, id, body) + put("/projects/#{url_encode project}/snippets/#{snippet}/notes/#{id}", body: body) + end + + # Modifies a merge_request note. + # + # @example + # Gitlab.edit_merge_request_note(5, 11, 3, 'This is an edited merge request note') + # + # @param [Integer] project The ID of a project. + # @param [Integer] merge_request The ID of a merge_request. + # @param [Integer] id The ID of a note. + # @return [Gitlab::ObjectifiedHash] + def edit_merge_request_note(project, merge_request, id, body) + put("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes/#{id}", body: body) + end + alias_method :edit_merge_request_comment, :edit_merge_request_note end end diff --git a/lib/gitlab/client/projects.rb b/lib/gitlab/client/projects.rb index 69b3bd5..1496ca8 100644 --- a/lib/gitlab/client/projects.rb +++ b/lib/gitlab/client/projects.rb @@ -34,7 +34,7 @@ # @option options [String] :sort Return requests sorted in asc or desc order # @return [Array] def project_search(query, options={}) - get("/projects/search/#{query}", query: options) + get("/projects", query: options.merge(search:query)) end alias_method :search_projects, :project_search @@ -44,7 +44,7 @@ # Gitlab.project(3) # Gitlab.project('gitlab') # - # @param [Integer, String] id The ID or name of a project. + # @param [Integer, String] id The ID or path of a project. # @return [Gitlab::ObjectifiedHash] def project(id) get("/projects/#{url_encode id}") @@ -56,7 +56,7 @@ # Gitlab.project_events(42) # Gitlab.project_events('gitlab') # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Hash] options A customizable set of options. # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. @@ -76,6 +76,7 @@ # @param [Hash] options A customizable set of options. # @option options [String] :description The description of a project. # @option options [String] :default_branch The default branch of a project. + # @option options [String] :path Repository name for new project. (Default is lowercase name with dashes) # @option options [String] :namespace_id The namespace in which to create a project. # @option options [Boolean] :wiki_enabled The wiki integration for a project (0 = false, 1 = true). # @option options [Boolean] :wall_enabled The wall functionality for a project (0 = false, 1 = true). @@ -95,10 +96,10 @@ # @example # Gitlab.delete_project(4) # - # @param [Integer, String] id The ID or name of a project. + # @param [Integer, String] id The ID or path of a project. # @return [Gitlab::ObjectifiedHash] Information about deleted project. def delete_project(id) - delete("/projects/#{id}") + delete("/projects/#{url_encode id}") end # Gets a list of project team members. @@ -107,7 +108,7 @@ # Gitlab.team_members(42) # Gitlab.team_members('gitlab') # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Hash] options A customizable set of options. # @option options [String] :query The search query. # @option options [Integer] :page The page number. @@ -122,7 +123,7 @@ # @example # Gitlab.team_member('gitlab', 2) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] id The ID of a project team member. # @return [Gitlab::ObjectifiedHash] def team_member(project, id) @@ -134,7 +135,7 @@ # @example # Gitlab.add_team_member('gitlab', 2, 40) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] id The ID of a user. # @param [Integer] access_level The access level to project. # @param [Hash] options A customizable set of options. @@ -148,7 +149,7 @@ # @example # Gitlab.edit_team_member('gitlab', 3, 20) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] id The ID of a user. # @param [Integer] access_level The access level to project. # @param [Hash] options A customizable set of options. @@ -162,7 +163,7 @@ # @example # Gitlab.remove_team_member('gitlab', 2) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] id The ID of a user. # @param [Hash] options A customizable set of options. # @return [Gitlab::ObjectifiedHash] Information about removed team member. @@ -176,7 +177,7 @@ # Gitlab.project_hooks(42) # Gitlab.project_hooks('gitlab') # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Hash] options A customizable set of options. # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. @@ -191,7 +192,7 @@ # Gitlab.project_hook(42, 5) # Gitlab.project_hook('gitlab', 5) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] id The ID of a hook. # @return [Gitlab::ObjectifiedHash] def project_hook(project, id) @@ -203,7 +204,7 @@ # @example # Gitlab.add_project_hook(42, 'https://api.example.net/v1/webhooks/ci') # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [String] url The hook URL. # @param [Hash] options A customizable set of options. # @param option [Boolean] :push_events Trigger hook on push events (0 = false, 1 = true) @@ -221,7 +222,7 @@ # @example # Gitlab.edit_project_hook(42, 1, 'https://api.example.net/v1/webhooks/ci') # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] id The ID of the hook. # @param [String] url The hook URL. # @param [Hash] options A customizable set of options. @@ -240,7 +241,7 @@ # @example # Gitlab.delete_project_hook('gitlab', 4) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [String] id The ID of the hook. # @return [Gitlab::ObjectifiedHash] Information about deleted hook. def delete_project_hook(project, id) @@ -256,7 +257,7 @@ # @param [Integer] id The ID of a project. # @return [Gitlab::ObjectifiedHash] def push_rule(id) - get("/projects/#{id}/push_rule") + get("/projects/#{url_encode id}/push_rule") end # Adds a project push rule. @@ -271,7 +272,7 @@ # @param option [String] :commit_message_regex Commit message regex # @return [Gitlab::ObjectifiedHash] Information about added push rule. def add_push_rule(id, options={}) - post("/projects/#{id}/push_rule", body: options) + post("/projects/#{url_encode id}/push_rule", body: options) end # Updates a project push rule. @@ -286,7 +287,7 @@ # @param option [String] :commit_message_regex Commit message regex # @return [Gitlab::ObjectifiedHash] Information about updated push rule. def edit_push_rule(id, options={}) - put("/projects/#{id}/push_rule", body: options) + put("/projects/#{url_encode id}/push_rule", body: options) end # Deletes a push rule from a project. @@ -298,7 +299,7 @@ # @param [Integer] id The ID of a project. # @return [Gitlab::ObjectifiedHash] Information about deleted push rule. def delete_push_rule(id, options={}) - delete("/projects/#{id}/push_rule") + delete("/projects/#{url_encode id}/push_rule") end # Mark this project as forked from the other @@ -306,7 +307,7 @@ # @example # Gitlab.make_forked(42, 24) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] id The ID of the project it is forked from. # @return [Gitlab::ObjectifiedHash] Information about the forked project. def make_forked_from(project, id) @@ -318,7 +319,7 @@ # @example # Gitlab.remove_forked(42) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] project The ID of the project it is forked from # @return [Gitlab::ObjectifiedHash] Information about the forked project. def remove_forked(project) @@ -330,7 +331,7 @@ # @example # Gitlab.deploy_keys(42) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Hash] options A customizable set of options. # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. @@ -344,7 +345,7 @@ # @example # Gitlab.deploy_key(42, 1) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] id The ID of a deploy key. # @return [Gitlab::ObjectifiedHash] def deploy_key(project, id) @@ -356,7 +357,7 @@ # @example # Gitlab.create_deploy_key(42, 'My Key', 'Key contents') # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [String] title The title of a deploy key. # @param [String] key The content of a deploy key. # @return [Gitlab::ObjectifiedHash] Information about created deploy key. @@ -369,7 +370,7 @@ # @example # Gitlab.enable_deploy_key(42, 66) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] key The ID of a deploy key. # @return [Gitlab::ObjectifiedHash] Information about the enabled deploy key. def enable_deploy_key(project, key) @@ -381,7 +382,7 @@ # @example # Gitlab.disable_deploy_key(42, 66) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] key The ID of a deploy key. # @return [Gitlab::ObjectifiedHash] Information about the disabled deploy key. def disable_deploy_key(project, key) @@ -393,7 +394,7 @@ # @example # Gitlab.delete_deploy_key(42, 1) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] id The ID of a deploy key. # @return [Gitlab::ObjectifiedHash] Information about deleted deploy key. def delete_deploy_key(project, id) @@ -406,28 +407,31 @@ # Gitlab.create_fork(42) # Gitlab.create_fork(42, { sudo: 'another_username' }) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Hash] options A customizable set of options. # @option options [String] :sudo The username the project will be forked for # @return [Gitlab::ObjectifiedHash] Information about the forked project. def create_fork(id, options={}) - post("/projects/#{id}/fork", body: options) + post("/projects/#{url_encode id}/fork", body: options) end # Updates an existing project. # # @example # Gitlab.edit_project(42) - # Gitlab.edit_project(42, { name: 'project_name' }) - # - # @param [Integer, String] project The ID or name of a project. - # @param [Hash] options A customizable set of options. + # Gitlab.edit_project(42, { name: 'Project Name' }) + # Gitlab.edit_project('project-name', { name: 'New Project Name', path: 'new-project-patth' }) + # + # @param [Integer, String] project The ID or path of a project. + # @param [Hash] options A customizable set of options # @option options [String] :name The name of a project - # @option options [String] :path The name of a project - # @option options [String] :description The name of a project + # @option options [String] :path The project's repository name, also used in Gitlab's URLs + # @option options [String] :description The description to show in Gitlab + # (Any provided options will be passed to Gitlab. See {https://docs.gitlab.com/ce/api/projects.html#edit-project Gitlab docs} for all valid options) + # # @return [Gitlab::ObjectifiedHash] Information about the edited project. def edit_project(id, options={}) - put("/projects/#{id}", query: options) + put("/projects/#{url_encode id}", body: options) end # Share project with group. @@ -435,7 +439,7 @@ # @example # Gitlab.share_project_with_group('gitlab', 2, 40) # - # @param [Integer, String] project The ID or name of a project. + # @param [Integer, String] project The ID or path of a project. # @param [Integer] id The ID of a group. # @param [Integer] group_access The access level to project. def share_project_with_group(project, id, group_access) @@ -444,28 +448,28 @@ # Stars a project. # @see https://docs.gitlab.com/ce/api/projects.html#star-a-project - # + # # @example # Gitlab.star_project(42) # Gitlab.star_project('gitlab-org/gitlab-ce') - # - # @param [Integer, String] id The ID or name of a project. + # + # @param [Integer, String] id The ID or path of a project. # @return [Gitlab::ObjectifiedHash] Information about starred project. def star_project(id) - post("/projects/#{id}/star") + post("/projects/#{url_encode id}/star") end # Unstars a project. # @see https://docs.gitlab.com/ce/api/projects.html#unstar-a-project - # + # # @example # Gitlab.unstar_project(42) # Gitlab.unstar_project('gitlab-org/gitlab-ce') - # - # @param [Integer, String] id The ID or name of a project. + # + # @param [Integer, String] id The ID or path of a project. # @return [Gitlab::ObjectifiedHash] Information about unstarred project. def unstar_project(id) - delete("/projects/#{id}/star") + delete("/projects/#{url_encode id}/star") end end end diff --git a/lib/gitlab/client/repository_files.rb b/lib/gitlab/client/repository_files.rb index 983f58d..187e2e6 100644 --- a/lib/gitlab/client/repository_files.rb +++ b/lib/gitlab/client/repository_files.rb @@ -45,17 +45,19 @@ # Gitlab.create_file(42, "path", "branch", "content", "commit message") # # @param [Integer, String] project The ID or name of a project. - # @param [String] full path to new file. - # @param [String] the name of the branch. - # @param [String] file content. - # @param [String] commit message. + # @param [String] path full path to new file. + # @param [String] branch the name of the branch. + # @param [String] content file content. + # @param [String] commit_message ...commit message. + # @param [Hash] options Optional additional details for commit + # @option options [String] :author_name Commit author's name + # @option options [String] :author_email Commit author's email address # @return [Gitlab::ObjectifiedHash] - def create_file(project, path, branch, content, commit_message) - post("/projects/#{url_encode project}/repository/files", body: { - file_path: path, - branch_name: branch, + def create_file(project, path, branch, content, commit_message, options = {}) + post("/projects/#{url_encode project}/repository/files/#{url_encode path}", body: { + branch: branch, commit_message: commit_message - }.merge(encoded_content_attributes(content))) + }.merge(options).merge(encoded_content_attributes(content))) end # Edits an existing repository file. @@ -64,17 +66,19 @@ # Gitlab.edit_file(42, "path", "branch", "content", "commit message") # # @param [Integer, String] project The ID or name of a project. - # @param [String] full path to new file. - # @param [String] the name of the branch. - # @param [String] file content. - # @param [String] commit message. + # @param [String] path full path of file to update. + # @param [String] branch the name of the branch to commit changes to. + # @param [String] content new file content. + # @param [String] commit_message ...commit message. + # @param [Hash] options Optional additional details for commit + # @option options [String] :author_name Commit author's name + # @option options [String] :author_email Commit author's email address # @return [Gitlab::ObjectifiedHash] - def edit_file(project, path, branch, content, commit_message) - put("/projects/#{url_encode project}/repository/files", body: { - file_path: path, - branch_name: branch, + def edit_file(project, path, branch, content, commit_message, options = {}) + put("/projects/#{url_encode project}/repository/files/#{url_encode path}", body: { + branch: branch, commit_message: commit_message - }.merge(encoded_content_attributes(content))) + }.merge(options).merge(encoded_content_attributes(content))) end # Removes an existing repository file. @@ -83,16 +87,18 @@ # Gitlab.remove_file(42, "path", "branch", "commit message") # # @param [Integer, String] project The ID or name of a project. - # @param [String] full path to new file. - # @param [String] the name of the branch. - # @param [String] commit message. + # @param [String] path full path of file to delete. + # @param [String] branch the name of the branch to commit the deletion to. + # @param [String] commit_message ...a commit message ;) + # @param [Hash] options Optional additional details for commit + # @option options [String] :author_name Commit author's name + # @option options [String] :author_email Commit author's email address # @return [Gitlab::ObjectifiedHash] - def remove_file(project, path, branch, commit_message) - delete("/projects/#{url_encode project}/repository/files", body: { - file_path: path, - branch_name: branch, + def remove_file(project, path, branch, commit_message, options = {}) + delete("/projects/#{url_encode project}/repository/files/#{url_encode path}", body: { + branch: branch, commit_message: commit_message - }) + }.merge(options)) end private diff --git a/lib/gitlab/client/system_hooks.rb b/lib/gitlab/client/system_hooks.rb index fae3b51..35896b3 100644 --- a/lib/gitlab/client/system_hooks.rb +++ b/lib/gitlab/client/system_hooks.rb @@ -24,9 +24,12 @@ # Gitlab.add_system_hook('https://api.example.net/v1/hook') # # @param [String] url The hook URL. + # @param [Hash] options Additional options, as allowed by Gitlab API, including but not limited to: + # @option options [String] :token A secret token for Gitlab to send in the `X-Gitlab-Token` header for authentication. + # @option options [boolean] :enable_ssl_verification `false` will cause Gitlab to ignore invalid/unsigned certificate errors (default is `true`) # @return [Gitlab::ObjectifiedHash] - def add_hook(url) - post("/hooks", body: { url: url }) + def add_hook(url, options = {}) + post("/hooks", body: options.merge(url: url)) end alias_method :add_system_hook, :add_hook diff --git a/lib/gitlab/client/todos.rb b/lib/gitlab/client/todos.rb new file mode 100644 index 0000000..ee71766 --- /dev/null +++ b/lib/gitlab/client/todos.rb @@ -0,0 +1,44 @@ +class Gitlab::Client + # Defines methods related to todos + # @see https://docs.gitlab.com/ce/api/todos.html + module Todos + # Gets a list of todos. + # + # @example + # Gitlab.todos + # Gitlab.todos({ action: 'assigned' }) + # Gitlab.todos({ state: 'pending' }) + # + # @param [Hash] options A customizable set of options. + # @option options [Integer] :action The action to be filtered. Can be `assigned`, `mentioned`, `build_failed`, `marked`, or `approval_required`. + # @option options [Integer] :author_id The ID of an author + # @option options [Integer] :project_id The ID of a project + # @option options [Integer] :state The state of the todo. Can be either `pending` or `done` + # @option options [Integer] :type The type of a todo. Can be either `Issue` or `MergeRequest` + # @return [Array] + def todos(options={}) + get("/todos", query: options) + end + + # Marks a single pending todo for the current user as done. + # + # @example + # Gitlab.mark_todo_as_done(42) + # + # @param [Integer] id The ID of the todo. + # @return [Gitlab::ObjectifiedHash] + def mark_todo_as_done(id) + post("/todos/#{id}/mark_as_done") + end + + # Marks all todos for the current user as done + # + # @example + # Gitlab.mark_all_todos_as_done + # + # @return [void] This API call returns an empty response body. + def mark_all_todos_as_done + post("/todos/mark_as_done") + end + end +end \ No newline at end of file diff --git a/lib/gitlab/client.rb b/lib/gitlab/client.rb index 3684d94..d46bd40 100644 --- a/lib/gitlab/client.rb +++ b/lib/gitlab/client.rb @@ -3,10 +3,13 @@ class Client < API Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f } + include AwardEmojis + include Boards include Branches include Builds include BuildVariables include Commits + include Environments include Groups include Issues include Keys @@ -25,6 +28,7 @@ include Snippets include SystemHooks include Tags + include Todos include Users include Jobs diff --git a/lib/gitlab/version.rb b/lib/gitlab/version.rb index 4c8f93b..5cf9381 100644 --- a/lib/gitlab/version.rb +++ b/lib/gitlab/version.rb @@ -1,3 +1,3 @@ module Gitlab - VERSION = "4.1.0" + VERSION = "4.2.0" end diff --git a/spec/fixtures/board_list.json b/spec/fixtures/board_list.json new file mode 100644 index 0000000..8387063 --- /dev/null +++ b/spec/fixtures/board_list.json @@ -0,0 +1 @@ +{ "id" : 1, "label" : { "name" : "Testing", "color" : "#F0AD4E", "description" : null }, "position" : 1 } diff --git a/spec/fixtures/board_lists.json b/spec/fixtures/board_lists.json new file mode 100644 index 0000000..baf7d86 --- /dev/null +++ b/spec/fixtures/board_lists.json @@ -0,0 +1 @@ +[ { "id" : 1, "label" : { "name" : "Testing", "color" : "#F0AD4E", "description" : null }, "position" : 1 }, { "id" : 2, "label" : { "name" : "Ready", "color" : "#FF0000", "description" : null }, "position" : 2 }, { "id" : 3, "label" : { "name" : "Production", "color" : "#FF5F00", "description" : null }, "position" : 3 } ] diff --git a/spec/fixtures/boards.json b/spec/fixtures/boards.json new file mode 100644 index 0000000..beaac52 --- /dev/null +++ b/spec/fixtures/boards.json @@ -0,0 +1 @@ +[ { "id" : 1, "lists" : [ { "id" : 1, "label" : { "name" : "Testing", "color" : "#F0AD4E", "description" : null }, "position" : 1 }, { "id" : 2, "label" : { "name" : "Ready", "color" : "#FF0000", "description" : null }, "position" : 2 }, { "id" : 3, "label" : { "name" : "Production", "color" : "#FF5F00", "description" : null }, "position" : 3 } ] } ] diff --git a/spec/fixtures/environment.json b/spec/fixtures/environment.json new file mode 100644 index 0000000..d1c004b --- /dev/null +++ b/spec/fixtures/environment.json @@ -0,0 +1,6 @@ +{ + "id": 12, + "name": "staging", + "slug": "staging-cb247rv", + "external_url": "https://staging.example.gitlab.com" +} \ No newline at end of file diff --git a/spec/fixtures/environments.json b/spec/fixtures/environments.json new file mode 100644 index 0000000..e1feeb5 --- /dev/null +++ b/spec/fixtures/environments.json @@ -0,0 +1,14 @@ +[ + { + "id": 1, + "name": "review/fix-foo", + "slug": "review-fix-foo-dfjre3", + "external_url": "https://review-fix-foo-dfjre3.example.gitlab.com" + }, + { + "id": 12, + "name": "review/fix-bar", + "slug": "review-fix-bar-dbwr18", + "external_url": "https://review-fix-bar-dbwr18.example.gitlab.com" + } +] \ No newline at end of file diff --git a/spec/fixtures/issue_award_emoji.json b/spec/fixtures/issue_award_emoji.json new file mode 100644 index 0000000..fefeaf1 --- /dev/null +++ b/spec/fixtures/issue_award_emoji.json @@ -0,0 +1,16 @@ +{ + "id": 4, + "name": "blowfish", + "user": { + "name": "Administrator", + "username": "root", + "id": 1, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "http://gitlab.example.com/root" + }, + "created_at": "2016-06-15T10:09:34.206Z", + "updated_at": "2016-06-15T10:09:34.206Z", + "awardable_id": 80, + "awardable_type": "Issue" +} \ No newline at end of file diff --git a/spec/fixtures/issue_award_emojis.json b/spec/fixtures/issue_award_emojis.json new file mode 100644 index 0000000..44338b8 --- /dev/null +++ b/spec/fixtures/issue_award_emojis.json @@ -0,0 +1,34 @@ +[ + { + "id": 4, + "name": "1234", + "user": { + "name": "Administrator", + "username": "root", + "id": 1, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "http://gitlab.example.com/root" + }, + "created_at": "2016-06-15T10:09:34.206Z", + "updated_at": "2016-06-15T10:09:34.206Z", + "awardable_id": 80, + "awardable_type": "Issue" + }, + { + "id": 1, + "name": "microphone", + "user": { + "name": "User 4", + "username": "user4", + "id": 26, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/7e65550957227bd38fe2d7fbc6fd2f7b?s=80&d=identicon", + "web_url": "http://gitlab.example.com/user4" + }, + "created_at": "2016-06-15T10:09:34.177Z", + "updated_at": "2016-06-15T10:09:34.177Z", + "awardable_id": 80, + "awardable_type": "Issue" + } +] \ No newline at end of file diff --git a/spec/fixtures/label.json b/spec/fixtures/label.json index 5308d6b..8e8ef22 100644 --- a/spec/fixtures/label.json +++ b/spec/fixtures/label.json @@ -1 +1 @@ -{"name": "Backlog", "color": "#DD10AA"} +{"name": "Backlog", "color": "#DD10AA", "subscribed": true} diff --git a/spec/fixtures/label_unsubscribe.json b/spec/fixtures/label_unsubscribe.json new file mode 100644 index 0000000..aebc94d --- /dev/null +++ b/spec/fixtures/label_unsubscribe.json @@ -0,0 +1 @@ +{"name": "Backlog", "color": "#DD10AA", "subscribed": false} diff --git a/spec/fixtures/merge_request_award_emoji.json b/spec/fixtures/merge_request_award_emoji.json new file mode 100644 index 0000000..491493a --- /dev/null +++ b/spec/fixtures/merge_request_award_emoji.json @@ -0,0 +1,16 @@ +{ + "id": 4, + "name": "blowfish", + "user": { + "name": "Administrator", + "username": "root", + "id": 1, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "http://gitlab.example.com/root" + }, + "created_at": "2016-06-15T10:09:34.206Z", + "updated_at": "2016-06-15T10:09:34.206Z", + "awardable_id": 80, + "awardable_type": "MergeRequest" +} \ No newline at end of file diff --git a/spec/fixtures/merge_request_award_emojis.json b/spec/fixtures/merge_request_award_emojis.json new file mode 100644 index 0000000..1cb0758 --- /dev/null +++ b/spec/fixtures/merge_request_award_emojis.json @@ -0,0 +1,34 @@ +[ + { + "id": 4, + "name": "1234", + "user": { + "name": "Administrator", + "username": "root", + "id": 1, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "http://gitlab.example.com/root" + }, + "created_at": "2016-06-15T10:09:34.206Z", + "updated_at": "2016-06-15T10:09:34.206Z", + "awardable_id": 80, + "awardable_type": "MergeRequest" + }, + { + "id": 1, + "name": "microphone", + "user": { + "name": "User 4", + "username": "user4", + "id": 26, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/7e65550957227bd38fe2d7fbc6fd2f7b?s=80&d=identicon", + "web_url": "http://gitlab.example.com/user4" + }, + "created_at": "2016-06-15T10:09:34.177Z", + "updated_at": "2016-06-15T10:09:34.177Z", + "awardable_id": 80, + "awardable_type": "MergeRequest" + } +] \ No newline at end of file diff --git a/spec/fixtures/note_award_emoji.json b/spec/fixtures/note_award_emoji.json new file mode 100644 index 0000000..26c7413 --- /dev/null +++ b/spec/fixtures/note_award_emoji.json @@ -0,0 +1,16 @@ +{ + "id": 4, + "name": "mood_bubble_lightning", + "user": { + "name": "User 4", + "username": "user4", + "id": 26, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/7e65550957227bd38fe2d7fbc6fd2f7b?s=80&d=identicon", + "web_url": "http://gitlab.example.com/user4" + }, + "created_at": "2016-06-15T10:09:34.197Z", + "updated_at": "2016-06-15T10:09:34.197Z", + "awardable_id": 1, + "awardable_type": "Note" +} diff --git a/spec/fixtures/note_award_emojis.json b/spec/fixtures/note_award_emojis.json new file mode 100644 index 0000000..cc701ba --- /dev/null +++ b/spec/fixtures/note_award_emojis.json @@ -0,0 +1,18 @@ +[ + { + "id": 2, + "name": "mood_bubble_lightning", + "user": { + "name": "User 4", + "username": "user4", + "id": 26, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/7e65550957227bd38fe2d7fbc6fd2f7b?s=80&d=identicon", + "web_url": "http://gitlab.example.com/user4" + }, + "created_at": "2016-06-15T10:09:34.197Z", + "updated_at": "2016-06-15T10:09:34.197Z", + "awardable_id": 1, + "awardable_type": "Note" + } +] \ No newline at end of file diff --git a/spec/fixtures/snippet_award_emoji.json b/spec/fixtures/snippet_award_emoji.json new file mode 100644 index 0000000..666e296 --- /dev/null +++ b/spec/fixtures/snippet_award_emoji.json @@ -0,0 +1,16 @@ +{ + "id": 4, + "name": "blowfish", + "user": { + "name": "Administrator", + "username": "root", + "id": 1, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "http://gitlab.example.com/root" + }, + "created_at": "2016-06-15T10:09:34.206Z", + "updated_at": "2016-06-15T10:09:34.206Z", + "awardable_id": 80, + "awardable_type": "Snippet" +} \ No newline at end of file diff --git a/spec/fixtures/snippet_award_emojis.json b/spec/fixtures/snippet_award_emojis.json new file mode 100644 index 0000000..cce5887 --- /dev/null +++ b/spec/fixtures/snippet_award_emojis.json @@ -0,0 +1,34 @@ +[ + { + "id": 4, + "name": "1234", + "user": { + "name": "Administrator", + "username": "root", + "id": 1, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "http://gitlab.example.com/root" + }, + "created_at": "2016-06-15T10:09:34.206Z", + "updated_at": "2016-06-15T10:09:34.206Z", + "awardable_id": 80, + "awardable_type": "Snippet" + }, + { + "id": 1, + "name": "microphone", + "user": { + "name": "User 4", + "username": "user4", + "id": 26, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/7e65550957227bd38fe2d7fbc6fd2f7b?s=80&d=identicon", + "web_url": "http://gitlab.example.com/user4" + }, + "created_at": "2016-06-15T10:09:34.177Z", + "updated_at": "2016-06-15T10:09:34.177Z", + "awardable_id": 80, + "awardable_type": "Snippet" + } +] \ No newline at end of file diff --git a/spec/fixtures/todo.json b/spec/fixtures/todo.json new file mode 100644 index 0000000..deff6fb --- /dev/null +++ b/spec/fixtures/todo.json @@ -0,0 +1,73 @@ +{ + "id": 102, + "project": { + "id": 2, + "name": "Gitlab Ce", + "name_with_namespace": "Gitlab Org / Gitlab Ce", + "path": "gitlab-ce", + "path_with_namespace": "gitlab-org/gitlab-ce" + }, + "author": { + "name": "Administrator", + "username": "root", + "id": 1, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "https://gitlab.example.com/root" + }, + "action_name": "marked", + "target_type": "MergeRequest", + "target": { + "id": 34, + "iid": 7, + "project_id": 2, + "title": "Dolores in voluptatem tenetur praesentium omnis repellendus voluptatem quaerat.", + "description": "Et ea et omnis illum cupiditate. Dolor aspernatur tenetur ducimus facilis est nihil. Quo esse cupiditate molestiae illo corrupti qui quidem dolor.", + "state": "opened", + "created_at": "2016-06-17T07:49:24.419Z", + "updated_at": "2016-06-17T07:52:43.484Z", + "target_branch": "tutorials_git_tricks", + "source_branch": "DNSBL_docs", + "upvotes": 0, + "downvotes": 0, + "author": { + "name": "Maxie Medhurst", + "username": "craig_rutherford", + "id": 12, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/a0d477b3ea21970ce6ffcbb817b0b435?s=80&d=identicon", + "web_url": "https://gitlab.example.com/craig_rutherford" + }, + "assignee": { + "name": "Administrator", + "username": "root", + "id": 1, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "https://gitlab.example.com/root" + }, + "source_project_id": 2, + "target_project_id": 2, + "labels": [], + "work_in_progress": false, + "milestone": { + "id": 32, + "iid": 2, + "project_id": 2, + "title": "v1.0", + "description": "Assumenda placeat ea voluptatem voluptate qui.", + "state": "active", + "created_at": "2016-06-17T07:47:34.163Z", + "updated_at": "2016-06-17T07:47:34.163Z", + "due_date": null + }, + "merge_when_pipeline_succeeds": false, + "merge_status": "cannot_be_merged", + "subscribed": true, + "user_notes_count": 7 + }, + "target_url": "https://gitlab.example.com/gitlab-org/gitlab-ce/merge_requests/7", + "body": "Dolores in voluptatem tenetur praesentium omnis repellendus voluptatem quaerat.", + "state": "done", + "created_at": "2016-06-17T07:52:35.225Z" +} \ No newline at end of file diff --git a/spec/fixtures/todos.json b/spec/fixtures/todos.json new file mode 100644 index 0000000..98a7db3 --- /dev/null +++ b/spec/fixtures/todos.json @@ -0,0 +1,148 @@ +[ + { + "id": 102, + "project": { + "id": 2, + "name": "Gitlab Ce", + "name_with_namespace": "Gitlab Org / Gitlab Ce", + "path": "gitlab-ce", + "path_with_namespace": "gitlab-org/gitlab-ce" + }, + "author": { + "name": "Administrator", + "username": "root", + "id": 1, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "https://gitlab.example.com/root" + }, + "action_name": "marked", + "target_type": "MergeRequest", + "target": { + "id": 34, + "iid": 7, + "project_id": 2, + "title": "Dolores in voluptatem tenetur praesentium omnis repellendus voluptatem quaerat.", + "description": "Et ea et omnis illum cupiditate. Dolor aspernatur tenetur ducimus facilis est nihil. Quo esse cupiditate molestiae illo corrupti qui quidem dolor.", + "state": "opened", + "created_at": "2016-06-17T07:49:24.419Z", + "updated_at": "2016-06-17T07:52:43.484Z", + "target_branch": "tutorials_git_tricks", + "source_branch": "DNSBL_docs", + "upvotes": 0, + "downvotes": 0, + "author": { + "name": "Maxie Medhurst", + "username": "craig_rutherford", + "id": 12, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/a0d477b3ea21970ce6ffcbb817b0b435?s=80&d=identicon", + "web_url": "https://gitlab.example.com/craig_rutherford" + }, + "assignee": { + "name": "Administrator", + "username": "root", + "id": 1, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "https://gitlab.example.com/root" + }, + "source_project_id": 2, + "target_project_id": 2, + "labels": [], + "work_in_progress": false, + "milestone": { + "id": 32, + "iid": 2, + "project_id": 2, + "title": "v1.0", + "description": "Assumenda placeat ea voluptatem voluptate qui.", + "state": "active", + "created_at": "2016-06-17T07:47:34.163Z", + "updated_at": "2016-06-17T07:47:34.163Z", + "due_date": null + }, + "merge_when_pipeline_succeeds": false, + "merge_status": "cannot_be_merged", + "subscribed": true, + "user_notes_count": 7 + }, + "target_url": "https://gitlab.example.com/gitlab-org/gitlab-ce/merge_requests/7", + "body": "Dolores in voluptatem tenetur praesentium omnis repellendus voluptatem quaerat.", + "state": "pending", + "created_at": "2016-06-17T07:52:35.225Z" + }, + { + "id": 98, + "project": { + "id": 2, + "name": "Gitlab Ce", + "name_with_namespace": "Gitlab Org / Gitlab Ce", + "path": "gitlab-ce", + "path_with_namespace": "gitlab-org/gitlab-ce" + }, + "author": { + "name": "Maxie Medhurst", + "username": "craig_rutherford", + "id": 12, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/a0d477b3ea21970ce6ffcbb817b0b435?s=80&d=identicon", + "web_url": "https://gitlab.example.com/craig_rutherford" + }, + "action_name": "assigned", + "target_type": "MergeRequest", + "target": { + "id": 34, + "iid": 7, + "project_id": 2, + "title": "Dolores in voluptatem tenetur praesentium omnis repellendus voluptatem quaerat.", + "description": "Et ea et omnis illum cupiditate. Dolor aspernatur tenetur ducimus facilis est nihil. Quo esse cupiditate molestiae illo corrupti qui quidem dolor.", + "state": "opened", + "created_at": "2016-06-17T07:49:24.419Z", + "updated_at": "2016-06-17T07:52:43.484Z", + "target_branch": "tutorials_git_tricks", + "source_branch": "DNSBL_docs", + "upvotes": 0, + "downvotes": 0, + "author": { + "name": "Maxie Medhurst", + "username": "craig_rutherford", + "id": 12, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/a0d477b3ea21970ce6ffcbb817b0b435?s=80&d=identicon", + "web_url": "https://gitlab.example.com/craig_rutherford" + }, + "assignee": { + "name": "Administrator", + "username": "root", + "id": 1, + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url": "https://gitlab.example.com/root" + }, + "source_project_id": 2, + "target_project_id": 2, + "labels": [], + "work_in_progress": false, + "milestone": { + "id": 32, + "iid": 2, + "project_id": 2, + "title": "v1.0", + "description": "Assumenda placeat ea voluptatem voluptate qui.", + "state": "active", + "created_at": "2016-06-17T07:47:34.163Z", + "updated_at": "2016-06-17T07:47:34.163Z", + "due_date": null + }, + "merge_when_pipeline_succeeds": false, + "merge_status": "cannot_be_merged", + "subscribed": true, + "user_notes_count": 7 + }, + "target_url": "https://gitlab.example.com/gitlab-org/gitlab-ce/merge_requests/7", + "body": "Dolores in voluptatem tenetur praesentium omnis repellendus voluptatem quaerat.", + "state": "pending", + "created_at": "2016-06-17T07:49:24.624Z" + } +] \ No newline at end of file diff --git a/spec/gitlab/client/award_emojis_spec.rb b/spec/gitlab/client/award_emojis_spec.rb new file mode 100644 index 0000000..9acbdf4 --- /dev/null +++ b/spec/gitlab/client/award_emojis_spec.rb @@ -0,0 +1,391 @@ +require 'spec_helper' + +describe Gitlab::Client do + describe '.award_emojis' do + context 'when issue award emojis' do + before do + stub_get("/projects/1/issues/80/award_emoji", "issue_award_emojis") + @emojis = Gitlab.award_emojis(1, 80, 'issue') + end + + it "should get the correct resources" do + expect(a_get("/projects/1/issues/80/award_emoji")).to have_been_made + end + + it "should return a paginated response of issue award emojis" do + expect(@emojis).to be_a Gitlab::PaginatedResponse + expect(@emojis.first.awardable_id).to eq(80) + expect(@emojis.first.awardable_type).to eq("Issue") + end + end + + context 'when merge request award emojis' do + before do + stub_get("/projects/1/merge_requests/80/award_emoji", "merge_request_award_emojis") + @emojis = Gitlab.award_emojis(1, 80, 'merge_request') + end + + it "should get the correct resources" do + expect(a_get("/projects/1/merge_requests/80/award_emoji")).to have_been_made + end + + it "should return a paginated response of merge request award emojis" do + expect(@emojis).to be_a Gitlab::PaginatedResponse + expect(@emojis.first.awardable_id).to eq(80) + expect(@emojis.first.awardable_type).to eq("MergeRequest") + end + end + + context 'when snippet award emojis' do + before do + stub_get("/projects/1/snippets/80/award_emoji", "snippet_award_emojis") + @emojis = Gitlab.award_emojis(1, 80, 'snippet') + end + + it "should get the correct resources" do + expect(a_get("/projects/1/snippets/80/award_emoji")).to have_been_made + end + + it "should return a paginated response of snippet award emojis" do + expect(@emojis).to be_a Gitlab::PaginatedResponse + expect(@emojis.first.awardable_id).to eq(80) + expect(@emojis.first.awardable_type).to eq("Snippet") + end + end + end + + describe '.note_award_emojis' do + context 'when issue note award emojis' do + before do + stub_get("/projects/1/issues/80/notes/1/award_emoji", "note_award_emojis") + @note_emojis = Gitlab.note_award_emojis(1, 80, 'issue', 1) + end + + it "should get the correct resources" do + expect(a_get("/projects/1/issues/80/notes/1/award_emoji")).to have_been_made + end + + it "should return a paginated response of issue note award emojis" do + expect(@note_emojis).to be_a Gitlab::PaginatedResponse + expect(@note_emojis.first.awardable_id).to eq(1) + expect(@note_emojis.first.awardable_type).to eq("Note") + end + end + + context 'when merge request note award emojis' do + before do + stub_get("/projects/1/merge_requests/80/notes/1/award_emoji", "note_award_emojis") + @note_emojis = Gitlab.note_award_emojis(1, 80, 'merge_request', 1) + end + + it "should get the correct resources" do + expect(a_get("/projects/1/merge_requests/80/notes/1/award_emoji")).to have_been_made + end + + it "should return a paginated response of merge request note award emojis" do + expect(@note_emojis).to be_a Gitlab::PaginatedResponse + expect(@note_emojis.first.awardable_id).to eq(1) + expect(@note_emojis.first.awardable_type).to eq("Note") + end + end + + context 'when snippet note award emojis' do + before do + stub_get("/projects/1/snippets/80/notes/1/award_emoji", "note_award_emojis") + @note_emojis = Gitlab.note_award_emojis(1, 80, 'snippet', 1) + end + + it "should get the correct resources" do + expect(a_get("/projects/1/snippets/80/notes/1/award_emoji")).to have_been_made + end + + it "should return a paginated response of snippet note award emojis" do + expect(@note_emojis).to be_a Gitlab::PaginatedResponse + expect(@note_emojis.first.awardable_id).to eq(1) + expect(@note_emojis.first.awardable_type).to eq("Note") + end + end + end + + describe '.award_emoji' do + context 'when issue award emoji' do + before do + stub_get("/projects/1/issues/80/award_emoji/4", "issue_award_emoji") + @emoji = Gitlab.award_emoji(1, 80, 'issue', 4) + end + + it "should get the correct resource" do + expect(a_get("/projects/1/issues/80/award_emoji/4")).to have_been_made + end + + it "should return information about an issue award emoji" do + expect(@emoji.id).to eq(4) + expect(@emoji.awardable_type).to eq("Issue") + expect(@emoji.awardable_id).to eq(80) + end + end + + context 'when merge request award emoji' do + before do + stub_get("/projects/1/merge_requests/80/award_emoji/4", "merge_request_award_emoji") + @emoji = Gitlab.award_emoji(1, 80, 'merge_request', 4) + end + + it "should get the correct resource" do + expect(a_get("/projects/1/merge_requests/80/award_emoji/4")).to have_been_made + end + + it "should return information about a merge request award emoji" do + expect(@emoji.id).to eq(4) + expect(@emoji.awardable_type).to eq("MergeRequest") + expect(@emoji.awardable_id).to eq(80) + end + end + + context 'when snippet award emoji' do + before do + stub_get("/projects/1/snippets/80/award_emoji/4", "snippet_award_emoji") + @emoji = Gitlab.award_emoji(1, 80, 'snippet', 4) + end + + it "should get the correct resource" do + expect(a_get("/projects/1/snippets/80/award_emoji/4")).to have_been_made + end + + it "should return information about a snippet award emoji" do + expect(@emoji.id).to eq(4) + expect(@emoji.awardable_type).to eq("Snippet") + expect(@emoji.awardable_id).to eq(80) + end + end + end + + describe '.note_award_emoji' do + context 'when issue note award emoji' do + before do + stub_get("/projects/1/issues/80/notes/1/award_emoji/4", "note_award_emoji") + @note_emoji = Gitlab.note_award_emoji(1, 80, 'issue', 1, 4) + end + + it "should get the correct resource" do + expect(a_get("/projects/1/issues/80/notes/1/award_emoji/4")).to have_been_made + end + + it "should return information about an issue note award emoji" do + expect(@note_emoji.id).to eq(4) + expect(@note_emoji.awardable_type).to eq("Note") + expect(@note_emoji.awardable_id).to eq(1) + end + end + + context 'when merge request note award emoji' do + before do + stub_get("/projects/1/merge_requests/80/notes/1/award_emoji/4", "note_award_emoji") + @note_emoji = Gitlab.note_award_emoji(1, 80, 'merge_request', 1, 4) + end + + it "should get the correct resource" do + expect(a_get("/projects/1/merge_requests/80/notes/1/award_emoji/4")).to have_been_made + end + + it "should return information about a merge request note award emoji" do + expect(@note_emoji.id).to eq(4) + expect(@note_emoji.awardable_type).to eq("Note") + expect(@note_emoji.awardable_id).to eq(1) + end + end + + context 'when snippet note award emoji' do + before do + stub_get("/projects/1/snippets/80/notes/1/award_emoji/4", "note_award_emoji") + @note_emoji = Gitlab.note_award_emoji(1, 80, 'snippet', 1, 4) + end + + it "should get the correct resource" do + expect(a_get("/projects/1/snippets/80/notes/1/award_emoji/4")).to have_been_made + end + + it "should return information about a snippet note award emoji" do + expect(@note_emoji.id).to eq(4) + expect(@note_emoji.awardable_type).to eq("Note") + expect(@note_emoji.awardable_id).to eq(1) + end + end + end + + describe '.create_award_emoji' do + context 'when issue award emoji' do + before do + stub_post("/projects/1/issues/80/award_emoji", "issue_award_emoji") + @emoji = Gitlab.create_award_emoji(1, 80, "issue", "blowfish") + end + + it "should get the correct resource" do + expect(a_post("/projects/1/issues/80/award_emoji"). + with(body: { name: 'blowfish' })).to have_been_made + end + + it "should return correct information about the created issue award emoji" do + expect(@emoji.name).to eq('blowfish') + expect(@emoji.awardable_type).to eq('Issue') + end + end + + context 'when merge request award emoji' do + before do + stub_post("/projects/1/merge_requests/80/award_emoji", "merge_request_award_emoji") + @emoji = Gitlab.create_award_emoji(1, 80, "merge_request", "blowfish") + end + + it "should get the correct resource" do + expect(a_post("/projects/1/merge_requests/80/award_emoji"). + with(body: { name: 'blowfish' })).to have_been_made + end + + it "should return correct information about the created merge request award emoji" do + expect(@emoji.name).to eq('blowfish') + expect(@emoji.awardable_type).to eq('MergeRequest') + end + end + + context 'when snippet award emoji' do + before do + stub_post("/projects/1/snippets/80/award_emoji", "snippet_award_emoji") + @emoji = Gitlab.create_award_emoji(1, 80, "snippet", "blowfish") + end + + it "should get the correct resource" do + expect(a_post("/projects/1/snippets/80/award_emoji"). + with(body: { name: 'blowfish' })).to have_been_made + end + + it "should return correct information about the created snippet award emoji" do + expect(@emoji.name).to eq('blowfish') + expect(@emoji.awardable_type).to eq('Snippet') + end + end + end + + describe '.create_note_award_emoji' do + context 'when issue note award emoji' do + before do + stub_post("/projects/1/issues/80/notes/1/award_emoji", "note_award_emoji") + @note_emoji = Gitlab.create_note_award_emoji(1, 80, "issue", 1, "mood_bubble_lightning") + end + + it "should get the correct resource" do + expect(a_post("/projects/1/issues/80/notes/1/award_emoji"). + with(body: { name: 'mood_bubble_lightning' })).to have_been_made + end + + it "should return correct information about the created issue note award emoji" do + expect(@note_emoji.name).to eq('mood_bubble_lightning') + expect(@note_emoji.awardable_type).to eq('Note') + end + end + + context 'when merge request note award emoji' do + before do + stub_post("/projects/1/merge_requests/80/notes/1/award_emoji", "note_award_emoji") + @note_emoji = Gitlab.create_note_award_emoji(1, 80, "merge_request", 1, "mood_bubble_lightning") + end + + it "should get the correct resource" do + expect(a_post("/projects/1/merge_requests/80/notes/1/award_emoji"). + with(body: { name: 'mood_bubble_lightning' })).to have_been_made + end + + it "should return correct information about the created merge request note award emoji" do + expect(@note_emoji.name).to eq('mood_bubble_lightning') + expect(@note_emoji.awardable_type).to eq('Note') + end + end + + context 'when snippet note award emoji' do + before do + stub_post("/projects/1/snippets/80/notes/1/award_emoji", "note_award_emoji") + @note_emoji = Gitlab.create_note_award_emoji(1, 80, "snippet", 1, "mood_bubble_lightning") + end + + it "should get the correct resource" do + expect(a_post("/projects/1/snippets/80/notes/1/award_emoji"). + with(body: { name: 'mood_bubble_lightning' })).to have_been_made + end + + it "should return correct information about the created snippet note award emoji" do + expect(@note_emoji.name).to eq('mood_bubble_lightning') + expect(@note_emoji.awardable_type).to eq('Note') + end + end + end + + describe '.delete_award_emoji' do + context 'when issue award emoji' do + before do + stub_delete("/projects/1/issues/80/award_emoji/4", "issue_award_emoji") + @emoji = Gitlab.delete_award_emoji(1, 80, "issue", 4) + end + + it "should get the correct resource" do + expect(a_delete("/projects/1/issues/80/award_emoji/4")).to have_been_made + end + end + + context 'when merge request award emoji' do + before do + stub_delete("/projects/1/merge_requests/80/award_emoji/4", "merge_request_award_emoji") + @emoji = Gitlab.delete_award_emoji(1, 80, "merge_request", 4) + end + + it "should get the correct resource" do + expect(a_delete("/projects/1/merge_requests/80/award_emoji/4")).to have_been_made + end + end + + context 'when snippet award emoji' do + before do + stub_delete("/projects/1/snippets/80/award_emoji/4", "snippet_award_emoji") + @emoji = Gitlab.delete_award_emoji(1, 80, "snippet", 4) + end + + it "should get the correct resource" do + expect(a_delete("/projects/1/snippets/80/award_emoji/4")).to have_been_made + end + end + end + + describe '.delete_note_award_emoji' do + context 'when issue note award emoji' do + before do + stub_delete("/projects/1/issues/80/notes/1/award_emoji/4", "note_award_emoji") + @note_emoji = Gitlab.delete_note_award_emoji(1, 80, "issue", 1, 4) + end + + it "should get the correct resource" do + expect(a_delete("/projects/1/issues/80/notes/1/award_emoji/4")).to have_been_made + end + end + + context 'when merge request note award emoji' do + before do + stub_delete("/projects/1/merge_requests/80/notes/1/award_emoji/4", "note_award_emoji") + @note_emoji = Gitlab.delete_note_award_emoji(1, 80, "merge_request", 1, 4) + end + + it "should get the correct resource" do + expect(a_delete("/projects/1/merge_requests/80/notes/1/award_emoji/4")).to have_been_made + end + end + + context 'when snippet note award emoji' do + before do + stub_delete("/projects/1/snippets/80/notes/1/award_emoji/4", "note_award_emoji") + @note_emoji = Gitlab.delete_note_award_emoji(1, 80, "snippet", 1, 4) + end + + it "should get the correct resource" do + expect(a_delete("/projects/1/snippets/80/notes/1/award_emoji/4")).to have_been_made + end + end + end +end \ No newline at end of file diff --git a/spec/gitlab/client/boards_spec.rb b/spec/gitlab/client/boards_spec.rb new file mode 100644 index 0000000..7eb86b1 --- /dev/null +++ b/spec/gitlab/client/boards_spec.rb @@ -0,0 +1,94 @@ +require 'spec_helper' + +describe Gitlab::Client do + describe ".boards" do + before do + stub_get("/projects/3/boards", "boards") + @boards = Gitlab.boards(3) + end + + it "should get the correct resource" do + expect(a_get("/projects/3/boards")).to have_been_made + end + + it "should return a paginated response of project's boards" do + expect(@boards).to be_a Gitlab::PaginatedResponse + end + end + + describe ".board_lists" do + before do + stub_get("/projects/3/boards/1/lists", "board_lists") + @board_lists = Gitlab.board_lists(3, 1) + end + + it "should get the correct resource" do + expect(a_get("/projects/3/boards/1/lists")).to have_been_made + end + + it "should return a paginated response of board's lists" do + expect(@board_lists).to be_a Gitlab::PaginatedResponse + expect(@board_lists.first.id).to eq(1) + end + end + + describe ".board_list" do + before do + stub_get("/projects/3/boards/1/lists/1", "board_list") + @board_list = Gitlab.board_list(3, 1, 1) + end + + it "should get the correct resource" do + expect(a_get("/projects/3/boards/1/lists/1")).to have_been_made + end + + it "should return information about the list" do + expect(@board_list.id).to eq(1) + end + end + + describe ".create_board_list" do + before do + stub_post("/projects/3/boards/1/lists", "board_list") + @board_list = Gitlab.create_board_list(3, 1, 4) + end + + it "should get the correct resource" do + expect(a_post("/projects/3/boards/1/lists")).to have_been_made + end + + it "should return information about a created board" do + expect(@board_list.position).to eq(1) + end + end + + describe ".edit_board_list" do + before do + stub_put("/projects/3/boards/1/lists/1", "board_list") + @board_list = Gitlab.edit_board_list(3, 1, 1, 3) + end + + it "should get the correct resource" do + expect(a_put("/projects/3/boards/1/lists/1")).to have_been_made + end + + it "should return information about an edited board" do + expect(@board_list.id).to eq(1) + end + end + + describe ".delete_board_list" do + before do + stub_delete("/projects/3/boards/1/lists/1", "board_list") + @board_list = Gitlab.delete_board_list(3, 1, 1) + end + + it "should get the correct resource" do + expect(a_delete("/projects/3/boards/1/lists/1")).to have_been_made + end + + it "should return information about the deleted board list" do + expect(@board_list.id).to eq(1) + end + end +end diff --git a/spec/gitlab/client/branches_spec.rb b/spec/gitlab/client/branches_spec.rb index 751bb6a..b21e08a 100644 --- a/spec/gitlab/client/branches_spec.rb +++ b/spec/gitlab/client/branches_spec.rb @@ -40,15 +40,32 @@ describe ".protect_branch" do before do stub_put("/projects/3/repository/branches/api/protect", "branch") - @branch = Gitlab.protect_branch(3, "api") end - it "should get the correct resource" do - expect(a_put("/projects/3/repository/branches/api/protect")).to have_been_made + context "without options" do + before do + @branch = Gitlab.protect_branch(3, "api") + end + + it "should update the correct resource" do + expect(a_put("/projects/3/repository/branches/api/protect")).to have_been_made + end + + it "should return information about a protected repository branch" do + expect(@branch.name).to eq("api") + end end - it "should return information about a protected repository branch" do - expect(@branch.name).to eq("api") + context "with options" do + before do + @branch = Gitlab.protect_branch(3, "api", developers_can_push: true) + end + + it "should update the correct resource with the correct options" do + expect( + a_put("/projects/3/repository/branches/api/protect").with(body: { developers_can_push: 'true' }) + ).to have_been_made + end end end diff --git a/spec/gitlab/client/commits_spec.rb b/spec/gitlab/client/commits_spec.rb index a474efc..595304a 100644 --- a/spec/gitlab/client/commits_spec.rb +++ b/spec/gitlab/client/commits_spec.rb @@ -148,7 +148,7 @@ let(:query) do { - branch_name: 'dev', + branch: 'dev', commit_message: 'refactors everything', actions: actions, author_email: 'joe@sample.org', @@ -157,7 +157,7 @@ end before do - stub_post("/projects/6/repository/commits", 'project_commit_create').with(query: query) + stub_post("/projects/6/repository/commits", 'project_commit_create').with(body: query) @commit = Gitlab.create_commit(6, 'dev', 'refactors everything', actions, {author_email: 'joe@sample.org', author_name: 'Joe Sample'}) end diff --git a/spec/gitlab/client/environments_spec.rb b/spec/gitlab/client/environments_spec.rb new file mode 100644 index 0000000..3e10b96 --- /dev/null +++ b/spec/gitlab/client/environments_spec.rb @@ -0,0 +1,132 @@ +require 'spec_helper' + +describe Gitlab::Client do + describe ".environments" do + before do + stub_get("/projects/3/environments", "environments") + @environments = Gitlab.environments(3) + end + + it "should get the correct resource" do + expect(a_get("/projects/3/environments")).to have_been_made + end + + it "should return a paginated response of project's environments" do + expect(@environments).to be_a Gitlab::PaginatedResponse + end + end + + describe ".environment" do + before do + stub_get("/projects/3/environments/12", "environment") + @environment = Gitlab.environment(3, 12) + end + + it "should get the correct resource" do + expect(a_get("/projects/3/environments/12")).to have_been_made + end + + it "should return a single environment" do + expect(@environment).to be_a Gitlab::ObjectifiedHash + end + + it "should return information about an environment" do + expect(@environment.id).to eq(12) + expect(@environment.name).to eq("staging") + end + end + + describe ".create_environment" do + context "without external_url" do + before do + stub_post("/projects/3/environments", "environment") + @environment = Gitlab.create_environment(3, 'staging') + end + + it "should get the correct resource" do + expect(a_post("/projects/3/environments").with(body: { name: 'staging' })).to have_been_made + end + + it "should return a single environment" do + expect(@environment).to be_a Gitlab::ObjectifiedHash + end + + it "should return information about an environment" do + expect(@environment.name).to eq("staging") + end + end + + context "with external_url" do + before do + stub_post("/projects/3/environments", "environment") + @environment = Gitlab.create_environment(3, 'staging', external_url: "https://staging.example.gitlab.com") + end + + it "should get the correct resource" do + expect(a_post("/projects/3/environments") + .with(body: { name: 'staging', external_url: "https://staging.example.gitlab.com" })).to have_been_made + end + end + end + + describe ".edit_environment" do + before do + stub_put("/projects/3/environments/12", "environment") + @environment = Gitlab.edit_environment(3, 12, { + name: 'staging', + external_url: "https://staging.example.gitlab.com" + }) + end + + it "should get the correct resource" do + expect(a_put("/projects/3/environments/12") + .with(body: { name: 'staging', external_url: "https://staging.example.gitlab.com" })).to have_been_made + end + + it "should return a single environment" do + expect(@environment).to be_a Gitlab::ObjectifiedHash + end + + it "should return information about an environment" do + expect(@environment.name).to eq("staging") + end + end + + describe ".delete_environment" do + before do + stub_delete("/projects/3/environments/12", "environment") + @environment = Gitlab.delete_environment(3, 12) + end + + it "should get the correct resource" do + expect(a_delete("/projects/3/environments/12")).to have_been_made + end + + it "should return a single pipeline" do + expect(@environment).to be_a Gitlab::ObjectifiedHash + end + + it "should return information about a pipeline" do + expect(@environment.name).to eq("staging") + end + end + + describe ".stop_environment" do + before do + stub_post("/projects/3/environments/12/stop", "environment") + @environment = Gitlab.stop_environment(3, 12) + end + + it "should get the correct resource" do + expect(a_post("/projects/3/environments/12/stop")).to have_been_made + end + + it "should return a single pipeline" do + expect(@environment).to be_a Gitlab::ObjectifiedHash + end + + it "should return information about a pipeline" do + expect(@environment.name).to eq("staging") + end + end +end diff --git a/spec/gitlab/client/groups_spec.rb b/spec/gitlab/client/groups_spec.rb index c1d069e..4ae039c 100644 --- a/spec/gitlab/client/groups_spec.rb +++ b/spec/gitlab/client/groups_spec.rb @@ -59,20 +59,18 @@ end describe ".delete_group" do - context "without description" do - before do - stub_delete("/groups/42", "group_delete") - @group = Gitlab.delete_group(42) - end + before do + stub_delete("/groups/42", "group_delete") + @group = Gitlab.delete_group(42) + end - it "should get the correct resource" do - expect(a_delete("/groups/42")).to have_been_made - end + it "should get the correct resource" do + expect(a_delete("/groups/42")).to have_been_made + end - it "should return information about a deleted group" do - expect(@group.name).to eq("Gitlab-Group") - expect(@group.path).to eq("gitlab-group") - end + it "should return information about a deleted group" do + expect(@group.name).to eq("Gitlab-Group") + expect(@group.path).to eq("gitlab-group") end end diff --git a/spec/gitlab/client/labels_spec.rb b/spec/gitlab/client/labels_spec.rb index 9c14bf2..42ec4ec 100644 --- a/spec/gitlab/client/labels_spec.rb +++ b/spec/gitlab/client/labels_spec.rb @@ -65,4 +65,36 @@ expect(@label.color).to eq('#DD10AA') end end + + describe ".subscribe_to_label" do + before do + stub_post("/projects/3/labels/Backlog/subscribe", "label") + @label = Gitlab.subscribe_to_label(3, 'Backlog') + end + + it "should get the correct resource" do + expect(a_post("/projects/3/labels/Backlog/subscribe")).to have_been_made + end + + it "should return information about the label subscribed to" do + expect(@label.name).to eq('Backlog') + expect(@label.subscribed).to eq(true) + end + end + + describe ".unsubscribe_from_label" do + before do + stub_post("/projects/3/labels/Backlog/unsubscribe", "label_unsubscribe") + @label = Gitlab.unsubscribe_from_label(3, 'Backlog') + end + + it "should get the correct resource" do + expect(a_post("/projects/3/labels/Backlog/unsubscribe")).to have_been_made + end + + it "should return information about the label subscribed to" do + expect(@label.name).to eq('Backlog') + expect(@label.subscribed).to eq(false) + end + end end diff --git a/spec/gitlab/client/notes_spec.rb b/spec/gitlab/client/notes_spec.rb index b8557db..0aab9ed 100644 --- a/spec/gitlab/client/notes_spec.rb +++ b/spec/gitlab/client/notes_spec.rb @@ -202,4 +202,132 @@ end end end + + describe "delete note" do + context "when wall note" do + before do + stub_delete("/projects/3/notes/1201", "note") + @note = Gitlab.delete_note(3, 1201) + end + + it "should get the correct resource" do + expect(a_delete("/projects/3/notes/1201")).to have_been_made + end + + it "should return information about a deleted note" do + expect(@note.id).to eq(1201) + end + end + + context "when issue note" do + before do + stub_delete("/projects/3/issues/7/notes/1201", "note") + @note = Gitlab.delete_issue_note(3, 7, 1201) + end + + it "should get the correct resource" do + expect(a_delete("/projects/3/issues/7/notes/1201")).to have_been_made + end + + it "should return information about a deleted issue note" do + expect(@note.id).to eq(1201) + end + end + + context "when snippet note" do + before do + stub_delete("/projects/3/snippets/7/notes/1201", "note") + @note = Gitlab.delete_snippet_note(3, 7, 1201) + end + + it "should get the correct resource" do + expect(a_delete("/projects/3/snippets/7/notes/1201")).to have_been_made + end + + it "should return information about a deleted snippet note" do + expect(@note.id).to eq(1201) + end + end + + context "when merge request note" do + before do + stub_delete("/projects/3/merge_requests/7/notes/1201", "note") + @note = Gitlab.delete_merge_request_note(3, 7, 1201) + end + + it "should get the correct resource" do + expect(a_delete("/projects/3/merge_requests/7/notes/1201")).to have_been_made + end + + it "should return information about a deleted merge request note" do + expect(@note.id).to eq(1201) + end + end + end + + describe "modify note" do + context "when wall note" do + before do + stub_put("/projects/3/notes/1201", "note") + @note = Gitlab.edit_note(3, 1201, body: "edited wall note content") + end + + it "should get the correct resource" do + expect(a_put("/projects/3/notes/1201"). + with(body: {body: 'edited wall note content'})).to have_been_made + end + + it "should return information about a modified note" do + expect(@note.id).to eq(1201) + end + end + + context "when issue note" do + before do + stub_put("/projects/3/issues/7/notes/1201", "note") + @note = Gitlab.edit_issue_note(3, 7, 1201, body: "edited issue note content") + end + + it "should get the correct resource" do + expect(a_put("/projects/3/issues/7/notes/1201"). + with(body: {body: 'edited issue note content'})).to have_been_made + end + + it "should return information about a modified issue note" do + expect(@note.id).to eq(1201) + end + end + + context "when snippet note" do + before do + stub_put("/projects/3/snippets/7/notes/1201", "note") + @note = Gitlab.edit_snippet_note(3, 7, 1201, body: "edited snippet note content") + end + + it "should get the correct resource" do + expect(a_put("/projects/3/snippets/7/notes/1201"). + with(body: {body: 'edited snippet note content'})).to have_been_made + end + + it "should return information about a modified snippet note" do + expect(@note.id).to eq(1201) + end + end + + context "when merge request note" do + before do + stub_put("/projects/3/merge_requests/7/notes/1201", "note") + @note = Gitlab.edit_merge_request_note(3, 7, 1201, body: "edited merge request note content") + end + + it "should get the correct resource" do + expect(a_put("/projects/3/merge_requests/7/notes/1201"). + with(body: {body: 'edited merge request note content'})).to have_been_made + end + + it "should return information about a modified request note" do + expect(@note.id).to eq(1201) + end + end + end end diff --git a/spec/gitlab/client/projects_spec.rb b/spec/gitlab/client/projects_spec.rb index d2c6e47..fea9198 100644 --- a/spec/gitlab/client/projects_spec.rb +++ b/spec/gitlab/client/projects_spec.rb @@ -22,12 +22,12 @@ describe ".project_search" do before do - stub_get("/projects/search/Gitlab", "project_search") + stub_get("/projects?search=Gitlab", "project_search") @project_search = Gitlab.project_search("Gitlab") end it "should get the correct resource" do - expect(a_get("/projects/search/Gitlab")).to have_been_made + expect(a_get("/projects?search=Gitlab")).to have_been_made end it "should return a paginated response of projects found" do @@ -315,17 +315,27 @@ end describe ".edit_project" do - before do - stub_put("/projects/3", "project_edit").with(query: { name: "Gitlab-edit" }) - @edited_project = Gitlab.edit_project(3, name: "Gitlab-edit") - end - - it "should get the correct resource" do - expect(a_put("/projects/3").with(query: { name: "Gitlab-edit" })).to have_been_made - end - - it "should return information about an edited project" do - expect(@edited_project.name).to eq("Gitlab-edit") + context "using project ID" do + before do + stub_put("/projects/3", "project_edit").with(body: { name: "Gitlab-edit" }) + @edited_project = Gitlab.edit_project(3, name: "Gitlab-edit") + end + + it "should get the correct resource" do + expect(a_put("/projects/3").with(body: { name: "Gitlab-edit" })).to have_been_made + end + + it "should return information about an edited project" do + expect(@edited_project.name).to eq("Gitlab-edit") + end + end + + context "using namespaced project path" do + it "encodes the path properly" do + stub = stub_put("/projects/namespace%2Fpath", "project_edit").with(body: { name: "Gitlab-edit" }) + Gitlab.edit_project('namespace/path', name: "Gitlab-edit") + expect(stub).to have_been_requested + end end end diff --git a/spec/gitlab/client/repository_files_spec.rb b/spec/gitlab/client/repository_files_spec.rb index 6900884..1b89313 100644 --- a/spec/gitlab/client/repository_files_spec.rb +++ b/spec/gitlab/client/repository_files_spec.rb @@ -22,7 +22,7 @@ @file = Gitlab.get_file(3, 'README.md', 'master') end - it "should create the correct resource" do + it "should get the correct resource" do expect(a_get("/projects/3/repository/files/README%2Emd?ref=master")).to have_been_made end @@ -34,11 +34,17 @@ end describe ".create_file" do - let!(:request_stub) { stub_post("/projects/3/repository/files", "repository_file") } - let!(:file) { Gitlab.create_file(3, "path", "branch", "content", "commit message") } + let(:api_path) { "/projects/3/repository/files/path" } + let!(:request_stub) { stub_post(api_path, "repository_file") } + let!(:file) { Gitlab.create_file(3, "path", "branch", "content", "commit message", author_name: "joe") } it "should create the correct resource" do - expect(request_stub).to have_been_made + expected_parameters = { + author_name: "joe", + branch: "branch", + commit_message: "commit message" + } + expect(a_post(api_path).with(body: hash_including(expected_parameters))).to have_been_made end it "should return information about the new file" do @@ -48,11 +54,17 @@ end describe ".edit_file" do - let!(:request_stub) { stub_put("/projects/3/repository/files", "repository_file") } - let!(:file) { Gitlab.edit_file(3, "path", "branch", "content", "commit message") } + let(:api_path) { "/projects/3/repository/files/path" } + let!(:request_stub) { stub_put(api_path, "repository_file") } + let!(:file) { Gitlab.edit_file(3, "path", "branch", "content", "commit message", author_name: "joe") } - it "should create the correct resource" do - expect(request_stub).to have_been_made + it "should update the correct resource" do + expected_parameters = { + author_name: "joe", + branch: "branch", + commit_message: "commit message" + } + expect(a_put(api_path).with(body: hash_including(expected_parameters))).to have_been_made end it "should return information about the new file" do @@ -62,11 +74,17 @@ end describe ".remove_file" do - let!(:request_stub) { stub_delete("/projects/3/repository/files", "repository_file") } - let!(:file) { Gitlab.remove_file(3, "path", "branch", "commit message") } + let(:api_path) { "/projects/3/repository/files/path" } + let!(:request_stub) { stub_delete(api_path, "repository_file") } + let!(:file) { Gitlab.remove_file(3, "path", "branch", "commit message", author_name: "joe") } - it "should create the correct resource" do - expect(request_stub).to have_been_made + it "should update the correct resource" do + expected_parameters = { + author_name: "joe", + branch: "branch", + commit_message: "commit message" + } + expect(a_delete(api_path).with(body: hash_including(expected_parameters))).to have_been_made end it "should return information about the new file" do diff --git a/spec/gitlab/client/system_hooks_spec.rb b/spec/gitlab/client/system_hooks_spec.rb index e808435..ce32eab 100644 --- a/spec/gitlab/client/system_hooks_spec.rb +++ b/spec/gitlab/client/system_hooks_spec.rb @@ -25,11 +25,11 @@ describe ".add_hook" do before do stub_post("/hooks", "system_hook") - @hook = Gitlab.add_hook("http://example.com/hook") + @hook = Gitlab.add_hook("http://example.com/hook", token: 'secret-token') end it "should get the correct resource" do - expect(a_post("/hooks")).to have_been_made + expect(a_post("/hooks").with(body: hash_including(token: 'secret-token'))).to have_been_made end it "should return information about a added system hook" do diff --git a/spec/gitlab/client/todos_spec.rb b/spec/gitlab/client/todos_spec.rb new file mode 100644 index 0000000..92ebd5a --- /dev/null +++ b/spec/gitlab/client/todos_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe Gitlab::Client do + describe '.todos' do + before do + stub_get("/todos", "todos") + @todos = Gitlab.todos + end + + it "should get the correct resources" do + expect(a_get("/todos")).to have_been_made + end + + it "should return a paginated response of user's todos" do + expect(@todos).to be_a Gitlab::PaginatedResponse + end + end + + describe '.mark_todo_as_done' do + before do + stub_post("/todos/102/mark_as_done", "todo") + @todo = Gitlab.mark_todo_as_done(102) + end + + it "should get the correct resource" do + expect(a_post("/todos/102/mark_as_done")).to have_been_made + end + + it "should return information about the todo marked as done" do + expect(@todo.id).to eq(102) + expect(@todo.state).to eq('done') + end + end + + describe '.mark_all_todos_as_done' do + before do + stub_post("/todos/mark_as_done", "todos") + @todos = Gitlab.mark_all_todos_as_done + end + + it "should get the correct resources" do + expect(a_post("/todos/mark_as_done")).to have_been_made + end + end +end \ No newline at end of file