Class: Commands::Unblock

Inherits:
Base
  • Object
show all
Defined in:
lib/commands/unblock.rb

Constant Summary collapse

PlaceholderLabel =
"."

Instance Attribute Summary

Attributes inherited from Base

#input, #options, #output

Instance Method Summary collapse

Methods inherited from Base

#get, #put, #sys, #with

Constructor Details

#initialize(*args) ⇒ Unblock

Returns a new instance of Unblock.



8
9
10
11
# File 'lib/commands/unblock.rb', line 8

def initialize(*args)
  @story_id = args.shift if args.first =~ /^(\d+)$/
  super(*args)
end

Instance Method Details

#run!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/commands/unblock.rb', line 13

def run!
  super

  unless story_id
    put "No story id was supplied and you aren't on a topic branch!"
    return 1
  end
  
  unless story.labels.to_s.include?(Block::Label)
    put "Story #{story_id} is already unblocked."
    return 0
  end
  
  labels = story.labels.to_s.split(",") - [Block::Label]
  
  # this line is to work aroudn Pivotal Tracker's broken API for removing the last
  # label on a card. http://community.pivotaltracker.com/pivotal/topics/api_v3_cannot_remove_labels_from_a_story_anymore
  if labels.empty?
    labels << PlaceholderLabel
    put "Note: a '.' label will be placed on this card due to a bug in the v3 API of Pivotal Tracker."
  end
  
  story.update :labels => labels.join(",")
  put "Story #{story_id} has been unblocked."
  
  return 0
end