Module: Gith::Pivotal

Included in:
Accept, Deliver, Discuss, Estimate, Finish, Reject, Start
Defined in:
lib/gith/adapters/pivotal.rb

Constant Summary collapse

STARTED =
'started'
FINISHED =
'finished'
DELIVERED =
'delivered'
ACCEPTED =
'accepted'
REJECTED =
'rejected'
V5_URL =
'https://www.pivotaltracker.com/services/v5'

Instance Method Summary collapse

Instance Method Details

#accept_story(story) ⇒ Object



25
26
27
# File 'lib/gith/adapters/pivotal.rb', line 25

def accept_story(story)
  story.update current_state: ACCEPTED
end

#compress_comments(story) ⇒ Object



61
62
63
64
65
# File 'lib/gith/adapters/pivotal.rb', line 61

def compress_comments(story)
  ids = hubot_commit_comments(story).map(&:id)
  ids.pop
  ids.each { |id| delete_comment(story, id) }
end

#delete_comment(story, id) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/gith/adapters/pivotal.rb', line 67

def delete_comment(story, id)
  # api v3 does not support note destroys, so using v5 for now
  uri               = URI.parse("#{V5_URL}/projects/#{story.project_id}/stories/#{story.id}/comments/#{id}")
  http              = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl      = true
  http.verify_mode  = OpenSSL::SSL::VERIFY_NONE
  http.delete(uri.path, { 'X-TrackerToken' => config[:pivotal_token] })
end

#deliver_story(story) ⇒ Object



21
22
23
# File 'lib/gith/adapters/pivotal.rb', line 21

def deliver_story(story)
  story.update current_state: DELIVERED
end

#finish_story(story) ⇒ Object



17
18
19
# File 'lib/gith/adapters/pivotal.rb', line 17

def finish_story(story)
  story.update current_state: FINISHED
end

#hubot_commit_comments(story) ⇒ Object



57
58
59
# File 'lib/gith/adapters/pivotal.rb', line 57

def hubot_commit_comments(story)
  story.notes.all.select{ |x| x.author == 'Hubot' && x.text =~ /^Commit by/ }
end

#meObject



76
77
78
79
80
81
82
# File 'lib/gith/adapters/pivotal.rb', line 76

def me
  uri               = URI.parse("#{V5_URL}/me")
  http              = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl      = true
  http.verify_mode  = OpenSSL::SSL::VERIFY_NONE
  JSON.parse http.get(uri.path, { 'X-TrackerToken' => config[:pivotal_token] }).body
end

#project(id) ⇒ Object



41
42
43
44
45
# File 'lib/gith/adapters/pivotal.rb', line 41

def project(id)
  p = projects.detect { |x| x.id.to_i == id.to_i }
  error "Could not find project ##{id}" unless p
  p
end

#project_from_story(id) ⇒ Object



53
54
55
# File 'lib/gith/adapters/pivotal.rb', line 53

def project_from_story(id)
  project(story(id).project_id)
end

#projectsObject



33
34
35
36
37
38
39
# File 'lib/gith/adapters/pivotal.rb', line 33

def projects
  @projects ||= lambda do
    PivotalTracker::Client.token    = config[:pivotal_token]
    PivotalTracker::Client.use_ssl  = true
    PivotalTracker::Project.all
  end.call
end

#start_story(story) ⇒ Object



13
14
15
# File 'lib/gith/adapters/pivotal.rb', line 13

def start_story(story)
  story.update current_state: STARTED
end

#story(id) ⇒ Object



47
48
49
50
51
# File 'lib/gith/adapters/pivotal.rb', line 47

def story(id)
  s = projects.flat_map { |x| x.stories.find(id.to_i) }.compact.first
  error "Could not find story ##{id}" unless s
  s
end

#take_ownership(story) ⇒ Object



29
30
31
# File 'lib/gith/adapters/pivotal.rb', line 29

def take_ownership(story)
  story.update owned_by: me['name']
end