Class: Ehpt::CreateStoryAttributes

Inherits:
Base
  • Object
show all
Defined in:
lib/ehpt/create_story_attributes.rb

Constant Summary collapse

ARRAY_TYPE_ATTRIBUTES =
%w[ labels tasks pull_requests branches blockers comments reviews ]
INT_ARRAY_TYPE_ATTRIBUTES =
%w[ owner_ids label_ids follower_ids ]
INT_TYPE_ATTRIBUTES =
%w[ project_id requested_by_id before_id after_id integration_id ]
FLOAT_TYPE_ATTRIBUES =
%w[ estimate ]

Instance Attribute Summary collapse

Attributes inherited from Base

#data, #errors, #warnings

Instance Method Summary collapse

Methods inherited from Base

#add_error, #add_warning, call, #error?, #success?, #warning?

Constructor Details

#initialize(row) ⇒ CreateStoryAttributes

Returns a new instance of CreateStoryAttributes.



13
14
15
16
# File 'lib/ehpt/create_story_attributes.rb', line 13

def initialize(row)
  @row = row
  super
end

Instance Attribute Details

#rowObject (readonly)

Returns the value of attribute row.



3
4
5
# File 'lib/ehpt/create_story_attributes.rb', line 3

def row
  @row
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ehpt/create_story_attributes.rb', line 18

def call
  story_attrs = row.to_h.compact
  story_attrs.each do |key, value|
    story_attrs[key] = value.to_i if INT_TYPE_ATTRIBUTES.include?(key)
    story_attrs[key] = value.to_f if FLOAT_TYPE_ATTRIBUES.include?(key)
    story_attrs[key] = value.split(',') if ARRAY_TYPE_ATTRIBUTES.include?(key)
    story_attrs[key] = value.split(',').map(&:to_i) if INT_ARRAY_TYPE_ATTRIBUTES.include?(key)
  end

  if story_attrs['story_type'] != 'feature' && !Ehpt.project.bugs_and_chores_are_estimatable
    story_attrs['estimate'] = nil
  end

  if story_attrs.has_key?('requested_by')
    user_id = get_user_id_from(story_attrs.delete('requested_by'))
    story_attrs['requested_by_id'] = user_id unless user_id.nil?
  end

  if story_attrs.has_key?('owners')
    owners = story_attrs.delete('owners').split(',')
    owner_ids = owners.map { |owner| get_user_id_from(owner.strip) }.compact
    story_attrs['owner_ids'] = owner_ids unless owner_ids.empty?
  end

  @data = story_attrs
rescue StandardError => e
  add_error({
    row: row.to_h,
    warnings: e.message
  })
end