Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Un)subscribe to issues and merge_requests #260

Merged
merged 4 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- Add method `share_project_with_group` (@danhalligan)
- Allow to retrieve `ssh_keys` for a specific user(@dirker)
- Allow issues to use NAMESPACE/REPO identifier (@brodock)
- Add issues subscribe/unsubscribe (@newellista)
- Add merge_requests subscribe/unsubscribe (@newellista)

### 3.7.0 (16/08/2016)

Expand Down
24 changes: 24 additions & 0 deletions lib/gitlab/client/issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ def reopen_issue(project, id)
put("/projects/#{url_encode project}/issues/#{id}", body: { state_event: 'reopen' })
end

# Subscribe to an issue.
#
# @example
# Gitlab.subscribe_to_issue(3, 42)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] id The ID of an issue.
# @return [Gitlab::ObjectifiedHash] Information about subscribed issue.
def subscribe_to_issue(project, id)
post("/projects/#{url_encode project}/issues/#{id}/subscribe")
end

# Unsubscribe from an issue.
#
# @example
# Gitlab.unsubscribe_from_issue(3, 42)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] id The ID of an issue.
# @return [Gitlab::ObjectifiedHash] Information about unsubscribed issue.
def unsubscribe_from_issue(project, id)
post("/projects/#{url_encode project}/issues/#{id}/unsubscribe")
end

# Deletes an issue.
# Only for admins and project owners
#
Expand Down
26 changes: 26 additions & 0 deletions lib/gitlab/client/merge_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,31 @@ def merge_request_changes(project, id)
def merge_request_commits(project, id)
get("/projects/#{url_encode project}/merge_requests/#{id}/commits")
end

# Subscribes to a merge request.
#
# @example
# Gitlab.subscribe_to_merge_request(5, 1)
# Gitlab.subscribe_to_merge_request('gitlab', 1)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] id The ID of a merge request.
# @return [Gitlab::ObjectifiedHash] Information about subscribed merge request.
def subscribe_to_merge_request(project, id)
post("/projects/#{url_encode project}/merge_requests/#{id}/subscribe")
end

# Unsubscribes from a merge request.
#
# @example
# Gitlab.unsubscribe_from_merge_request(5, 1)
# Gitlab.unsubscribe_from_merge_request('gitlab', 1)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] id The ID of a merge request.
# @return [Gitlab::ObjectifiedHash] Information about unsubscribed merge request.
def unsubscribe_from_merge_request(project, id)
post("/projects/#{url_encode project}/merge_requests/#{id}/unsubscribe")
end
end
end
32 changes: 32 additions & 0 deletions spec/gitlab/client/issues_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,38 @@
end
end

describe ".subscribe_to_issue" do
before do
stub_post("/projects/3/issues/33/subscribe", "issue")
@issue = Gitlab.subscribe_to_issue(3, 33)
end

it "should get the correct resource" do
expect(a_post("/projects/3/issues/33/subscribe")).to have_been_made
end

it "should return information about the subscribed issue" do
expect(@issue.project_id).to eq(3)
expect(@issue.assignee.name).to eq("Jack Smith")
end
end

describe ".unsubscribe_from_issue" do
before do
stub_post("/projects/3/issues/33/unsubscribe", "issue")
@issue = Gitlab.unsubscribe_from_issue(3, 33)
end

it "should get the correct resource" do
expect(a_post("/projects/3/issues/33/unsubscribe")).to have_been_made
end

it "should return information about the unsubscribed issue" do
expect(@issue.project_id).to eq(3)
expect(@issue.assignee.name).to eq("Jack Smith")
end
end

describe ".delete_issue" do
before do
stub_delete("/projects/3/issues/33", "issue")
Expand Down
30 changes: 30 additions & 0 deletions spec/gitlab/client/merge_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,34 @@
expect(@mr_commits[1].title).to eq "hoge"
end
end

describe ".subscribe_to_merge_request" do
before do
stub_post("/projects/3/merge_requests/2/subscribe", "merge_request")
@merge_request = Gitlab.subscribe_to_merge_request(3, 2)
end

it "should get the correct resource" do
expect(a_post("/projects/3/merge_requests/2/subscribe")).to have_been_made
end

it "should return information about a merge request" do
expect(@merge_request.project_id).to eq(3)
end
end

describe ".unsubscribe_from_merge_request" do
before do
stub_post("/projects/3/merge_requests/2/unsubscribe", "merge_request")
@merge_request = Gitlab.unsubscribe_from_merge_request(3, 2)
end

it "should get the correct resource" do
expect(a_post("/projects/3/merge_requests/2/unsubscribe")).to have_been_made
end

it "should return information about a merge request" do
expect(@merge_request.project_id).to eq(3)
end
end
end