Class: MetaProject::Tracker::Jira::JiraTracker

Inherits:
Base
  • Object
show all
Includes:
JiraIssues
Defined in:
lib/meta_project/tracker/jira/jira_tracker.rb

Overview

Defined Under Namespace

Classes: JiraEnvVarException, Session

Constant Summary collapse

JIRA_API =
"jira1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JiraIssues

command_pattern, #identifier_examples, issue_pattern, #markup

Methods inherited from Base

classes, #issue

Constructor Details

#initialize(jira_base_url = nil, jira_project_id = nil) ⇒ JiraTracker

Creates a new JiraTracker. In order to successfully get issue info (via XMLRPC), two env vars must be defined. Example:

JiraTracker.new("http://jira.codehaus.org", "DC")

Then the following must be defined:

JIRA_CODEHAUS_ORG_JIRA_USER
JIRA_CODEHAUS_ORG_JIRA_PASSWORD
TODO: pass in to ctor instead. do this somewhere else!


29
30
31
# File 'lib/meta_project/tracker/jira/jira_tracker.rb', line 29

def initialize(jira_base_url=nil, jira_project_id=nil)
  @jira_base_url, @jira_project_id = jira_base_url, jira_project_id
end

Instance Attribute Details

#jira_base_urlObject

Returns the value of attribute jira_base_url.



17
18
19
# File 'lib/meta_project/tracker/jira/jira_tracker.rb', line 17

def jira_base_url
  @jira_base_url
end

#jira_project_idObject

Returns the value of attribute jira_project_id.



17
18
19
# File 'lib/meta_project/tracker/jira/jira_tracker.rb', line 17

def jira_project_id
  @jira_project_id
end

Instance Method Details

#close(issue) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/meta_project/tracker/jira/jira_tracker.rb', line 52

def close(issue)
  begin
    issue_struct = {
      "project" => @jira_project_id,
      "summary" => issue.summary,
      "description" => issue.detail,
      "type" => 2, # magic number!
      "priority" => 1,
      "status" => 6 # magic number for closed? do we have to look it up?
    }
     do |session|
      # TODO: Can't close JIRA issue.
      # The following method:
      # http://www.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/com/atlassian/jira/rpc/xmlrpc/XmlRpcService.html#updateIssue(java.lang.String,%20java.lang.String,%20java.util.Hashtable)
      # doesn't seem to exist on the JIRA on Codehaus (older version probably)
      issue_struct = session.updateIssue(issue.identifier, issue_struct)
      issue.attributes[:identifier] = issue_struct["key"]
      issue
    end
  rescue XMLRPC::FaultException => e
    # Probably bad issue number. Don't set URL.
    STDERR.puts("WARNING: Exception from JIRA while closing issue #{issue.identifier}: #{e.faultCode}, #{e.faultString}")
  end
end

#create(issue) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/meta_project/tracker/jira/jira_tracker.rb', line 37

def create(issue)
  issue_struct = {
    "project" => @jira_project_id,
    "summary" => issue.summary,
    "description" => issue.detail,
    "type" => 2, # magic number!
    "priority" => 1
  }
   do |session|
    issue_struct = session.createIssue(issue_struct)
    issue.attributes[:identifier] = issue_struct["key"]
    issue
  end
end

#materialize(issue) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/meta_project/tracker/jira/jira_tracker.rb', line 77

def materialize(issue)
  issue.attributes[:identifier] = issue.attributes[:identifier].upcase

  # Getting summary and detail requires login
  begin
     do |session|
      issue_struct = session.getIssue(issue.identifier)            
      issue.attributes[:url] = "#{@jira_base_url}/browse/#{issue.identifier}"
      issue.attributes[:summary] = issue_struct["summary"] ? issue_struct["summary"].strip : nil
      issue.attributes[:detail] = issue_struct["description"] ? issue_struct["description"].strip : nil
    end
  rescue JiraEnvVarException => e
    # Couldn't log in because of missing login info. Assume issue exists
    issue.attributes[:url] = "#{@jira_base_url}/browse/#{issue.identifier}"
    STDERR.puts("WARNING: #{e.message}")
  rescue XMLRPC::FaultException => e
    # Probably bad issue number. Don't set URL.
    STDERR.puts("WARNING: Exception from JIRA while loading issue details for #{issue.identifier}: #{e.faultCode}, #{e.faultString}")
  end
  issue
end

#overviewObject



33
34
35
# File 'lib/meta_project/tracker/jira/jira_tracker.rb', line 33

def overview
  "#{@jira_base_url}/browse/#{@jira_project_id}"
end