Class: TerraspaceCiCircleci::Interface

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

Instance Method Summary collapse

Instance Method Details

#build_typeObject



43
44
45
# File 'lib/terraspace_ci_circleci/interface.rb', line 43

def build_type
  ENV['CIRCLE_PULL_REQUEST'] ? 'pull_request' : 'push'
end

#full_repoObject

IE: [email protected]:ORG/REPO.git



33
34
35
36
37
38
39
40
41
# File 'lib/terraspace_ci_circleci/interface.rb', line 33

def full_repo
  url = ENV['CIRCLE_REPOSITORY_URL']
  full_repo = if url.include?(':')
    url.split(':').last
  else
    URI(url).path.sub(%r{^/},'')
  end
  full_repo.sub('.git','')
end

#hostObject

IE: CIRCLE_BUILD_URL=circleci.com/gh/ORG/REPO/7



27
28
29
30
# File 'lib/terraspace_ci_circleci/interface.rb', line 27

def host
  uri = URI(ENV['CIRCLE_BUILD_URL'])
  "#{uri.scheme}://#{uri.host}"
end

#pr_numberObject

CIRCLE_PULL_REQUEST=github.com/ORG/REPO/pull/2



48
49
50
51
# File 'lib/terraspace_ci_circleci/interface.rb', line 48

def pr_number
  pr = ENV['CIRCLE_PULL_REQUEST']
  pr.split('/').last if pr
end

#varsObject

Interface method. Returns Hash of properties.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/terraspace_ci_circleci/interface.rb', line 6

def vars
  {
    build_system: "circleci",
    host: host,
    full_repo: full_repo,
    branch_name: ENV['CIRCLE_BRANCH'],
    # urls
    pr_url: ENV['CIRCLE_PULL_REQUEST'],
    build_url: ENV['CIRCLE_BUILD_URL'],
    # additional properties
    build_type: build_type,
    pr_number: pr_number,
    sha: ENV['CIRCLE_SHA1'],
    # additional properties
    # commit_message: ENV['REPLACE_ME'],
    build_id: ENV['CIRCLE_BUILD_NUM'],
    build_number: ENV['CIRCLE_BUILD_NUM'],
  }
end