Skip to content

Commit

Permalink
Merge pull request #427 from jcouball/issue_resolution
Browse files Browse the repository at this point in the history
Add Issue#resolution relationship
  • Loading branch information
bobbrodie authored Apr 26, 2024
2 parents c80cfb3 + 83a1f23 commit c4bdc10
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 14 deletions.
3 changes: 2 additions & 1 deletion lib/jira-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require 'jira/resource/issuetype'
require 'jira/resource/version'
require 'jira/resource/status'
require 'jira/resource/status_category'
require 'jira/resource/transition'
require 'jira/resource/project'
require 'jira/resource/priority'
Expand All @@ -32,11 +33,11 @@
require 'jira/resource/remotelink'
require 'jira/resource/sprint'
require 'jira/resource/sprint_report'
require 'jira/resource/resolution'
require 'jira/resource/issue'
require 'jira/resource/filter'
require 'jira/resource/field'
require 'jira/resource/rapidview'
require 'jira/resource/resolution'
require 'jira/resource/serverinfo'
require 'jira/resource/createmeta'
require 'jira/resource/webhook'
Expand Down
2 changes: 1 addition & 1 deletion lib/jira/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def self.collection_path(client, prefix = '/')
# JIRA::Resource::Comment.singular_path('456','/issue/123/')
# # => /jira/rest/api/2/issue/123/comment/456
def self.singular_path(client, key, prefix = '/')
collection_path(client, prefix) + '/' + key
collection_path(client, prefix) + '/' + key.to_s
end

# Returns the attribute name of the attribute used for find.
Expand Down
4 changes: 4 additions & 0 deletions lib/jira/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ def Status # :nodoc:
JIRA::Resource::StatusFactory.new(self)
end

def StatusCategory # :nodoc:
JIRA::Resource::StatusCategoryFactory.new(self)
end

def Resolution # :nodoc:
JIRA::Resource::ResolutionFactory.new(self)
end
Expand Down
3 changes: 3 additions & 0 deletions lib/jira/resource/issue.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'cgi'
require 'json'


module JIRA
module Resource
class IssueFactory < JIRA::BaseFactory # :nodoc:
Expand All @@ -19,6 +20,8 @@ class Issue < JIRA::Base

has_one :status, nested_under: 'fields'

has_one :resolution, nested_under: 'fields'

has_many :transitions

has_many :components, nested_under: 'fields'
Expand Down
6 changes: 5 additions & 1 deletion lib/jira/resource/status.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
require_relative 'status_category'

module JIRA
module Resource
class StatusFactory < JIRA::BaseFactory # :nodoc:
end

class Status < JIRA::Base; end
class Status < JIRA::Base
has_one :status_category, class: JIRA::Resource::StatusCategory, attribute_key: 'statusCategory'
end
end
end
8 changes: 8 additions & 0 deletions lib/jira/resource/status_category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module JIRA
module Resource
class StatusCategoryFactory < JIRA::BaseFactory # :nodoc:
end

class StatusCategory < JIRA::Base; end
end
end
20 changes: 20 additions & 0 deletions spec/integration/status_category_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'spec_helper'

describe JIRA::Resource::StatusCategory do
with_each_client do |site_url, client|
let(:client) { client }
let(:site_url) { site_url }

let(:key) { 1 }

let(:expected_attributes) do
JSON.parse(File.read('spec/mock_responses/statuscategory/1.json'))
end

let(:expected_collection_length) { 4 }

it_should_behave_like 'a resource'
it_should_behave_like 'a resource with a collection GET endpoint'
it_should_behave_like 'a resource with a singular GET endpoint'
end
end
6 changes: 1 addition & 5 deletions spec/integration/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
let(:key) { '1' }

let(:expected_attributes) do
{
'self' => 'http://localhost:2990/jira/rest/api/2/status/1',
'id' => key,
'name' => 'Open'
}
JSON.parse(File.read('spec/mock_responses/status/1.json'))
end

let(:expected_collection_length) { 5 }
Expand Down
4 changes: 4 additions & 0 deletions spec/jira/resource/issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc:
'priority' => { 'foo' => 'bar' },
'issuetype' => { 'foo' => 'bar' },
'status' => { 'foo' => 'bar' },
'resolution' => { 'foo' => 'bar' },
'components' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }],
'versions' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }],
'comment' => { 'comments' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] },
Expand Down Expand Up @@ -208,6 +209,9 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc:
expect(subject).to have_one(:status, JIRA::Resource::Status)
expect(subject.status.foo).to eq('bar')

expect(subject).to have_one(:resolution, JIRA::Resource::Resolution)
expect(subject.resolution.foo).to eq('bar')

