Class: Testcube::BuildEnv
- Inherits:
-
Object
- Object
- Testcube::BuildEnv
- Defined in:
- lib/testcube/build_env.rb
Class Method Summary collapse
-
.branch ⇒ Object
TODO: Add support for other CI systems.
- .build_url ⇒ Object
- .current ⇒ Object
- .git(cmd) ⇒ Object
- .merge_base ⇒ Object
- .parse_from_git(sha) ⇒ Object
Class Method Details
.branch ⇒ Object
TODO: Add support for other CI systems
16 17 18 |
# File 'lib/testcube/build_env.rb', line 16 def self.branch ENV['BUILDKITE_BRANCH'] || git('rev-parse --abbrev-ref HEAD') end |
.build_url ⇒ Object
20 21 22 |
# File 'lib/testcube/build_env.rb', line 20 def self.build_url ENV['BUILDKITE_BUILD_URL'] end |
.current ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/testcube/build_env.rb', line 5 def self.current # TODO could also get some of this data from github api { branch: branch, build_url: build_url, head: parse_from_git('HEAD'), merge_base: parse_from_git(merge_base) } end |
.git(cmd) ⇒ Object
42 43 44 45 46 |
# File 'lib/testcube/build_env.rb', line 42 def self.git(cmd) `git #{cmd}`.strip rescue Errno::ENOENT nil end |
.merge_base ⇒ Object
38 39 40 |
# File 'lib/testcube/build_env.rb', line 38 def self.merge_base git("merge-base HEAD master") end |
.parse_from_git(sha) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/testcube/build_env.rb', line 24 def self.parse_from_git(sha) out = git("show #{sha} --no-patch") return {} if !out # TODO: dont rescue nil return { sha: (out.match(/commit ([0-9a-f]+)\n/)[1] rescue nil), author: (out.match(/Author: (.*?) <(.*)>\n/)[1] rescue nil), ts: (Time.parse(out.match(/Date: (.*?)\n/)[1].strip).to_i rescue nil), author_email: (out.match(/Author: (.*?) <(.*)>\n/)[2] rescue nil), message: (out.lines[3..(out.lines.length)].find { |l| l.strip.length > 0 }.strip[0..50] rescue nil) } end |