Class: Jiralicious::Issue
- Defined in:
- lib/jiralicious/issue.rb,
lib/jiralicious/issue/fields.rb,
lib/jiralicious/issue/comment.rb,
lib/jiralicious/issue/watchers.rb,
lib/jiralicious/issue/transitions.rb
Overview
The Issue class rolls up all functionality of issues from Jira. This class contains methods to manage Issues from Ruby via the API. Several child classes are added in order to facilitate several different aspects of managing the issues.
Defined Under Namespace
Classes: Comment, Fields, Transitions, Watchers
Instance Attribute Summary collapse
-
#comments ⇒ Object
Contains the Comments Class.
-
#createmeta ⇒ Object
Retrieves the create meta for the Jira Project based on Issue Types.
-
#editmeta ⇒ Object
Retrieves the edit meta for the Jira Issue.
-
#fields ⇒ Object
Contains the Fields Class.
-
#watchers ⇒ Object
Contains the Watchers Class.
Attributes inherited from Base
Class Method Summary collapse
-
.assignee(name, key) ⇒ Object
Adds specified assignee to the Jira Issue.
-
.create(issue) ⇒ Object
Creates a new issue.
-
.createmeta(projectkeys, issuetypeids = nil) ⇒ Object
Retrieves the create meta for the Jira Project based on Issue Types.
-
.editmeta(key) ⇒ Object
Retrieves the edit meta for the Jira Issue.
-
.get_transitions(transitions_url) ⇒ Object
Legacy method to retrieve transitions manually.
-
.remove(key, options = {}) ⇒ Object
Removes/Deletes the Issue from the Jira Project.
-
.transition(transitions_url, data) ⇒ Object
Legacy method to process transitions manually.
-
.update(issue, key) ⇒ Object
Updates the specified issue based on the provided HASH.
Instance Method Summary collapse
-
#initialize(decoded_json = nil, default = nil) ⇒ Issue
constructor
Initialization Method.
-
#load(decoded_hash, default = nil) ⇒ Object
Imports all data from a decoded hash.
-
#reload ⇒ Object
Forces the Jira Issue to reload with current or updated information.
-
#remove(options = {}) ⇒ Object
Method to remove or delete the current issue.
-
#save ⇒ Object
Saves the current Issue but does not update itself.
-
#save! ⇒ Object
Saves the current Issue and reloads to ensure it is upto date.
-
#set_assignee(name) ⇒ Object
Method to assign an assignee by name in a current issue.
Methods inherited from Base
#all, #endpoint_name, endpoint_name, fetch, find, find_all, handler, issueKey_test, #loaded?, #method_missing, #numeric?, parent_name, #parent_name, #properties_from_hash
Methods included from Parsers::FieldParser
Constructor Details
#initialize(decoded_json = nil, default = nil) ⇒ Issue
Initialization Method
- Arguments
-
:decoded_json (optional) rubyized json object
:default (optional) set to not load subclasses
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/jiralicious/issue.rb', line 42 def initialize(decoded_json = nil, default = nil) @loaded = false if (!decoded_json.nil?) if !decoded_json.include? 'fields' decoded_json = {'fields' => decoded_json} end super(decoded_json) parse!(decoded_json["fields"]) if default.nil? @fields = Fields.new(self['fields']) if self['fields'] if self.jira_key @comments = Comment.find_by_key(self.jira_key) @watchers = Watchers.find_by_key(self.jira_key) @transitions = Transitions.new(self.jira_key) @loaded = true end end end @fields = Fields.new if @fields.nil? @comments = Comment.new if @comments.nil? @watchers = Watchers.new if @watchers.nil? @transitions = Transitions.new if @transitions.nil? @createmeta = nil @editmeta = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Jiralicious::Base
Instance Attribute Details
#comments ⇒ Object
Contains the Comments Class
26 27 28 |
# File 'lib/jiralicious/issue.rb', line 26 def comments @comments end |
#createmeta ⇒ Object
Retrieves the create meta for the Jira Project based on Issue Types. Can be used to validate or filter create requests to minimize errors.
30 31 32 |
# File 'lib/jiralicious/issue.rb', line 30 def @createmeta end |
#editmeta ⇒ Object
Retrieves the edit meta for the Jira Issue. Can be used to validate or filter create requests to minimize errors.
32 33 34 |
# File 'lib/jiralicious/issue.rb', line 32 def @editmeta end |
#fields ⇒ Object
Contains the Fields Class
24 25 26 |
# File 'lib/jiralicious/issue.rb', line 24 def fields @fields end |
#watchers ⇒ Object
Contains the Watchers Class
28 29 30 |
# File 'lib/jiralicious/issue.rb', line 28 def watchers @watchers end |
Class Method Details
.assignee(name, key) ⇒ Object
Adds specified assignee to the Jira Issue.
- Arguments
-
:name (required) name of assignee
:key (required) issue key
110 111 112 113 |
# File 'lib/jiralicious/issue.rb', line 110 def assignee(name, key) name = {"name" => name} if name.is_a? String fetch({:method => :put, :key => "#{key}/assignee", :body => name}) end |
.create(issue) ⇒ Object
Creates a new issue. This method is not recommended for direct access but is provided for advanced users.
- Arguments
-
:issue (required) issue fields in hash format
122 123 124 |
# File 'lib/jiralicious/issue.rb', line 122 def create(issue) fetch({:method => :post, :body => issue}) end |
.createmeta(projectkeys, issuetypeids = nil) ⇒ Object
Retrieves the create meta for the Jira Project based on Issue Types. Can be used to validate or filter create requests to minimize errors.
- Arguments
-
:projectkeys (required) project key to generate create meta
:issuetypeids (opitonal) list of issues types for create meta
166 167 168 169 |
# File 'lib/jiralicious/issue.rb', line 166 def (projectkeys, issuetypeids = nil) response = fetch({:body_to_params => true, :key => "createmeta", :body => {:expand => "projects.issuetypes.fields.", :projectKeys => projectkeys, :issuetypeIds => issuetypeids}}) return Field.new(response.parsed_response) end |
.editmeta(key) ⇒ Object
Retrieves the edit meta for the Jira Issue. Can be used to validate or filter create requests to minimize errors.
- Arguments
-
:key (required) issue key
178 179 180 181 182 |
# File 'lib/jiralicious/issue.rb', line 178 def (key) response = fetch({:key => "#{key}/editmeta"}) response.parsed_response["key"] = key Field.new(response.parsed_response) end |
.get_transitions(transitions_url) ⇒ Object
Legacy method to retrieve transitions manually.
- Arguments
-
:transitions_url (required) full URL
190 191 192 |
# File 'lib/jiralicious/issue.rb', line 190 def get_transitions(transitions_url) Jiralicious.session.request(:get, transitions_url, :handler => handler) end |
.remove(key, options = {}) ⇒ Object
Removes/Deletes the Issue from the Jira Project. It is not recommended to delete issues however the functionality is provided. It is recommended to override this function to throw an error or warning to maintain data integrity in systems that do not allow deleting from a remote location.
- Arguments
-
:key (required) issue key
:deleteSubtasks (optional) boolean flag to remove subtasks
139 140 141 |
# File 'lib/jiralicious/issue.rb', line 139 def remove(key, = {}) fetch({:method => :delete, :body_to_params => true, :key => key, :body => }) end |
.transition(transitions_url, data) ⇒ Object
Legacy method to process transitions manually.
- Arguments
-
:transitions_url (required) full URL and params to be processed
:data (required) data for the transition
202 203 204 205 206 |
# File 'lib/jiralicious/issue.rb', line 202 def transition(transitions_url, data) Jiralicious.session.request(:post, transitions_url, :handler => handler, :body => data.to_json) end |
.update(issue, key) ⇒ Object
Updates the specified issue based on the provided HASH. It is not recommended to access this method directly but is provided for advanced users.
- Arguments
-
:issue (required) hash of fields to update
:key (required) issue key to update
153 154 155 |
# File 'lib/jiralicious/issue.rb', line 153 def update(issue, key) fetch({:method => :put, :key => key, :body => issue}) end |
Instance Method Details
#load(decoded_hash, default = nil) ⇒ Object
Imports all data from a decoded hash. This function is used when a blank issue is created but needs to be loaded from a JSON string at a later time.
- Arguments
-
:decoded_hash (optional) rubyized json object
:default (optional) set to not load subclasses
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/jiralicious/issue.rb', line 78 def load(decoded_hash, default = nil) decoded_hash.each do |k,v| self[:"#{k}"] = v end if default.nil? parse!(self['fields']) @fields = Fields.new(self['fields']) if self['fields'] @comments = Comment.find_by_key(self.jira_key) if self.jira_key @watchers = Watchers.find_by_key(self.jira_key) if self.jira_key @loaded = true if self.jira_key else parse!(decoded_hash) end end |
#reload ⇒ Object
Forces the Jira Issue to reload with current or updated information. This method is used in lazy loading methods.
97 98 99 |
# File 'lib/jiralicious/issue.rb', line 97 def reload load(self.class.find(self.jira_key, {:reload => true}).parsed_response) end |
#remove(options = {}) ⇒ Object
Method to remove or delete the current issue.
- Arguments
-
:options (optional) passed on
225 226 227 |
# File 'lib/jiralicious/issue.rb', line 225 def remove( = {}) self.class.remove(self.jira_key, ) end |
#save ⇒ Object
Saves the current Issue but does not update itself.
254 255 256 257 258 259 260 261 262 |
# File 'lib/jiralicious/issue.rb', line 254 def save if loaded? self.class.update(@fields.format_for_update, self.jira_key) else response = self.class.create(@fields.format_for_create) self.jira_key = response.parsed_response['key'] end return self.jira_key end |
#save! ⇒ Object
Saves the current Issue and reloads to ensure it is upto date.
267 268 269 |
# File 'lib/jiralicious/issue.rb', line 267 def save! load(self.class.find(save, {:reload => true}).parsed_response) end |
#set_assignee(name) ⇒ Object
Method to assign an assignee by name in a current issue.
- Arguments
-
:name (required) name of assignee
215 216 217 |
# File 'lib/jiralicious/issue.rb', line 215 def set_assignee(name) self.class.assignee(name, self.jira_key) end |