Class: Ditz::Operator
Defined Under Namespace
Classes: Error
Class Method Summary collapse
- .build_args(project, method, args) ⇒ Object
- .has_operation?(op) ⇒ Boolean
- .method_to_op(meth) ⇒ Object
- .op_to_method(op) ⇒ Object
- .operation(method, desc, *args_spec) ⇒ Object
- .operations ⇒ Object
- .parse_releases_arg(project, releases_arg) ⇒ Object
Instance Method Summary collapse
- #actually_do_todo(project, config, releases, full) ⇒ Object
- #add(project, config) ⇒ Object
- #add_component(project, config) ⇒ Object
- #add_reference(project, config, issue) ⇒ Object
- #add_release(project, config) ⇒ Object
- #assign(project, config, issue) ⇒ Object
- #changelog(project, config, r) ⇒ Object
- #close(project, config, issue) ⇒ Object
- #comment(project, config, issue) ⇒ Object
- #do(op, project, config, args) ⇒ Object
- #drop(project, config, issue) ⇒ Object
- #edit(project, config, issue) ⇒ Object
- #format_log_events(events) ⇒ Object
- #grep(project, config, match) ⇒ Object
- #help(project, config, command) ⇒ Object
- #help_single(command) ⇒ Object
- #html(project, config, dir) ⇒ Object
- #init ⇒ Object
- #log(project, config) ⇒ Object
- #release(project, config, release) ⇒ Object
- #releases(project, config) ⇒ Object
- #show(project, config, issue) ⇒ Object
- #start(project, config, issue) ⇒ Object
- #status(project, config, releases) ⇒ Object
- #status_bar_for(issues) ⇒ Object
- #stop(project, config, issue) ⇒ Object
- #todo(project, config, releases) ⇒ Object
- #todo_full(project, config, releases) ⇒ Object
- #todo_list_for(issues) ⇒ Object
- #unassign(project, config, issue) ⇒ Object
- #validate(project, config) ⇒ Object
Class Method Details
.build_args(project, method, args) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/operator.rb', line 58 def build_args project, method, args command = "command '#{method_to_op method}'" built_args = @operations[method][:args_spec].map do |spec| val = args.shift case spec when :issue raise Error, "#{command} requires an issue name" unless val project.issue_for(val) or raise Error, "no issue with name #{val}" when :release raise Error, "#{command} requires a release name" unless val project.release_for(val) or raise Error, "no release with name #{val}" when :maybe_release parse_releases_arg project, val when :string raise Error, "#{command} requires a string" unless val val else val # no translation for other types end end raise Error, "too many arguments for #{command}" unless args.empty? built_args end |
.has_operation?(op) ⇒ Boolean
21 |
# File 'lib/operator.rb', line 21 def has_operation? op; @operations.member? op_to_method(op) end |
.method_to_op(meth) ⇒ Object
10 |
# File 'lib/operator.rb', line 10 def method_to_op meth; meth.to_s.gsub("_", "-") end |
.op_to_method(op) ⇒ Object
11 |
# File 'lib/operator.rb', line 11 def op_to_method op; op.gsub("-", "_").intern end |
.operation(method, desc, *args_spec) ⇒ Object
13 14 15 16 |
# File 'lib/operator.rb', line 13 def operation method, desc, *args_spec @operations ||= {} @operations[method] = { :desc => desc, :args_spec => args_spec } end |
.operations ⇒ Object
18 19 20 |
# File 'lib/operator.rb', line 18 def operations @operations.map { |k, v| [method_to_op(k), v] }.sort_by { |k, v| k } end |
.parse_releases_arg(project, releases_arg) ⇒ Object
23 24 25 26 27 28 29 30 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 |
# File 'lib/operator.rb', line 23 def parse_releases_arg project, releases_arg ret = [] releases, show_unassigned, force_show = case releases_arg when nil; [project.releases, true, false] when "unassigned"; [[], true, true] else release = project.release_for(releases_arg) raise Error, "no release with name #{releases_arg}" unless release [[release], false, true] end releases.each do |r| next if r.released? unless force_show bugs = project.issues. select { |i| i.type == :bugfix && i.release == r.name } feats = project.issues. select { |i| i.type == :feature && i.release == r.name } #next if bugs.empty? && feats.empty? unless force_show ret << [r, bugs, feats] end return ret unless show_unassigned bugs = project.issues.select { |i| i.type == :bugfix && i.release.nil? } feats = project.issues.select { |i| i.type == :feature && i.release.nil? } return ret if bugs.empty? && feats.empty? unless force_show ret << [nil, bugs, feats] end |
Instance Method Details
#actually_do_todo(project, config, releases, full) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/operator.rb', line 231 def actually_do_todo project, config, releases, full releases.each do |r, bugs, feats| if r puts "Version #{r.name} (#{r.status}):" else puts "Unassigned:" end issues = bugs + feats issues = issues.select { |i| i.open? } unless full puts(todo_list_for(issues.sort_by { |i| i.sort_order }) || "No open issues.") puts end end |
#add(project, config) ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/operator.rb', line 135 def add project, config issue = Issue.create_interactively(:args => [config, project]) or return comment = ask_multiline "Comments" issue.log "created", config.user, comment project.add_issue issue project.assign_issue_names! puts "Added issue #{issue.name}." end |
#add_component(project, config) ⇒ Object
160 161 162 163 164 |
# File 'lib/operator.rb', line 160 def add_component project, config component = Component.create_interactively(:args => [project, config]) or return project.add_component component puts "Added component #{component.name}." end |
#add_reference(project, config, issue) ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/operator.rb', line 167 def add_reference project, config, issue puts "Adding a reference to #{issue.name}: #{issue.title}." reference = ask "Reference" comment = ask_multiline "Comments" issue.add_reference reference issue.log "added reference #{issue.references.size}", config.user, comment puts "Added reference to #{issue.name}." end |
#add_release(project, config) ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/operator.rb', line 151 def add_release project, config release = Release.create_interactively(:args => [project, config]) or return comment = ask_multiline "Comments" release.log "created", config.user, comment project.add_release release puts "Added release #{release.name}." end |
#assign(project, config, issue) ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/operator.rb', line 303 def assign project, config, issue puts "Issue #{issue.name} currently " + if issue.release "assigned to release #{issue.release}." else "not assigned to any release." end releases = project.releases.sort_by { |r| (r.release_time || 0).to_i } releases -= [releases.find { |r| r.name == issue.release }] if issue.release release = ask_for_selection(releases, "release") do |r| r.name + if r.released? " (released #{r.release_time.pretty_date})" else " (unreleased)" end end comment = ask_multiline "Comments" issue.assign_to_release release, config.user, comment puts "Assigned #{issue.name} to #{release.name}." end |
#changelog(project, config, r) ⇒ Object
357 358 359 360 361 362 |
# File 'lib/operator.rb', line 357 def changelog project, config, r feats, bugs = project.issues_for_release(r).partition { |i| i.feature? } puts "== #{r.name} / #{r.released? ? r.release_time.pretty_date : 'unreleased'}" feats.select { |f| f.closed? }.each { |i| puts "* #{i.title}" } bugs.select { |f| f.closed? }.each { |i| puts "* bugfix: #{i.title}" } end |
#close(project, config, issue) ⇒ Object
294 295 296 297 298 299 300 |
# File 'lib/operator.rb', line 294 def close project, config, issue puts "Closing issue #{issue.name}: #{issue.title}." disp = ask_for_selection Issue::DISPOSITIONS, "disposition", lambda { |x| Issue::DISPOSITION_STRINGS[x] || x.to_s } comment = ask_multiline "Comments" issue.close disp, config.user, comment puts "Closed issue #{issue.name} with disposition #{issue.disposition_string}." end |
#comment(project, config, issue) ⇒ Object
333 334 335 336 337 338 |
# File 'lib/operator.rb', line 333 def comment project, config, issue puts "Commenting on issue #{issue.name}: #{issue.title}." comment = ask_multiline "Comments" issue.log "commented", config.user, comment puts "Comments recorded for #{issue.name}." end |
#do(op, project, config, args) ⇒ Object
83 84 85 86 87 |
# File 'lib/operator.rb', line 83 def do op, project, config, args meth = self.class.op_to_method(op) built_args = self.class.build_args project, meth, args send meth, project, config, *built_args end |
#drop(project, config, issue) ⇒ Object
145 146 147 148 |
# File 'lib/operator.rb', line 145 def drop project, config, issue project.drop_issue issue puts "Dropped #{issue.name}. Note that other issue names may have changed." end |
#edit(project, config, issue) ⇒ Object
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/operator.rb', line 460 def edit project, config, issue data = { :title => issue.title, :description => issue.desc, :reporter => issue.reporter } fn = run_editor { |f| f.puts data.to_yaml } unless fn puts "Aborted." return end comment = ask_multiline "Comments" begin edits = YAML.load_file fn if issue.change edits, config.user, comment puts "Changed recorded." else puts "No changes." end end end |
#format_log_events(events) ⇒ Object
270 271 272 273 274 275 |
# File 'lib/operator.rb', line 270 def format_log_events events return "none" if events.empty? events.map do |time, who, what, comment| "- #{time.pretty} :: #{who}\n #{what}#{comment.multiline " > "}" end.join("\n") end |
#grep(project, config, match) ⇒ Object
436 437 438 439 440 |
# File 'lib/operator.rb', line 436 def grep project, config, match re = /#{match}/ issues = project.issues.select { |i| i.title =~ re || i.desc =~ re } puts(todo_list_for(issues) || "No matching issues.") end |
#help(project, config, command) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/operator.rb', line 99 def help project, config, command return help_single(command) if command puts <<EOS Ditz commands: EOS ops = self.class.operations len = ops.map { |name, op| name.to_s.length }.max ops.each do |name, opts| printf " %#{len}s: %s\n", name, opts[:desc] end puts <<EOS Use 'ditz help <command>' for details. EOS end |
#help_single(command) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/operator.rb', line 116 def help_single command name, opts = self.class.operations.find { |name, spec| name == command } raise Error, "no such ditz command '#{command}'" unless name args = opts[:args_spec].map do |spec| case spec.to_s when /^maybe_(.*)$/ "[#{$1}]" else "<#{spec.to_s}>" end end.join(" ") puts <<EOS #{opts[:desc]}. Usage: ditz #{name} #{args} EOS end |
#html(project, config, dir) ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/operator.rb', line 365 def html project, config, dir dir ||= "html" Dir.mkdir dir unless File.exists? dir ## find the ERB templates. this is my brilliant approach ## to the 'gem datadir' problem. template_dir = $:.find { |p| File.exists? File.join(p, "index.rhtml") } FileUtils.cp File.join(template_dir, "style.css"), dir ## build up links links = {} project.releases.each { |r| links[r] = "release-#{r.name}.html" } project.issues.each { |i| links[i] = "issue-#{i.id}.html" } project.components.each { |c| links[c] = "component-#{c.name}.html" } links["unassigned"] = "unassigned.html" # special case: unassigned links["index"] = "index.html" # special case: index project.issues.each do |issue| fn = File.join dir, links[issue] puts "Generating #{fn}..." File.open(fn, "w") do |f| f.puts ErbHtml.new(template_dir, "issue", links, :issue => issue, :release => (issue.release ? project.release_for(issue.release) : nil), :component => project.component_for(issue.component), :project => project) end end project.releases.each do |r| fn = File.join dir, links[r] puts "Generating #{fn}..." File.open(fn, "w") do |f| f.puts ErbHtml.new(template_dir, "release", links, :release => r, :issues => project.issues_for_release(r), :project => project) end end project.components.each do |c| fn = File.join dir, links[c] puts "Generating #{fn}..." File.open(fn, "w") do |f| f.puts ErbHtml.new(template_dir, "component", links, :component => c, :issues => project.issues_for_component(c), :project => project) end end fn = File.join dir, links["unassigned"] puts "Generating #{fn}..." File.open(fn, "w") do |f| f.puts ErbHtml.new(template_dir, "unassigned", links, :issues => project.unassigned_issues, :project => project) end past_rels, upcoming_rels = project.releases.partition { |r| r.released? } fn = File.join dir, links["index"] puts "Generating #{fn}..." File.open(fn, "w") do |f| f.puts ErbHtml.new(template_dir, "index", links, :project => project, :past_releases => past_rels, :upcoming_releases => upcoming_rels, :components => project.components) end puts "Local generated URL: file://#{File.(fn)}" end |
#init ⇒ Object
94 95 96 |
# File 'lib/operator.rb', line 94 def init Project.create_interactively end |
#log(project, config) ⇒ Object
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/operator.rb', line 443 def log project, config project.issues.map { |i| i.log_events.map { |e| [e, i] } }. flatten_one_level.sort_by { |e| e.first.first }.reverse. each do |(date, , what, comment), i| puts <<EOS date : #{date.localtime} (#{date.ago} ago) author: #{} #{i.name}: #{i.title} #{what} #{comment.multiline " "} EOS puts unless comment.blank? end end |
#release(project, config, release) ⇒ Object
350 351 352 353 354 |
# File 'lib/operator.rb', line 350 def release project, config, release comment = ask_multiline "Comments" release.release! project, config.user, comment puts "Release #{release.name} released!" end |
#releases(project, config) ⇒ Object
341 342 343 344 345 346 347 |
# File 'lib/operator.rb', line 341 def releases project, config a, b = project.releases.partition { |r| r.released? } (b + a.sort_by { |r| r.release_time }).each do |r| status = r.released? ? "released #{r.release_time.pretty_date}" : r.status puts "#{r.name} (#{status})" end end |
#show(project, config, issue) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/operator.rb', line 246 def show project, config, issue status = case issue.status when :closed "#{issue.status_string}: #{issue.disposition_string}" else issue.status_string end puts <<EOS #{"Issue #{issue.name}".underline} Title: #{issue.title} Description: #{issue.interpolated_desc(project.issues).multiline " "} Type: #{issue.type} Status: #{status} Creator: #{issue.reporter} Age: #{issue.creation_time.ago} Release: #{issue.release} References: #{issue.references.listify " "} Identifier: #{issue.id} Event log: #{format_log_events issue.log_events} EOS end |
#start(project, config, issue) ⇒ Object
278 279 280 281 282 283 |
# File 'lib/operator.rb', line 278 def start project, config, issue puts "Starting work on issue #{issue.name}: #{issue.title}." comment = ask_multiline "Comments" issue.start_work config.user, comment puts "Recorded start of work for #{issue.name}." end |
#status(project, config, releases) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/operator.rb', line 177 def status project, config, releases releases.each do |r, bugs, feats| title, = [r ? r.name : "unassigned", (bugs + feats)] ncbugs = bugs.count_of { |b| b.closed? } ncfeats = feats.count_of { |f| f.closed? } pcbugs = 100.0 * (bugs.empty? ? 1.0 : ncbugs.to_f / bugs.size) pcfeats = 100.0 * (feats.empty? ? 1.0 : ncfeats.to_f / feats.size) special = if r && r.released? "(released)" elsif bugs.empty? && feats.empty? "(no issues)" elsif ncbugs == bugs.size && ncfeats == feats.size "(ready for release)" else end printf "%-10s %2d/%2d (%3.0f%%) bugs, %2d/%2d (%3.0f%%) features %s\n", title, ncbugs, bugs.size, pcbugs, ncfeats, feats.size, pcfeats, special end if project.releases.empty? puts "No releases." return end end |
#status_bar_for(issues) ⇒ Object
206 207 208 209 210 211 |
# File 'lib/operator.rb', line 206 def issues Issue::STATUS_WIDGET. sort_by { |k, v| -Issue::STATUS_SORT_ORDER[k] }. map { |k, v| v * issues.count_of { |i| i.status == k } }. join end |
#stop(project, config, issue) ⇒ Object
286 287 288 289 290 291 |
# File 'lib/operator.rb', line 286 def stop project, config, issue puts "Stopping work on issue #{issue.name}: #{issue.title}." comment = ask_multiline "Comments" issue.stop_work config.user, comment puts "Recorded work stop for #{issue.name}." end |
#todo(project, config, releases) ⇒ Object
222 223 224 |
# File 'lib/operator.rb', line 222 def todo project, config, releases actually_do_todo project, config, releases, false end |
#todo_full(project, config, releases) ⇒ Object
227 228 229 |
# File 'lib/operator.rb', line 227 def todo_full project, config, releases actually_do_todo project, config, releases, true end |
#todo_list_for(issues) ⇒ Object
213 214 215 216 217 218 219 |
# File 'lib/operator.rb', line 213 def todo_list_for issues return if issues.empty? name_len = issues.max_of { |i| i.name.length } issues.map do |i| sprintf "%s %#{name_len}s: %s\n", i., i.name, i.title end.join end |
#unassign(project, config, issue) ⇒ Object
325 326 327 328 329 330 |
# File 'lib/operator.rb', line 325 def unassign project, config, issue puts "Unassigning issue #{issue.name}: #{issue.title}." comment = ask_multiline "Comments" issue.unassign config.user, comment puts "Unassigned #{issue.name}." end |
#validate(project, config) ⇒ Object
431 432 433 |
# File 'lib/operator.rb', line 431 def validate project, config ## a no-op end |