Class: Escobar::Heroku::PipelinePromotion

Inherits:
Object
  • Object
show all
Defined in:
lib/escobar/heroku/pipeline_promotion.rb

Overview

Class reperesenting a Heroku Pipeline Promotion

Defined Under Namespace

Classes: MissingContextsError, RequiresTwoFactorError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, pipeline, source, targets, second_factor) ⇒ PipelinePromotion

Returns a new instance of PipelinePromotion.



7
8
9
10
11
12
13
14
# File 'lib/escobar/heroku/pipeline_promotion.rb', line 7

def initialize(client, pipeline, source, targets, second_factor)
  @id = pipeline.id
  @client = client
  @source = source
  @targets = targets
  @pipeline = pipeline
  @second_factor = second_factor
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion.rb', line 5

def client
  @client
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion.rb', line 5

def name
  @name
end

#pipelineObject (readonly)

Returns the value of attribute pipeline.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion.rb', line 5

def pipeline
  @pipeline
end

#second_factorObject (readonly)

Returns the value of attribute second_factor.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion.rb', line 5

def second_factor
  @second_factor
end

#sourceObject (readonly)

Returns the value of attribute source.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion.rb', line 5

def source
  @source
end

#targetsObject (readonly)

Returns the value of attribute targets.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion.rb', line 5

def targets
  @targets
end

Instance Method Details

#bodyObject



48
49
50
51
52
53
54
# File 'lib/escobar/heroku/pipeline_promotion.rb', line 48

def body
  {
    pipeline: { id: id },
    source: { app: { id: source.id } },
    targets: targets.map { |t| { app: { id: t.id } } }
  }
end

#createObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/escobar/heroku/pipeline_promotion.rb', line 20

def create
  response = client.heroku.post(promotion_path, body, second_factor)
  case response["id"]
  when Escobar::UUID_REGEX
    results = Escobar::Heroku::PipelinePromotionTargets.new(
      self, response
    )
    results.releases
  when "two_factor"
    raise_2fa_error
  else
    raise ArgumentError, response.to_json
  end
end

#promotion_pathObject



16
17
18
# File 'lib/escobar/heroku/pipeline_promotion.rb', line 16

def promotion_path
  "/pipeline-promotions"
end

#raise_2fa_errorObject



43
44
45
46
# File 'lib/escobar/heroku/pipeline_promotion.rb', line 43

def raise_2fa_error
  message = "Pipeline requires second factor: #{pipeline.name}"
  raise RequiresTwoFactorError.new_from_build_request(self, message)
end