Class: Mosespa::Mosespa
- Inherits:
-
Object
- Object
- Mosespa::Mosespa
- Defined in:
- lib/mosespa.rb
Instance Method Summary collapse
- #browse(url) ⇒ Object
- #comment(ticket, comment) ⇒ Object
- #create(client, project, summary, description) ⇒ Object
- #create_get_options(file, project, task_type, summary, description) ⇒ Object
- #search(tickets, json, verbose) ⇒ Object
- #show(ticket, json, verbose) ⇒ Object
Instance Method Details
#browse(url) ⇒ Object
22 23 24 |
# File 'lib/mosespa.rb', line 22 def browse(url) `#{ENV['BROWSER']} #{url}` end |
#comment(ticket, comment) ⇒ Object
26 27 28 29 |
# File 'lib/mosespa.rb', line 26 def comment(ticket, comment) c = ticket.comments.build c.save({'body' => comment}) end |
#create(client, project, summary, description) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mosespa.rb', line 35 def create(client, project, summary, description) file = Tempfile.new('mosespa') need_external_editor = summary.nil? if need_external_editor task_type, summary, description = (file, project,'Task' ,summary, description) $stderr.puts "Ticket type was: #{task_type}" $stderr.puts "Summary was: #{summary}" end fail "Won't create a ticket without summary" if summary.nil? or summary.empty? t = client.Issue.build request = {'summary' => summary, 'description' => description, 'project' => {'key' => project.key}, 'issuetype' => {'name'=> task_type || 'Task'} } begin resp = t.save!({'fields' =>request}) rescue Exception => e $stderr.puts "Error while creating your ticket" $stderr.puts "Your ticket information was saved in #{file.path}" if need_external_editor raise e end puts "Created #{t.key}" file.unlink end |
#create_get_options(file, project, task_type, summary, description) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mosespa.rb', line 57 def (file, project, task_type, summary, description) file.write(summary || "Task:") file.write("\n") file.write("\n") file.write(description ||"") file.write("\n") file.write("# Here you can edit the ticket you want to create\n") file.write("# Line starting with a # will be ignored\n") file.write("# The format is the same as a git commit\n") file.write("\n") file.write("# Summary line follows this template : [TaskType]: [Title]\n") file.write("# This means that if you write: Story: Create a prototype of SOA\n") file.write("# You'll get a new story about creating a SOA prototype") file.write("# The summary line is always followed by an empty line and may be followed by a description") file.write("\n\n") file.write("# /* vim: set filetype=gitcommit : */") file.close #need to flush file.open system "$EDITOR #{file.path}" all = file.read.lines.reject {|l| l.start_with? "#"}.map {|l| l.chop} summary = all[0] m = /^(\w+):(.*)/.match(summary) task_type, summary = m.to_a.drop(1) if m description = all.drop(2).join("\n") $stderr.puts "Type: #{task_type}" $stderr.puts "summary: #{summary}" $stderr.puts "description: #{description}" file.close [task_type, summary, description] end |
#search(tickets, json, verbose) ⇒ Object
31 32 33 |
# File 'lib/mosespa.rb', line 31 def search(tickets, json, verbose) tickets.each { |t| show(t, json, verbose) } end |
#show(ticket, json, verbose) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mosespa.rb', line 7 def show(ticket, json, verbose) p = Puts.new if json puts ticket.to_json else puts "#{ticket.key} (#{ticket.status.name}) #{ticket.summary}" if verbose puts ticket.summary ticket.comments.each do |c| p.puts(c.['name'], c.body) end end end end |