Class: Toolshed::TicketTracking::Jira
- Inherits:
-
Object
- Object
- Toolshed::TicketTracking::Jira
- Extended by:
- Toolshed::TicketTracking
- Includes:
- HTTParty
- Defined in:
- lib/toolshed/ticket_tracking/jira.rb
Constant Summary collapse
- USE_PROJECT_NAME =
true
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#project ⇒ Object
Returns the value of attribute project.
-
#ticket ⇒ Object
Returns the value of attribute ticket.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_note(note_text) ⇒ Object
Instance methods.
- #available_statuses ⇒ Object
-
#initialize(options = {}) ⇒ Jira
constructor
A new instance of Jira.
- #title ⇒ Object
- #transition_status_id_by_status(status) ⇒ Object
- #update_ticket_status(status, options = {}) ⇒ Object
- #url ⇒ Object
Methods included from Toolshed::TicketTracking
clean, story_id_from_branch_name
Constructor Details
#initialize(options = {}) ⇒ Jira
Returns a new instance of Jira.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 11 def initialize(={}) username = ([:username].nil?) ? Toolshed::Client::ticket_tracker_username : [:username] password = ([:password].nil?) ? Toolshed::Client::ticket_tracker_password : [:password] self.owner = Toolshed::Client::ticket_tracker_owner self.client = JIRA::Client.new({ username: username, password: password, site: "https://#{self.owner}.atlassian.net", context_path: '', auth_type: :basic, use_ssl: true, }) self.project = self.client.Project.find([:project]) self.ticket = self.client.Issue.find([:ticket_id]) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
9 10 11 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 9 def client @client end |
#owner ⇒ Object
Returns the value of attribute owner.
9 10 11 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 9 def owner @owner end |
#project ⇒ Object
Returns the value of attribute project.
9 10 11 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 9 def project @project end |
#ticket ⇒ Object
Returns the value of attribute ticket.
9 10 11 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 9 def ticket @ticket end |
Class Method Details
.create_instance(options = {}) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 88 def self.create_instance(={}) unless (.has_key?(:project)) raise 'Unable to use Jira as project name was not supplied' end unless (.has_key?(:ticket_id)) raise 'Unable to use Jira as ticket id was not supplied' end jira = Toolshed::TicketTracking::Jira.new({ project: [:project], username: Toolshed::TicketTracking::Jira.username, password: Toolshed::TicketTracking::Jira.password, ticket_id: [:ticket_id] }) end |
.password ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 78 def self.password return Toolshed::Client::ticket_tracker_password unless Toolshed::Client::ticket_tracker_password.nil? # prompt to ask for password system "stty -echo" puts "Jira password? " password = $stdin.gets.chomp.strip system "stty echo" end |
.username ⇒ Object
Class methods
70 71 72 73 74 75 76 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 70 def self.username return Toolshed::Client::ticket_tracker_username unless Toolshed::Client::ticket_tracker_username.nil? # prompt to ask for username puts "Jira username? " username = $stdin.gets.chomp.strip end |
Instance Method Details
#add_note(note_text) ⇒ Object
Instance methods
33 34 35 36 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 33 def add_note(note_text) issue = self.ticket.comments.build issue.save({ 'body' => note_text }) end |
#available_statuses ⇒ Object
45 46 47 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 45 def available_statuses self.client.Transition.all(issue: self.ticket) end |
#title ⇒ Object
59 60 61 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 59 def title self.ticket.summary end |
#transition_status_id_by_status(status) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 49 def transition_status_id_by_status(status) self.available_statuses.each do |transition_status| if (status == transition_status.name) return transition_status.id end end raise "Unable to find available status" end |
#update_ticket_status(status, options = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 38 def update_ticket_status(status, ={}) available_statuses transition = self.ticket.transitions.build transition.save({ 'transition' => { "id" => transition_status_id_by_status(status) } }) end |
#url ⇒ Object
63 64 65 |
# File 'lib/toolshed/ticket_tracking/jira.rb', line 63 def url "https://#{self.owner}.atlassian.net/browse/#{self.ticket.key}" end |