Module: Octopusci::Helpers

Defined in:
lib/octopusci/helpers.rb

Class Method Summary collapse

Class Method Details

.decode(str) ⇒ Object



53
54
55
# File 'lib/octopusci/helpers.rb', line 53

def self.decode(str)
  ::MultiJson.decode(str)
end

.encode(str) ⇒ Object



57
58
59
# File 'lib/octopusci/helpers.rb', line 57

def self.encode(str)
  ::MultiJson.encode(str)
end

.get_project_info(project_name, project_owner) ⇒ Object

Get the information specified in the config about this project. If project info can’t be found for the given project_name and project_owner this method returns nil. Otherwise, this project returns a hash of the project info that it found in the config.



44
45
46
47
48
49
50
51
# File 'lib/octopusci/helpers.rb', line 44

def self.get_project_info(project_name, project_owner)
  Octopusci::Config["projects"].each do |proj|
    if (proj['name'] == project_name) && (proj['owner'] == project_owner)
      return proj
    end
  end
  return nil
end

.gh_payload_to_job_attrs(gh_pl) ⇒ Object

Take the github payload hash and translate it to the Job model’s attrs so that we can easily use the github payload hash to update_attributes on the Job mode.l



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/octopusci/helpers.rb', line 6

def self.gh_payload_to_job_attrs(gh_pl)
  attrs = {}
        
  # ref
  attrs['ref'] = gh_pl["ref"]
  attrs['branch_name'] = gh_pl["ref"].split('/').last
  # compare
  attrs['compare'] = gh_pl["compare"]
  # repo_name
  attrs['repo_name'] = gh_pl["repository"]["name"]
  # repo_owner_name
  attrs['repo_owner_name'] = gh_pl["repository"]["owner"]["name"]
  # repo_owner_email
  attrs['repo_owner_email'] = gh_pl["repository"]["owner"]["email"]
  # repo_pushed_at
  attrs['repo_pushed_at'] = gh_pl["repository"]["pushed_at"]
  # repo_created_at
  attrs['repo_created_at'] = gh_pl["repository"]["created_at"]
  # repo_desc
  attrs['repo_desc'] = gh_pl["repository"]["description"]
  # repo_url
  attrs['repo_url'] = gh_pl["repository"]["url"]
  # before_commit
  attrs['before_commit'] = gh_pl["before"]
  # forced
  attrs['forced'] = gh_pl["forced"]
  # after_commit
  attrs['after_commit'] = gh_pl["after"]
  
  attrs['payload'] = gh_pl
  
  return attrs
end

.workspace_path(stage) ⇒ Object



61
62
63
# File 'lib/octopusci/helpers.rb', line 61

def self.workspace_path(stage)
  return Octopusci::Config['general']['workspace_base_path'] + "/#{stage}"
end