Class: PivotalIntegration::Util::Label

Inherits:
Object
  • Object
show all
Defined in:
lib/pivotal-integration/util/label.rb

Overview

Utilities for dealing with the shell

Class Method Summary collapse

Class Method Details

.add(story, *labels) ⇒ boolean

Add labels to story if they are not already appended to story.

Parameters:

  • labels (PivotalTracker::Story, String)

    as Strings, one label per parameter.

Returns:

  • (boolean)

    Boolean defining whether story was updated or not.



25
26
27
28
29
30
31
32
33
34
# File 'lib/pivotal-integration/util/label.rb', line 25

def self.add(story, *labels)
  current_labels = story.labels.split(',') rescue []
  new_labels = current_labels | labels
  if story.update(:labels => new_labels)
    puts "Updated labels on #{story.name}:"
    puts "#{current_labels} => #{new_labels}"
  else
    abort("Failed to update labels on Pivotal Tracker")
  end
end

.list(story) ⇒ boolean

Print labels from story.

Parameters:

  • labels (PivotalTracker::Story, String)

    as Strings, one label per parameter.

Returns:

  • (boolean)

    Boolean defining whether story was updated or not.



68
69
70
71
# File 'lib/pivotal-integration/util/label.rb', line 68

def self.list(story)
  puts "Story labels:"
  puts story.labels.split(',') rescue []
end

.once(story, *labels) ⇒ boolean

Add labels from story and remove those labels from every other story in a project.

Parameters:

  • labels (PivotalTracker::Story, String)

    as Strings, one label per parameter.

Returns:

  • (boolean)

    Boolean defining whether story was updated or not.



40
41
42
43
44
45
46
47
# File 'lib/pivotal-integration/util/label.rb', line 40

def self.once(story, *labels)
  PivotalTracker::Project.find(story.project_id).stories.all.each do |other_story|
    self.remove(other_story, *labels) if story.name != other_story.name and
                                         other_story.labels and
                                         (other_story.labels.split(',') & labels).any?
  end
  self.add(story, *labels)
end

.remove(story, *labels) ⇒ boolean

Remove labels from story.

Parameters:

  • labels (PivotalTracker::Story, String)

    as Strings, one label per parameter.

Returns:

  • (boolean)

    Boolean defining whether story was updated or not.



53
54
55
56
57
58
59
60
61
62
# File 'lib/pivotal-integration/util/label.rb', line 53

def self.remove(story, *labels)
  current_labels = story.labels.split(',') rescue []
  new_labels = current_labels - labels
  if story.update(:labels => new_labels)
    puts "Updated labels on #{story.name}:"
    puts "#{current_labels} => #{new_labels}"
  else
    abort("Failed to update labels on Pivotal Tracker")
  end
end