percy-client 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/percy/client/environment.rb +21 -12
- data/lib/percy/client/version.rb +1 -1
- data/spec/lib/percy/client/environment_spec.rb +15 -7
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d2b12edbcf92649f7f63cf396884d852332bb38
|
4
|
+
data.tar.gz: 4ebf745962d67e4bc58fa5b636c9d6b6f211aa49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c29f557ff8cadba3b55e721b72fe0cd29493e2f4fc9ce6490d1cbff7ce43e5d8bd81002665923c45adb808ba364b6acb670bdb4e37da0f12c8e21fd0a1d244f
|
7
|
+
data.tar.gz: 2a5363ce9f0a34254a6495bb8cb8e219de99057caa1035d885106851ac85cb748847ed32fb4bfce1c5dd38e91e5d2e1312cbf8f26b88d60254f5beab66fb90af
|
@@ -25,19 +25,29 @@ module Percy
|
|
25
25
|
# @return [Hash] All commit data from the current commit. Might be empty if commit data could
|
26
26
|
# not be found.
|
27
27
|
def self.commit
|
28
|
-
output = _raw_commit_output(_commit_sha)
|
28
|
+
output = _raw_commit_output(_commit_sha) if _commit_sha
|
29
29
|
output = _raw_commit_output('HEAD') if !output
|
30
|
-
return {branch: branch} if !output
|
31
30
|
|
31
|
+
# Use the specified SHA or, if not given, the parsed SHA at HEAD.
|
32
|
+
commit_sha = _commit_sha || output && output.match(/COMMIT_SHA:(.*)/)[1]
|
33
|
+
|
34
|
+
# If not running in a git repo, allow nils for certain commit attributes.
|
35
|
+
extract_or_nil = lambda { |regex| (output && output.match(regex) || [])[1] }
|
32
36
|
data = {
|
33
|
-
|
37
|
+
# The only required attribute:
|
34
38
|
branch: branch,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
# An optional but important attribute:
|
40
|
+
sha: commit_sha,
|
41
|
+
|
42
|
+
# Optional attributes:
|
43
|
+
message: extract_or_nil.call(/COMMIT_MESSAGE:(.*)/m),
|
44
|
+
committed_at: extract_or_nil.call(/COMMITTED_DATE:(.*)/),
|
45
|
+
# These GIT_ environment vars are from the Jenkins Git Plugin, but could be
|
46
|
+
# used generically. This behavior may change in the future.
|
47
|
+
author_name: extract_or_nil.call(/AUTHOR_NAME:(.*)/) || ENV['GIT_AUTHOR_NAME'],
|
48
|
+
author_email: extract_or_nil.call(/AUTHOR_EMAIL:(.*)/) || ENV['GIT_AUTHOR_EMAIL'],
|
49
|
+
committer_name: extract_or_nil.call(/COMMITTER_NAME:(.*)/) || ENV['GIT_COMMITTER_NAME'],
|
50
|
+
committer_email: extract_or_nil.call(/COMMITTER_EMAIL:(.*)/) || ENV['GIT_COMMITTER_EMAIL'],
|
41
51
|
}
|
42
52
|
end
|
43
53
|
|
@@ -47,15 +57,14 @@ module Percy
|
|
47
57
|
|
48
58
|
case current_ci
|
49
59
|
when :jenkins
|
50
|
-
|
60
|
+
# Pull Request Builder Plugin OR Git Plugin.
|
61
|
+
ENV['ghprbActualCommit'] || ENV['GIT_COMMIT']
|
51
62
|
when :travis
|
52
63
|
ENV['TRAVIS_COMMIT']
|
53
64
|
when :circle
|
54
65
|
ENV['CIRCLE_SHA1']
|
55
66
|
when :codeship
|
56
67
|
ENV['CI_COMMIT_ID']
|
57
|
-
else
|
58
|
-
'HEAD'
|
59
68
|
end
|
60
69
|
end
|
61
70
|
|
data/lib/percy/client/version.rb
CHANGED
@@ -73,8 +73,8 @@ RSpec.describe Percy::Client::Environment do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
describe '#_commit_sha' do
|
76
|
-
it '
|
77
|
-
expect(Percy::Client::Environment._commit_sha).to
|
76
|
+
it 'returns nil if no environment info can be found' do
|
77
|
+
expect(Percy::Client::Environment._commit_sha).to be_nil
|
78
78
|
end
|
79
79
|
it 'can be overridden with PERCY_COMMIT' do
|
80
80
|
ENV['PERCY_COMMIT'] = 'test-commit'
|
@@ -277,22 +277,30 @@ RSpec.describe Percy::Client::Environment do
|
|
277
277
|
describe '#commit' do
|
278
278
|
it 'returns current local commit data' do
|
279
279
|
commit = Percy::Client::Environment.commit
|
280
|
+
expect(commit[:branch]).to_not be_empty
|
281
|
+
expect(commit[:sha]).to_not be_empty
|
282
|
+
expect(commit[:sha].length).to eq(40)
|
283
|
+
|
280
284
|
expect(commit[:author_email]).to match(/.+@.+\..+/)
|
281
285
|
expect(commit[:author_name]).to_not be_empty
|
282
|
-
expect(commit[:branch]).to_not be_empty
|
283
286
|
expect(commit[:committed_at]).to_not be_empty
|
284
287
|
expect(commit[:committer_email]).to_not be_empty
|
285
288
|
expect(commit[:committer_name]).to_not be_empty
|
286
289
|
expect(commit[:message]).to_not be_empty
|
287
|
-
expect(commit[:sha]).to_not be_empty
|
288
|
-
expect(commit[:sha].length).to eq(40)
|
289
290
|
end
|
290
291
|
it 'returns only branch if commit data cannot be found' do
|
291
|
-
expect(Percy::Client::Environment).to receive(:_raw_commit_output).
|
292
|
+
expect(Percy::Client::Environment).to receive(:_raw_commit_output).once.and_return(nil)
|
292
293
|
|
293
294
|
commit = Percy::Client::Environment.commit
|
294
|
-
expect(commit.length).to eq(1)
|
295
295
|
expect(commit[:branch]).to be
|
296
|
+
expect(commit[:sha]).to be_nil
|
297
|
+
|
298
|
+
expect(commit[:author_email]).to be_nil
|
299
|
+
expect(commit[:author_name]).to be_nil
|
300
|
+
expect(commit[:committed_at]).to be_nil
|
301
|
+
expect(commit[:committer_email]).to be_nil
|
302
|
+
expect(commit[:committer_name]).to be_nil
|
303
|
+
expect(commit[:message]).to be_nil
|
296
304
|
end
|
297
305
|
end
|
298
306
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percy-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
171
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
172
|
+
rubygems_version: 2.2.2
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: Percy::Client
|
@@ -190,4 +190,3 @@ test_files:
|
|
190
190
|
- spec/lib/percy_spec.rb
|
191
191
|
- spec/spec_helper.rb
|
192
192
|
- spec/support/vcr_setup.rb
|
193
|
-
has_rdoc:
|