Class: Pivotal

Inherits:
Object
  • Object
show all
Defined in:
lib/pivotal.rb

Overview

Pivotal handler

Instance Method Summary collapse

Constructor Details

#initialize(pivotal_api = nil) ⇒ Pivotal

Returns a new instance of Pivotal.



6
7
8
# File 'lib/pivotal.rb', line 6

def initialize(pivotal_api = nil)
  @api = pivotal_api || PivotalApi.new
end

Instance Method Details

#configure!(config) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pivotal.rb', line 14

def configure!(config)
  settings = Configliere::Param.new

  settings.define :project_id, :required => true
  settings.define :token, :required => true, :env_var => 'PIVOTAL_TOKEN'

  settings.use(config)
  settings.resolve!

  @config = settings
end

#dump(filter) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pivotal.rb', line 41

def dump(filter)
  @api.configure!(@config.project_id, @config.token)
  @api.stories(filter).each do |story|
    yield YamlStory.new(
        name: story['name'],
        description: story['description'],
        story_type: story['story_type'],
        labels: story['labels'].map{|l| l['name']}.join(', ')
    )
  end
end

#handle(yaml_story) {|success, message| ... } ⇒ Object

Yields:

  • (success, message)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pivotal.rb', line 26

def handle(yaml_story)
  @api.configure!(@config.project_id, @config.token)

  success, response_body = @api.create_story(yaml_story)
  response = JSON.parse response_body

  if success
    message = "Issue ID = #{response['id']}, #{response['url']}"
  else
    message = JSON.pretty_generate response
  end

  yield success, message
end

#supports?(config) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/pivotal.rb', line 10

def supports?(config)
  (config['tracker'] == nil && config['project_id'] != nil) || config.fetch('tracker', '').downcase == 'pivotal'
end