Class: Testcube::BuildEnv

Inherits:
Object
  • Object
show all
Defined in:
lib/testcube/build_env.rb

Class Method Summary collapse

Class Method Details

.branchObject

TODO: Add support for other CI systems



18
19
20
# File 'lib/testcube/build_env.rb', line 18

def self.branch
  ENV['BUILDKITE_BRANCH'] || git('rev-parse --abbrev-ref HEAD')
end

.build_urlObject



22
23
24
# File 'lib/testcube/build_env.rb', line 22

def self.build_url
  ENV['BUILDKITE_BUILD_URL']
end

.currentObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/testcube/build_env.rb', line 3

def self.current
  sha, author, author_email, commit_message = git_show
  # TODO master fork sha
  # TODO could also get some of this data from github api
  {
    sha: sha,
    author: author,
    author_email: author_email,
    commit_message: commit_message,
    branch: branch,
    build_url: build_url,
  }
end

.git(cmd) ⇒ Object



39
40
41
42
43
# File 'lib/testcube/build_env.rb', line 39

def self.git(cmd)
  `git #{cmd}`.strip
rescue Errno::ENOENT
  nil
end

.git_showObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/testcube/build_env.rb', line 26

def self.git_show
  out = git('show --format=short --no-patch')
  return [nil, nil, nil, nil] if !out

  # TODO: dont rescue nil
  sha = out.match(/commit ([0-9a-f]+)\n/)[1] rescue nil
  author = out.match(/Author: (.*?) <(.*)>\n/)[1] rescue nil
  author_email = out.match(/Author: (.*?) <(.*)>\n/)[2] rescue nil
  message = out.lines[2..(out.lines.length)].find { |l| l.strip.length > 0 }.strip rescue nil

  return [sha, author, author_email, message]
end