Class: BambooApi::Plan

Inherits:
BambooApi show all
Defined in:
lib/bamboo_api/plan.rb

Constant Summary

Constants inherited from BambooApi

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BambooApi

compose_url, request

Constructor Details

#initialize(short_name, short_key, type, enabled, link, key, name, is_favourite = nil, is_active = nil, is_building = nil, average_build_time = nil, actions = nil, stages = nil, branches = nil) ⇒ Plan

Returns a new instance of Plan.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bamboo_api/plan.rb', line 7

def initialize short_name, short_key, type, enabled, link, key, name, is_favourite=nil, 
  is_active=nil, is_building=nil, average_build_time=nil, actions=nil, stages=nil, branches=nil

  @short_name = short_name
  @short_key = short_key
  @type = type
  @enabled = enabled
  @link = link
  @key = key
  @name = name

  # optional
  @is_favourite = is_favourite
  @is_active = is_active
  @is_building = is_building
  @average_build_time = average_build_time
  @actions = actions
  @stages = stages
  @branches = branches
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def actions
  @actions
end

#average_build_timeObject (readonly)

Returns the value of attribute average_build_time.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def average_build_time
  @average_build_time
end

#branchesObject (readonly)

Returns the value of attribute branches.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def branches
  @branches
end

#builds_cacheObject (readonly)

Returns the value of attribute builds_cache.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def builds_cache
  @builds_cache
end

#enabledObject (readonly)

Returns the value of attribute enabled.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def enabled
  @enabled
end

#is_activeObject (readonly)

Returns the value of attribute is_active.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def is_active
  @is_active
end

#is_buildingObject (readonly)

Returns the value of attribute is_building.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def is_building
  @is_building
end

#is_favouriteObject (readonly)

Returns the value of attribute is_favourite.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def is_favourite
  @is_favourite
end

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def key
  @key
end

Returns the value of attribute link.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def link
  @link
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def name
  @name
end

#short_keyObject (readonly)

Returns the value of attribute short_key.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def short_key
  @short_key
end

#short_nameObject (readonly)

Returns the value of attribute short_name.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def short_name
  @short_name
end

#stagesObject (readonly)

Returns the value of attribute stages.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def stages
  @stages
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/bamboo_api/plan.rb', line 3

def type
  @type
end

Class Method Details

.allObject



85
86
87
# File 'lib/bamboo_api/plan.rb', line 85

def self.all
  BambooApi::Plan.parse( BambooApi.request "plan" )
end

.find(key) ⇒ Object



89
90
91
# File 'lib/bamboo_api/plan.rb', line 89

def self.find key
  BambooApi::Plan.parse_single( BambooApi.request "plan/#{key}" )
end

.parse(plans) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/bamboo_api/plan.rb', line 68

def self.parse plans
  parsed_plans = []

  plans[ "plans" ][ "plan" ].each do | plan |
    parsed_plans.push( BambooApi::Plan.parse_single( plan ) )
  end

  parsed_plans
end

.parse_single(plan) ⇒ Object



78
79
80
81
82
83
# File 'lib/bamboo_api/plan.rb', line 78

def self.parse_single plan
  BambooApi::Plan.new plan[ "shortName" ], plan[ "shortKey" ], plan[ "type" ], 
    plan[ "enabled" ], plan[ "link" ], plan[ "key" ], plan[ "name" ], plan[ "isFavourite" ],
    plan[ "isActive" ], plan[ "isBuilding" ], plan[ "averageBuildTimeInSeconds" ], plan[ "actions" ],
    plan[ "stages" ], plan[ "branches" ]
end

Instance Method Details

#building?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/bamboo_api/plan.rb', line 33

def building?
  self.is_building
end

#buildsObject



28
29
30
31
# File 'lib/bamboo_api/plan.rb', line 28

def builds
  @builds_cache = BambooApi::Build.find_by_plan self.key if @builds_cache.nil?
  @builds_cache   
end

#failed?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
# File 'lib/bamboo_api/plan.rb', line 47

def failed?
  is_failed = false

  if !self.building?
    is_failed = self.builds.first.failed? rescue false
  end

  is_failed
end

#readable_statusObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/bamboo_api/plan.rb', line 57

def readable_status
  if self.building?
    "#{self.name} is currently building."
  elsif self.successful?
    "#{self.name} is currently open and it is safe to commit."
  elsif self.failed?
    last_build = self.builds.first
    "#{self.name} is currently broken due to failing #{last_build.failing_stage.name} committed by #{ last_build.username }"
  end
end

#successful?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
# File 'lib/bamboo_api/plan.rb', line 37

def successful?
  is_successful = false

  if !self.building?
    is_successful = self.builds.first.successful?# rescue false
  end

  is_successful
end