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
- .pr ⇒ Object
Class Method Details
.branch ⇒ Object
TODO: Add support for other CI systems
17 18 19 |
# File 'lib/testcube/build_env.rb', line 17 def self.branch ENV['BUILDKITE_BRANCH'] || git('rev-parse --abbrev-ref HEAD') end |
.build_url ⇒ Object
25 26 27 |
# File 'lib/testcube/build_env.rb', line 25 def self.build_url ENV['BUILDKITE_BUILD_URL'] end |
.current ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/testcube/build_env.rb', line 5 def self.current # TODO could also get some of this data from github api { branch: branch, pr: pr, build_url: build_url, head: parse_from_git('HEAD'), merge_base: parse_from_git(merge_base) } end |
.git(cmd) ⇒ Object
47 48 49 50 51 |
# File 'lib/testcube/build_env.rb', line 47 def self.git(cmd) `git #{cmd}`.strip rescue Errno::ENOENT nil end |
.merge_base ⇒ Object
43 44 45 |
# File 'lib/testcube/build_env.rb', line 43 def self.merge_base git("merge-base HEAD master") end |
.parse_from_git(sha) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/testcube/build_env.rb', line 29 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 |
.pr ⇒ Object
21 22 23 |
# File 'lib/testcube/build_env.rb', line 21 def self.pr ENV['BUILDKITE_PULL_REQUEST'] end |