expect(subject).to have_many(:components, JIRA::Resource::Component)
expect(subject.components.length).to eq(2)

Expand Down
22 changes: 22 additions & 0 deletions spec/jira/resource/status_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'spec_helper'

describe JIRA::Resource::Status do

let(:client) do
client = double(options: { rest_base_path: '/jira/rest/api/2' })
allow(client).to receive(:Field).and_return(JIRA::Resource::FieldFactory.new(client))
allow(client).to receive(:cache).and_return(OpenStruct.new)
client
end

describe '#status_category' do
subject do
JIRA::Resource::Status.new(client, attrs: JSON.parse(File.read('spec/mock_responses/status/1.json')))
end

it 'has a status_category relationship' do
expect(subject).to have_one(:status_category, JIRA::Resource::StatusCategory)
expect(subject.status_category.name).to eq('To Do')
end
end
end
45 changes: 40 additions & 5 deletions spec/mock_responses/status.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,69 @@
"description": "The issue is open and ready for the assignee to start work on it.",
"iconUrl": "http://localhost:2990/jira/images/icons/status_open.gif",
"name": "Open",
"id": "1"
"id": "1",
"statusCategory": {
"self": "http://localhost:2990/jira/rest/api/2/statuscategory/2",
"id": 2,
"key": "new",
"colorName": "blue-gray",
"name": "To Do"
}
},
{
"self": "http://localhost:2990/jira/rest/api/2/status/3",
"description": "This issue is being actively worked on at the moment by the assignee.",
"iconUrl": "http://localhost:2990/jira/images/icons/status_inprogress.gif",
"name": "In Progress",
"id": "3"
"id": "3",
"statusCategory": {
"self": "http://localhost:2990/jira/rest/api/2/statuscategory/4",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
},
{
"self": "http://localhost:2990/jira/rest/api/2/status/4",
"description": "This issue was once resolved, but the resolution was deemed incorrect. From here issues are either marked assigned or resolved.",
"iconUrl": "http://localhost:2990/jira/images/icons/status_reopened.gif",
"name": "Reopened",
"id": "4"
"id": "4",
"statusCategory": {
"self": "http://localhost:2990/jira/rest/api/2/statuscategory/2",
"id": 2,
"key": "new",
"colorName": "blue-gray",
"name": "To Do"
}
},
{
"self": "http://localhost:2990/jira/rest/api/2/status/5",
"description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.",
"iconUrl": "http://localhost:2990/jira/images/icons/status_resolved.gif",
"name": "Resolved",
"id": "5"
"id": "5",
"statusCategory": {
"self": "http://localhost:2990/jira/rest/api/2/statuscategory/3",
"id": 3,
"key": "done",
"colorName": "green",
"name": "Done"
}
},
{
"self": "http://localhost:2990/jira/rest/api/2/status/6",
"description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.",
"iconUrl": "http://localhost:2990/jira/images/icons/status_closed.gif",
"name": "Closed",
"id": "6"
"id": "6",
"statusCategory": {
"self": "http://localhost:2990/jira/rest/api/2/statuscategory/3",
"id": 3,
"key": "done",
"colorName": "green",
"name": "Done"
}
}
]
9 changes: 8 additions & 1 deletion spec/mock_responses/status/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
"description": "The issue is open and ready for the assignee to start work on it.",
"iconUrl": "http://localhost:2990/jira/images/icons/status_open.gif",
"name": "Open",
"id": "1"
"id": "1",
"statusCategory": {
"self": "http://localhost:2990/jira/rest/api/2/statuscategory/2",
"id": 2,
"key": "new",
"colorName": "blue-gray",
"name": "To Do"
}
}
30 changes: 30 additions & 0 deletions spec/mock_responses/statuscategory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"self": "http://localhost:2990/jira/rest/api/2/statuscategory/1",
"id": 1,
"key": "undefined",
"colorName": "medium-gray",
"name": "No Category"
},
{
"self": "http://localhost:2990/jira/rest/api/2/statuscategory/2",
"id": 2,
"key": "new",
"colorName": "blue-gray",
"name": "To Do"
},
{
"self": "http://localhost:2990/jira/rest/api/2/statuscategory/4",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
},
{
"self": "http://localhost:2990/jira/rest/api/2/statuscategory/3",
"id": 3,
"key": "done",
"colorName": "green",
"name": "Done"
}
]
7 changes: 7 additions & 0 deletions spec/mock_responses/statuscategory/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"self": "http://localhost:2990/jira/rest/api/2/statuscategory/1",
"id": 1,
"key": "undefined",
"colorName": "medium-gray",
"name": "No Category"
}

0 comments on commit c4bdc10

Please sign in to comment.