Class: TicGit::Ticket
- Inherits:
-
Object
- Object
- TicGit::Ticket
- Defined in:
- lib/ticgit/ticket.rb
Instance Attribute Summary collapse
-
#assigned ⇒ Object
Returns the value of attribute assigned.
-
#attachments ⇒ Object
arrays.
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#comments ⇒ Object
arrays.
-
#description ⇒ Object
Returns the value of attribute description.
-
#milestone ⇒ Object
Returns the value of attribute milestone.
-
#opened ⇒ Object
Returns the value of attribute opened.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#state ⇒ Object
Returns the value of attribute state.
-
#tags ⇒ Object
arrays.
-
#ticket_id ⇒ Object
Returns the value of attribute ticket_id.
-
#ticket_name ⇒ Object
Returns the value of attribute ticket_name.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
- .clean_string(string) ⇒ Object
- .create(base, title, options = {}) ⇒ Object
- .create_ticket_name(title) ⇒ Object
- .open(base, ticket_name, ticket_hash, options = {}) ⇒ Object
- .parse_ticket_name(name) ⇒ Object
Instance Method Summary collapse
- #add_comment(comment) ⇒ Object
- #add_tag(tag) ⇒ Object
- #assigned_name ⇒ Object
- #change_assigned(new_assigned) ⇒ Object
- #change_state(new_state) ⇒ Object
- #comment_name(email) ⇒ Object
- #email ⇒ Object
-
#initialize(base, options = {}) ⇒ Ticket
constructor
A new instance of Ticket.
- #path ⇒ Object
- #remove_tag(tag) ⇒ Object
-
#save_new ⇒ Object
write this ticket to the git database.
Constructor Details
#initialize(base, options = {}) ⇒ Ticket
Returns a new instance of Ticket.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ticgit/ticket.rb', line 9 def initialize(base, = {}) [:user_name] ||= base.git.config('user.name') [:user_email] ||= base.git.config('user.email') @base = base @opts = || {} @description = .delete(:description) @state = 'open' # by default @comments = [] @tags = [] @attachments = [] end |
Instance Attribute Details
#assigned ⇒ Object
Returns the value of attribute assigned.
6 7 8 |
# File 'lib/ticgit/ticket.rb', line 6 def assigned @assigned end |
#attachments ⇒ Object
arrays
7 8 9 |
# File 'lib/ticgit/ticket.rb', line 7 def @attachments end |
#base ⇒ Object (readonly)
Returns the value of attribute base.
4 5 6 |
# File 'lib/ticgit/ticket.rb', line 4 def base @base end |
#comments ⇒ Object
arrays
7 8 9 |
# File 'lib/ticgit/ticket.rb', line 7 def comments @comments end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/ticgit/ticket.rb', line 6 def description @description end |
#milestone ⇒ Object
Returns the value of attribute milestone.
6 7 8 |
# File 'lib/ticgit/ticket.rb', line 6 def milestone @milestone end |
#opened ⇒ Object
Returns the value of attribute opened.
6 7 8 |
# File 'lib/ticgit/ticket.rb', line 6 def opened @opened end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
4 5 6 |
# File 'lib/ticgit/ticket.rb', line 4 def opts @opts end |
#state ⇒ Object
Returns the value of attribute state.
6 7 8 |
# File 'lib/ticgit/ticket.rb', line 6 def state @state end |
#tags ⇒ Object
arrays
7 8 9 |
# File 'lib/ticgit/ticket.rb', line 7 def @tags end |
#ticket_id ⇒ Object
Returns the value of attribute ticket_id.
5 6 7 |
# File 'lib/ticgit/ticket.rb', line 5 def ticket_id @ticket_id end |
#ticket_name ⇒ Object
Returns the value of attribute ticket_name.
5 6 7 |
# File 'lib/ticgit/ticket.rb', line 5 def ticket_name @ticket_name end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/ticgit/ticket.rb', line 6 def title @title end |
Class Method Details
.clean_string(string) ⇒ Object
118 119 120 |
# File 'lib/ticgit/ticket.rb', line 118 def self.clean_string(string) string.downcase.gsub(/[^a-zA-Z0-9_:;,.]+/, '-') end |
.create(base, title, options = {}) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/ticgit/ticket.rb', line 23 def self.create(base, title, = {}) t = Ticket.new(base, ) t.title = title t.ticket_name = self.create_ticket_name(title) t.save_new t end |
.create_ticket_name(title) ⇒ Object
218 219 220 |
# File 'lib/ticgit/ticket.rb', line 218 def self.create_ticket_name(title) [Time.now.to_i.to_s, Ticket.clean_string(title), rand(999).to_i.to_s].join('_') end |
.open(base, ticket_name, ticket_hash, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ticgit/ticket.rb', line 31 def self.open(base, ticket_name, ticket_hash, = {}) tid = nil t = Ticket.new(base, ) t.ticket_name = ticket_name basic_title, date = self.parse_ticket_name(ticket_name) # t.title will be overridden below if the file TICKET_TITLE exists t.title = basic_title t.opened = date ticket_hash['files'].each do |fname, value| if fname == 'TICKET_ID' t.ticket_id = value elsif fname == 'TICKET_TITLE' t.title = base.git.gblob(value).contents rescue nil elsif fname == 'TICKET_DESCRIPTION' t.description = base.git.gblob(value).contents rescue nil else # matching data = fname.split('_') if data[0] == 'ASSIGNED' t.assigned = data[1] end if data[0] == 'COMMENT' t.comments << TicGit::Comment.new(base, fname, value) end if data[0] == 'TAG' t. << data[1] end if data[0] == 'STATE' t.state = data[1] end end end t end |
.parse_ticket_name(name) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/ticgit/ticket.rb', line 73 def self.parse_ticket_name(name) unless name =~ /^([^_]+)_(.+)_([^_]+)$/ raise "invalid ticket name #{name.inspect}" end epoch, title, rand = $1, $2.gsub('-', ' '), $3 return [title, Time.at(epoch.to_i)] end |
Instance Method Details
#add_comment(comment) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ticgit/ticket.rb', line 122 def add_comment(comment) return false if !comment base.in_branch do |wd| Dir.chdir(ticket_name) do base.new_file(comment_name(email), comment) end base.git.add base.git.commit("added comment to ticket #{ticket_name}") end end |
#add_tag(tag) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/ticgit/ticket.rb', line 161 def add_tag(tag) return false if !tag added = false = tag.split(',').map { |t| t.strip } base.in_branch do |wd| Dir.chdir(ticket_name) do .each do |add_tag| if add_tag.size > 0 tag_filename = 'TAG_' + Ticket.clean_string(add_tag) if !File.exists?(tag_filename) base.new_file(tag_filename, tag_filename) added = true end end end end if added base.git.add base.git.commit("added tags (#{tag}) to ticket #{ticket_name}") end end end |
#assigned_name ⇒ Object
214 215 216 |
# File 'lib/ticgit/ticket.rb', line 214 def assigned_name assigned.split('@').first rescue '' end |
#change_assigned(new_assigned) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ticgit/ticket.rb', line 147 def change_assigned(new_assigned) new_assigned ||= email return false if new_assigned == assigned base.in_branch do |wd| Dir.chdir(ticket_name) do base.new_file('ASSIGNED_' + new_assigned, new_assigned) end base.git.remove(File.join(ticket_name,'ASSIGNED_' + assigned)) base.git.add base.git.commit("assigned #{new_assigned} to ticket #{ticket_name}") end end |
#change_state(new_state) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ticgit/ticket.rb', line 133 def change_state(new_state) return false if !new_state return false if new_state == state base.in_branch do |wd| Dir.chdir(ticket_name) do base.new_file('STATE_' + new_state, new_state) end base.git.remove(File.join(ticket_name,'STATE_' + state)) base.git.add base.git.commit("added state (#{new_state}) to ticket #{ticket_name}") end end |
#comment_name(email) ⇒ Object
206 207 208 |
# File 'lib/ticgit/ticket.rb', line 206 def comment_name(email) 'COMMENT_' + Time.now.to_i.to_s + '_' + email end |
#email ⇒ Object
210 211 212 |
# File 'lib/ticgit/ticket.rb', line 210 def email opts[:user_email] || 'anon' end |
#path ⇒ Object
202 203 204 |
# File 'lib/ticgit/ticket.rb', line 202 def path File.join(state, ticket_name) end |
#remove_tag(tag) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/ticgit/ticket.rb', line 184 def remove_tag(tag) return false if !tag removed = false = tag.split(',').map { |t| t.strip } base.in_branch do |wd| .each do |add_tag| tag_filename = File.join(ticket_name, 'TAG_' + Ticket.clean_string(add_tag)) if File.exists?(tag_filename) base.git.remove(tag_filename) removed = true end end if removed base.git.commit("removed tags (#{tag}) from ticket #{ticket_name}") end end end |
#save_new ⇒ Object
write this ticket to the git database
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ticgit/ticket.rb', line 82 def save_new base.in_branch do |wd| base.logger.info "saving #{ticket_name}" Dir.mkdir(ticket_name) Dir.chdir(ticket_name) do base.new_file('TICKET_ID', ticket_name) base.new_file('ASSIGNED_' + email, email) base.new_file('STATE_' + state, state) base.new_file('TICKET_TITLE',self.title) base.new_file('TICKET_DESCRIPTION',self.description) if self.description # add initial comment #COMMENT_080315060503045__schacon_at_gmail base.new_file(comment_name(email), opts[:comment]) if opts[:comment] # add initial tags if opts[:tags] && opts[:tags].size > 0 opts[:tags] = opts[:tags].map { |t| t.strip }.compact opts[:tags].each do |tag| if tag.size > 0 tag_filename = 'TAG_' + Ticket.clean_string(tag) if !File.exists?(tag_filename) base.new_file(tag_filename, tag_filename) end end end end end base.git.add base.git.commit("added ticket #{ticket_name}") end # ticket_id end |