Class: Git::Trac::Ticket
- Inherits:
-
Object
- Object
- Git::Trac::Ticket
- Defined in:
- lib/git/trac/ticket.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
- #attachment(name) ⇒ Object
- #attachment_url ⇒ Object
- #attachments ⇒ Object
- #cleanup(options = {}) ⇒ Object
- #comment!(body) ⇒ Object
- #csv ⇒ Object
- #fetch(options = {}, &block) ⇒ Object
- #form ⇒ Object
-
#initialize(repo, number) ⇒ Ticket
constructor
A new instance of Ticket.
- #inspect ⇒ Object
- #open? ⇒ Boolean
- #trac_dir ⇒ Object
- #upload_attachment(description, filename, body) ⇒ Object
- #upload_patch(options = {}) ⇒ Object
- #url(format = nil) ⇒ Object
Constructor Details
#initialize(repo, number) ⇒ Ticket
Returns a new instance of Ticket.
10 11 12 |
# File 'lib/git/trac/ticket.rb', line 10 def initialize(repo, number) @repository, @number = repo, Integer(number) end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
8 9 10 |
# File 'lib/git/trac/ticket.rb', line 8 def number @number end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
8 9 10 |
# File 'lib/git/trac/ticket.rb', line 8 def repository @repository end |
Instance Method Details
#attachment(name) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/git/trac/ticket.rb', line 60 def (name) if name .detect {|a| a.filename == name} or raise Git::Trac::Error, "no such attachment #{number}/#{name}" else .last or raise Git::Trac::Error, "no attachments for #{number}" end end |
#attachment_url ⇒ Object
23 24 25 |
# File 'lib/git/trac/ticket.rb', line 23 def "#{@repository.url}/attachment/ticket/#{@number}" end |
#attachments ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/git/trac/ticket.rb', line 49 def response = repository.get_response() if html = response.body[/<dl class="attachments">.*?<\/dl>/m] return Attachment.from_html(self,html) elsif response.kind_of?(Net::HTTPSuccess) return [] else response.error! end end |
#cleanup(options = {}) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/git/trac/ticket.rb', line 118 def cleanup( = {}) revs = [] repository.each_ref("refs/remotes/trac/#{number}") do |object, ref| revs << object repository.exec("git","update-ref","-d",ref,object) unless [:only_branches] end begin Dir.unlink("#{repository.git_dir}/refs/remotes/trac/#{number}") rescue Errno::ENOENT, Errno::ENOTEMPTY end revs.any? end |
#comment!(body) ⇒ Object
78 79 80 81 82 |
# File 'lib/git/trac/ticket.rb', line 78 def comment!(body) form = form() form.fields.name("comment").value = body form.submit end |
#csv ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/git/trac/ticket.rb', line 27 def csv response = repository.get_response(url(:tab)) no_such_ticket if response.kind_of?(Net::HTTPInternalServerError) response.error! unless response.kind_of?(Net::HTTPSuccess) body = response.body headers, values = body.split(/\r?\n/).map do |line| line.split("\t").map do |column| column.gsub(/\\(.)/) do case $1 when "r" then "" when "n" then "\n" when "t" then "\t" else $1 end end end end return headers.zip(values).inject({}) {|h,(k,v)| h[k] = v; h} end |
#fetch(options = {}, &block) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/git/trac/ticket.rb', line 131 def fetch( = {}, &block) cleanup() .each do || .fetch(,&block) end end |
#form ⇒ Object
74 75 76 |
# File 'lib/git/trac/ticket.rb', line 74 def form repository.agent.get(url).forms.last end |
#inspect ⇒ Object
14 15 16 |
# File 'lib/git/trac/ticket.rb', line 14 def inspect "#<#{self.class.inspect} #{url}>" end |
#open? ⇒ Boolean
113 114 115 116 |
# File 'lib/git/trac/ticket.rb', line 113 def open? c = csv %w(new reopened).include?(c["status"]) end |
#trac_dir ⇒ Object
70 71 72 |
# File 'lib/git/trac/ticket.rb', line 70 def trac_dir "#{repository.git_dir}/refs/remotes/trac/#{number}" end |
#upload_attachment(description, filename, body) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/git/trac/ticket.rb', line 84 def (description, filename, body) form = repository.agent.get("#{}?action=new").forms.last form.action = = form.fields.name("author") if .any? && .value == "anonymous" .value = repository.[:user].to_s end form.fields.name("description").value = description.to_s = form.file_uploads.name("attachment").first .file_name = filename .file_data = body submission = form.submit submission.instance_variable_get(:@uri) end |
#upload_patch(options = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/git/trac/ticket.rb', line 99 def upload_patch( = {}) filename = [:filename] || "#{File.basename(repository.current_checkout)}.patch" upstream = [:upstream] || "refs/remotes/trunk" upstream += "...HEAD" unless upstream.include?(".") diff = repository.exec("git","diff",upstream) return false if diff.empty? # Don't upload the exact same patch that was pulled down return false if repository.generated_commits[repository.rev_parse("HEAD")] == number if block_given? # confirmation block return false if yield(diff) == false end ([:description], filename, diff) end |
#url(format = nil) ⇒ Object
18 19 20 21 |
# File 'lib/git/trac/ticket.rb', line 18 def url(format = nil) query = "?format=#{format}" if format "#{@repository.url}/ticket/#{@number}#{query}" end |