Class: JIRA::Resource::Issue
- Defined in:
- lib/jira/resource/issue.rb,
lib/jira/resource/issuelink.rb
Overview
This class provides the Issue object <-> REST mapping for JIRA::Resource::Issue derived class, i.e. the Create, Retrieve, Update, Delete lifecycle methods.
Lifecycle methods
Retrieving all issues
client.Issue.all
Retrieving a single issue
= { expand: 'editmeta' }
issue = client.Issue.find("SUP-3000", )
Creating a new issue
issue = client.Issue.build(fields: { summary: 'New issue', project: { key: 'SUP' }, issuetype: { name: 'Bug' } })
issue.save
Updating an issue
issue = client.Issue.find("SUP-3000")
issue.save(fields: { summary: 'Updated issue' })
Deleting an issue
issue = client.Issue.find("SUP-3000")
issue.delete
Constant Summary
Constants inherited from Base
Base::QUERY_PARAMS_FOR_SEARCH, Base::QUERY_PARAMS_FOR_SINGLE_FETCH
Instance Attribute Summary
Attributes inherited from Base
#attrs, #client, #deleted, #expanded
Class Method Summary collapse
-
.all(client) ⇒ Array<JIRA::Resource::Issue>
Get collection of issues.
-
.build(attrs = {}) ⇒ JIRA::Resource::Issue
Constructs a new issue object.
-
.find(client, key, options = {}) ⇒ JIRA::Resource::Issue
Gets/fetches an issue from JIRA.
- .jql(client, jql, options = { fields: nil, max_results: nil, expand: nil, reconcile_issues: nil }) ⇒ Object
Instance Method Summary collapse
- #editmeta ⇒ Object
-
#fetch(reload = false, query_params = {}) ⇒ void
Fetches the attributes for the specified resource from JIRA unless the resource is already expanded and the optional force reload flag is not set.
Methods inherited from Base
belongs_to, belongs_to_relationships, collection_attributes_are_nested, #collection_path, collection_path, #delete, endpoint_name, #has_errors?, has_many, has_one, #id, #initialize, key_attribute, #key_value, nested_collections, #new_record?, parse_json, #patched_url, #path_component, #save, #save!, #set_attrs, #set_attrs_from_response, singular_path, #to_json, #to_s, #to_sym, #url
Constructor Details
This class inherits a constructor from JIRA::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/jira/resource/issue.rb', line 163 def method_missing(method_name, *args, &) if attrs.key?('fields') if attrs['fields'].key?(method_name.to_s) attrs['fields'][method_name.to_s] else official_name = client.Field.name_to_id(method_name) if attrs['fields'].key?(official_name) attrs['fields'][official_name] else super end end else super end end |
Class Method Details
.all(client) ⇒ Array<JIRA::Resource::Issue>
Get collection of issues.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/jira/resource/issue.rb', line 64 def self.all(client) start_at = 0 max_results = 1000 result = [] loop do url = client.[:rest_base_path] + "/search/jql?expand=transitions.fields&maxResults=#{max_results}&startAt=#{start_at}" response = client.get(url) json = parse_json(response.body) json['issues'].map do |issue| result.push(client.Issue.build(issue)) end break if json['issues'].empty? start_at += json['issues'].size end result end |
.build(attrs = {}) ⇒ JIRA::Resource::Issue
Constructs a new issue object.
|
|
# File 'lib/jira/resource/issue.rb', line 180
|
.find(client, key, options = {}) ⇒ JIRA::Resource::Issue
Gets/fetches an issue from JIRA.
Note: attachments are not fetched by default.
JIRA::Resource::Issue.find(client, “SUP-3000”, { fields: %w[summary description attachment created ] } )
|
|
# File 'lib/jira/resource/issue.rb', line 180
|
.jql(client, jql, options = { fields: nil, max_results: nil, expand: nil, reconcile_issues: nil }) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/jira/resource/issue.rb', line 83 def self.jql(client, jql, = { fields: nil, max_results: nil, expand: nil, reconcile_issues: nil }) url = client.[:rest_base_path] + "/search/jql?jql=#{CGI.escape(jql)}" if [:fields] url << "&fields=#{[:fields].map do |value| CGI.escape(client.Field.name_to_id(value)) end.join(',')}" end url << "&maxResults=#{CGI.escape([:max_results].to_s)}" if [:max_results] url << "&reconcileIssues=#{CGI.escape([:reconcile_issues].to_s)}" if [:reconcile_issues] if [:expand] [:expand] = [[:expand]] if [:expand].is_a?(String) url << "&expand=#{[:expand].to_a.map { |value| CGI.escape(value.to_s) }.join(',')}" end issues = [] next_page_token = nil json = {} while json['isLast'] != true page_url = url.dup page_url << "&nextPageToken=#{next_page_token}" if next_page_token response = client.get(page_url) json = parse_json(response.body) return json['total'] if [:max_results]&.zero? next_page_token = json['nextPageToken'] json['issues'].map do |issue| issues << client.Issue.build(issue) end end issues end |
Instance Method Details
#editmeta ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/jira/resource/issue.rb', line 143 def = client.[:rest_base_path] + "/#{self.class.endpoint_name}/#{key}/editmeta" response = client.get() json = self.class.parse_json(response.body) json['fields'] end |
#fetch(reload = false, query_params = {}) ⇒ void
This method returns an undefined value.
Fetches the attributes for the specified resource from JIRA unless the resource is already expanded and the optional force reload flag is not set
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/jira/resource/issue.rb', line 128 def fetch(reload = false, query_params = {}) return if && !reload response = client.get(url_with_query_params(url, query_params)) set_attrs_from_response(response) if @attrs && @attrs['fields'] && @attrs['fields']['worklog'] && (@attrs['fields']['worklog']['total'] > @attrs['fields']['worklog']['maxResults']) worklog_url = client.[:rest_base_path] + "/#{self.class.endpoint_name}/#{id}/worklog" response = client.get(worklog_url) set_attrs({ 'fields' => { 'worklog' => self.class.parse_json(response.body) } }, false) unless response.body.nil? || (response.body.length < 2) end @expanded = true end |