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

Feature : Resource State Events API Addition #580

Merged
merged 6 commits into from
Sep 1, 2020
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
1 change: 1 addition & 0 deletions lib/gitlab/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Client < API
include RepositoryFiles
include RepositorySubmodules
include ResourceLabelEvents
include ResourceStateEvents
include Runners
include Search
include Services
Expand Down
57 changes: 57 additions & 0 deletions lib/gitlab/client/resource_state_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

class Gitlab::Client
# Defines methods related to resource state events.
# @see https://docs.gitlab.com/ee/api/resource_state_events.html
module ResourceStateEvents
# Gets a list of all state events for a single issue.
#
# @example
# Gitlab.issue_state_events(5, 42)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] issue_iid The IID of an issue.
# @return [Array<Gitlab::ObjectifiedHash>]
def issue_state_events(project, issue_iid)
get("/projects/#{url_encode project}/issues/#{issue_iid}/resource_state_events")
end

# Returns a single state event for a specific project issue
#
# @example
# Gitlab.issue_state_event(5, 42, 1)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] issue_iid The IID of an issue.
# @param [Integer] id The ID of a resource event.
# @return Gitlab::ObjectifiedHash
def issue_state_event(project, issue_iid, id)
get("/projects/#{url_encode project}/issues/#{issue_iid}/resource_state_events/#{id}")
end

# Gets a list of all state events for a single merge request.
#
# @example
# Gitlab.merge_request_state_events(5, 42)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] merge_request_iid The IID of a merge request.
# @return [Array<Gitlab::ObjectifiedHash>]
def merge_request_state_events(project, merge_request_iid)
get("/projects/#{url_encode project}/merge_requests/#{merge_request_iid}/resource_state_events")
end

# Returns a single state event for a specific project merge request
#
# @example
# Gitlab.merge_request_state_event(5, 42, 1)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] merge_request_iid The IID of an merge request.
# @param [Integer] id The ID of a state event.
# @return Gitlab::ObjectifiedHash
def merge_request_state_event(project, merge_request_iid, id)
get("/projects/#{url_encode project}/merge_requests/#{merge_request_iid}/resource_state_events/#{id}")
end
end
end
15 changes: 15 additions & 0 deletions spec/fixtures/issue_resource_state_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": 143,
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.example.com/root"
},
"created_at": "2018-08-21T14:38:20.077Z",
"resource_type": "Issue",
"resource_id": 11,
"state": "closed"
}
32 changes: 32 additions & 0 deletions spec/fixtures/issue_resource_state_events.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"id": 142,
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.example.com/root"
},
"created_at": "2018-08-20T13:38:20.077Z",
"resource_type": "Issue",
"resource_id": 11,
"state": "opened"
},
{
"id": 143,
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.example.com/root"
},
"created_at": "2018-08-21T14:38:20.077Z",
"resource_type": "Issue",
"resource_id": 11,
"state": "closed"
}
]
15 changes: 15 additions & 0 deletions spec/fixtures/mr_resource_state_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": 120,
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.example.com/root"
},
"created_at": "2018-08-21T14:38:20.077Z",
"resource_type": "MergeRequest",
"resource_id": 11,
"state": "closed"
}
32 changes: 32 additions & 0 deletions spec/fixtures/mr_resource_state_events.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"id": 142,
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.example.com/root"
},
"created_at": "2018-08-20T13:38:20.077Z",
"resource_type": "MergeRequest",
"resource_id": 11,
"state": "opened"
},
{
"id": 143,
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.example.com/root"
},
"created_at": "2018-08-21T14:38:20.077Z",
"resource_type": "MergeRequest",
"resource_id": 11,
"state": "closed"
}
]
69 changes: 69 additions & 0 deletions spec/gitlab/client/resource_state_events_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::Client do
describe '.issue_state_events' do
before do
stub_get('/projects/5/issues/42/resource_state_events', 'issue_resource_state_events')
@events = Gitlab.issue_state_events(5, 42)
end

it 'gets the correct resource' do
expect(a_get('/projects/5/issues/42/resource_state_events')).to have_been_made
end

it "returns a paginated response of project's issue's state events" do
expect(@events).to be_a Gitlab::PaginatedResponse
expect(@events.first.id).to eq(142)
end
end

describe '.issue_state_event' do
before do
stub_get('/projects/5/issues/42/resource_state_events/142', 'issue_resource_state_event')
@event = Gitlab.issue_state_event(5, 42, 142)
end

it 'gets the correct resource' do
expect(a_get('/projects/5/issues/42/resource_state_events/142')).to have_been_made
end

it "returns a paginated response of project's issue's state event" do
expect(@event).to be_a Gitlab::ObjectifiedHash
expect(@event.user.name).to eq('Administrator')
end
end

describe '.merge_request_state_events' do
before do
stub_get('/projects/5/merge_requests/42/resource_state_events', 'mr_resource_state_events')
@events = Gitlab.merge_request_state_events(5, 42)
end

it 'gets the correct resource' do
expect(a_get('/projects/5/merge_requests/42/resource_state_events')).to have_been_made
end

it "returns a paginated response of project's merge request's state events" do
expect(@events).to be_a Gitlab::PaginatedResponse
expect(@events.first.id).to eq(142)
end
end

describe '.merge_request_state_event' do
before do
stub_get('/projects/5/merge_requests/42/resource_state_events/142', 'mr_resource_state_event')
@event = Gitlab.merge_request_state_event(5, 42, 142)
end

it 'gets the correct resource' do
expect(a_get('/projects/5/merge_requests/42/resource_state_events/142')).to have_been_made
end

it "returns a paginated response of project's merge request's state event" do
expect(@event).to be_a Gitlab::ObjectifiedHash
expect(@event.user.name).to eq('Administrator')
end
end
end
2 changes: 1 addition & 1 deletion spec/gitlab/shell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
it 'returns an Array of matching commands' do
completed_cmds = @comp.call 'issue'
expect(completed_cmds).to be_a Array
expect(completed_cmds.sort).to eq(%w[issue issue_label_event issue_label_events issue_links issue_note issue_notes issues])
expect(completed_cmds.sort).to eq(%w[issue issue_label_event issue_label_events issue_links issue_note issue_notes issue_state_event issue_state_events issues])
end
end
end
Expand Down