Class: NewIssue

Inherits:
Object
  • Object
show all
Defined in:
lib/jirarest2/newissue.rb

Overview

class to handle new issues (building them up, changing fields, persistence)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, type, connection) ⇒ NewIssue

Returns a new instance of NewIssue.

Parameters:

  • project (String)

    Key of the JIRA(tm) project the issue belongs to

  • type (String)

    Issuetype the issue belongs to

  • connection (Connection)

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jirarest2/newissue.rb', line 34

def initialize (project,type,connection)
  query = {:projectKeys => project, :issuetypeNames => type, :expand => "projects.issuetypes.fields" }
  answer = connection.execute("Get","issue/createmeta/",query)
  jhash = answer.result
  begin
    @project = jhash["projects"][0]["key"]
  rescue NoMethodError
    raise Jirarest2::WrongProjectException, project 
  end
  @issue = Issuetype.new
  @issue.createmeta(jhash["projects"][0]["issuetypes"][0])
  @issuetype = @issue.name
end

Instance Attribute Details

#issuekeyObject (readonly)

The issue numer if we got it somehow



28
29
30
# File 'lib/jirarest2/newissue.rb', line 28

def issuekey
  @issuekey
end

#issuetypeObject (readonly)

issue type of the issue



24
25
26
# File 'lib/jirarest2/newissue.rb', line 24

def issuetype
  @issuetype
end

#projectObject (readonly)

project the issue belongs to



26
27
28
# File 'lib/jirarest2/newissue.rb', line 26

def project
  @project
end

Instance Method Details

#add_watchers(connection, watchers) ⇒ Boolean

Set the watchers for this Ticket

Parameters:

  • connection (Connection)
  • watchers (Array)

    Watchers to be added

Returns:

  • (Boolean)

    True if successfull for all



99
100
101
102
103
104
105
106
# File 'lib/jirarest2/newissue.rb', line 99

def add_watchers(connection,watchers)
  success = false # Return whether we were successful with the watchers
  watch = Watcher.new(connection,@issuekey)
  watchers.each { |person|
    success = watch.add_watcher(person)
  }
  return success
end

#fieldtype(fieldname) ⇒ String

Return the fieldtype (Multitype as “array” nostly for backwards compability)

Returns:

  • (String)

    The fieldtype as String. MultiField types and CascadingField are returned as “array”



111
112
113
# File 'lib/jirarest2/newissue.rb', line 111

def fieldtype(fieldname)
  return @issue.fieldtype(fieldname)
end

#get_field(field) ⇒ String

Returns value of the field.

Parameters:

  • field (String)

    Name of the field

Returns:

  • (String)

    value of the field



79
80
81
# File 'lib/jirarest2/newissue.rb', line 79

def get_field(field)
  @issue.get_value(field,:name)
end

#get_fieldnamesArray

Returns Names of all fields.

Returns:

  • (Array)

    Names of all fields



54
55
56
57
58
59
60
# File 'lib/jirarest2/newissue.rb', line 54

def get_fieldnames
  names = Array.new
  @issue.fields.each {|id,field|
    names << field.name
  }
  return names
end

#get_requiredsArray

Returns Names of required fields.

Returns:

  • (Array)

    Names of required fields



49
50
51
# File 'lib/jirarest2/newissue.rb', line 49

def get_requireds
  return @issue.required_by_name
end

#jirahashHash

Deprecated.

@see Issuetype#new_ticket_hash does the same now

take this classes representation of an issue and make it presentable to JIRA(tm)

Returns:

  • (Hash)

    Hash to be sent to JIRA(tm) in a JSON representation



65
66
67
# File 'lib/jirarest2/newissue.rb', line 65

def jirahash
  return @issue.new_ticket_hash
end

#persist(connection) ⇒ Jirarest2::Result

persitence of this Issue object instance

Parameters:

  • connection (Connection)

Returns:



86
87
88
89
90
91
92
93
# File 'lib/jirarest2/newissue.rb', line 86

def persist(connection)
  hash = @issue.new_ticket_hash
  ret = connection.execute("Post","issue/",hash) 
  if ret.code == "201" then # Ticket sucessfully created
    @issuekey = ret.result["key"]
  end
  return ret
end

#set_field(key, value) ⇒ Object

TODO:

check if the allowed Values are working now too and if they might throw an exception

Parameters:

  • key (String)

    Name of the field

  • value (String)

    Value the field should be set to, this is either a String or an Array (don’t know if numbers work too)

Raises:



73
74
75
# File 'lib/jirarest2/newissue.rb', line 73

def set_field(key, value)
  @issue.set_value(key,value,:name)
end