Class: Toolshed::PivotalTracker

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/toolshed/pivotal_tracker.rb

Constant Summary collapse

STORY_STATUS_DEFAULT =
'finished'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PivotalTracker

Returns a new instance of PivotalTracker.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/toolshed/pivotal_tracker.rb', line 9

def initialize(options={})
  username = Toolshed::Client::pivotal_tracker_username
  password = Toolshed::Client::pivotal_tracker_password

  unless (options[:username].nil?)
    username = options[:username]
  end

  unless (options[:password].nil?)
     password = options[:password]
  end


  self.token = ::PivotalTracker::Client.token(username, password)

  self.project_id = (options[:project_id].nil?) ? Toolshed::Client.default_pivotal_tracker_project_id : options[:project_id]
  @pt_project = ::PivotalTracker::Project.find(self.project_id)
end

Instance Attribute Details

#project_idObject

Returns the value of attribute project_id.



7
8
9
# File 'lib/toolshed/pivotal_tracker.rb', line 7

def project_id
  @project_id
end

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/toolshed/pivotal_tracker.rb', line 7

def token
  @token
end

Class Method Details

.passwordObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/toolshed/pivotal_tracker.rb', line 74

def self.password
  password = Toolshed::Client::pivotal_tracker_password
  if (password.nil?)
    # prompt to ask for password
    system "stty -echo"
    puts "PivotalTracker password? "
    password = $stdin.gets.chomp.strip
    system "stty echo"
  end

  return password
end

.story_id_from_branch_name(branch_name) ⇒ Object



28
29
30
# File 'lib/toolshed/pivotal_tracker.rb', line 28

def self.story_id_from_branch_name(branch_name)
  story_id = branch_name.split("_")[0]
end

.usernameObject



63
64
65
66
67
68
69
70
71
72
# File 'lib/toolshed/pivotal_tracker.rb', line 63

def self.username
  username = Toolshed::Client::pivotal_tracker_username
  if (username.nil?)
    # prompt to ask for username
    puts "PivotalTracker username? "
    username = $stdin.gets.chomp.strip
  end

  return username
end

Instance Method Details

#add_note(story_id, note_text) ⇒ Object



36
37
38
39
# File 'lib/toolshed/pivotal_tracker.rb', line 36

def add_note(story_id, note_text)
  story = @pt_project.stories.find(story_id)
  results = story.notes.create(text: note_text)
end

#story_information(story_id) ⇒ Object



32
33
34
# File 'lib/toolshed/pivotal_tracker.rb', line 32

def (story_id)
  return @pt_project.stories.find(story_id)
end

#update_story_state(story_id, current_state, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/toolshed/pivotal_tracker.rb', line 41

def update_story_state(story_id, current_state, options={})
  options.merge!({
    :headers => {
        "X-TrackerToken"  => self.token,
        "User-Agent"      => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17",
        "Content-Type"    => "application/json",
    },
    body: {
      current_state: current_state
    }.to_json
  })

  response = HTTParty.put("#{Toolshed::Client::PIVOTAL_TRACKER_BASE_API_URL}projects/#{self.project_id}/stories/#{story_id}", options).response
  response = JSON.parse(response.body)

  if (response["error"].nil?)
    response
  else
    raise "validation errors #{response.inspect}"
  end
end