Class: Jira::Handler

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

Instance Method Summary collapse

Constructor Details

#initialize(jira_mapper = nil, jira_api = nil) ⇒ Handler

Returns a new instance of Handler.



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

def initialize(jira_mapper = nil, jira_api = nil)
  @mapper = jira_mapper || StoryMapper.new
  @api = jira_api || ApiConsumer.new
end

Instance Method Details

#configure!(config) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jira.rb', line 19

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

  settings.define :username, :required => true, :env_var => 'JIRA_USERNAME'
  settings.define :password, :required => true, :env_var => 'JIRA_PASSWORD'
  settings.define :url, :required => true
  settings.define :project, :required => true
  settings.define :mappings, :required => false

  settings.defaults api_version: 'latest', default_labels: '', mappings: {}

  settings.use(config)
  settings.resolve!

  @mapper.configure!(settings)
  @config = settings
end

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

Yields:

  • (success, message)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/jira.rb', line 37

def handle(yaml_story)
  @api.configure!(@config[:url], @config[:username], @config[:password], @config[:api_version])

  yaml_story['project'] = @config[:project]
  yaml_story['reporter'] = @config[:username] unless yaml_story.key?('reporter')

  issue = @mapper.map(yaml_story)

  success, response_body = @api.create_issue(issue)
  response = JSON.parse response_body

  if success
    message = "Issue key = #{response['key']}, #{@config[:url]}/browse/#{response['key']}"
  else
    message = JSON.pretty_generate response
  end

  yield success, message
end

#supports?(config) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/jira.rb', line 15

def supports?(config)
  config.fetch('tracker', '').downcase == 'jira'
end