percy-client 1.13.7 → 1.13.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/percy/client/environment.rb +20 -11
- data/lib/percy/client/version.rb +1 -1
- data/spec/lib/percy/client/environment_spec.rb +26 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf2ad29ea7519dca29107bb4730ce63b01209658
|
4
|
+
data.tar.gz: d0537050170ed7da2ae408d8e587b8e2a8b4de0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb995b91309f0289a1e823fa2ce9268a7d25649043085a3e71c6fd8c23fcd78461e73b101d4d1b0bcc465aa31037791f0b9d0d920aada58de6565d6bfe885599
|
7
|
+
data.tar.gz: 61aca7740b14dc0f72a19cd62649e89358e65cc6fce77e4bc3d8b541d25b2d9a15e75cb318c03a1954eb175e9f9afe5be404675168addc339148380659413395
|
@@ -29,16 +29,14 @@ module Percy
|
|
29
29
|
# @return [Hash] All commit data from the current commit. Might be empty if commit data could
|
30
30
|
# not be found.
|
31
31
|
def self.commit
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
output = output.force_encoding('UTF-8') if output && output.encoding.to_s == 'US-ASCII'
|
32
|
+
# Try getting data from git itself.
|
33
|
+
# If this has a result, it means git is present in the system.
|
34
|
+
git_data_from_git = _git_commit_output
|
36
35
|
|
37
|
-
|
38
|
-
|
36
|
+
parse = ->(regex) { (git_data_from_git && git_data_from_git.match(regex) || [])[1] }
|
37
|
+
|
38
|
+
commit_sha = _commit_sha || parse.call(/COMMIT_SHA:(.*)/)
|
39
39
|
|
40
|
-
# If not running in a git repo, allow nils for certain commit attributes.
|
41
|
-
parse = ->(regex) { (output && output.match(regex) || [])[1] }
|
42
40
|
{
|
43
41
|
# The only required attribute:
|
44
42
|
branch: branch,
|
@@ -46,10 +44,11 @@ module Percy
|
|
46
44
|
sha: commit_sha,
|
47
45
|
|
48
46
|
# Optional attributes:
|
49
|
-
|
50
|
-
|
51
|
-
# These GIT_ environment vars are from the Jenkins Git Plugin, but could be
|
47
|
+
# If we have the git information, read from those rather than env vars.
|
48
|
+
# The GIT_ environment vars are from the Jenkins Git Plugin, but could be
|
52
49
|
# used generically. This behavior may change in the future.
|
50
|
+
message: parse.call(/COMMIT_MESSAGE:(.*)/),
|
51
|
+
committed_at: parse.call(/COMMITTED_DATE:(.*)/),
|
53
52
|
author_name: parse.call(/AUTHOR_NAME:(.*)/) || ENV['GIT_AUTHOR_NAME'],
|
54
53
|
author_email: parse.call(/AUTHOR_EMAIL:(.*)/) || ENV['GIT_AUTHOR_EMAIL'],
|
55
54
|
committer_name: parse.call(/COMMITTER_NAME:(.*)/) || ENV['GIT_COMMITTER_NAME'],
|
@@ -57,6 +56,16 @@ module Percy
|
|
57
56
|
}
|
58
57
|
end
|
59
58
|
|
59
|
+
# @private
|
60
|
+
def self._git_commit_output
|
61
|
+
raw_git_output = _raw_commit_output(_commit_sha) if _commit_sha
|
62
|
+
raw_git_output ||= _raw_commit_output('HEAD')
|
63
|
+
if raw_git_output && raw_git_output.encoding.to_s == 'US-ASCII'
|
64
|
+
raw_git_output = raw_git_output.force_encoding('UTF-8')
|
65
|
+
end
|
66
|
+
raw_git_output
|
67
|
+
end
|
68
|
+
|
60
69
|
# @private
|
61
70
|
def self._commit_sha
|
62
71
|
return ENV['PERCY_COMMIT'] if ENV['PERCY_COMMIT']
|
data/lib/percy/client/version.rb
CHANGED
@@ -503,25 +503,39 @@ RSpec.describe Percy::Client::Environment do
|
|
503
503
|
describe 'local git repo methods' do
|
504
504
|
describe '#commit' do
|
505
505
|
it 'returns current local commit data' do
|
506
|
+
raw_git_output = "COMMIT_SHA:sweetsha\n" \
|
507
|
+
"AUTHOR_NAME:LC\n" \
|
508
|
+
"AUTHOR_EMAIL:foobar@gmail.com\n" \
|
509
|
+
"COMMITTER_NAME:LC\n" \
|
510
|
+
"COMMITTER_EMAIL:foobar@gmail.com\n" \
|
511
|
+
"COMMITTED_DATE:444-44-44 44:44:44 -0700\n" \
|
512
|
+
'COMMIT_MESSAGE:wow how cool is this commit'
|
513
|
+
expect(Percy::Client::Environment).to receive(:_git_commit_output).once.and_return(
|
514
|
+
raw_git_output,
|
515
|
+
)
|
516
|
+
|
506
517
|
commit = Percy::Client::Environment.commit
|
518
|
+
|
507
519
|
expect(commit[:branch]).to_not be_empty
|
508
|
-
expect(commit[:sha]).
|
509
|
-
expect(commit[:sha].length).to eq(40)
|
520
|
+
expect(commit[:sha]).to eq('sweetsha')
|
510
521
|
|
511
|
-
expect(commit[:author_email]).to
|
512
|
-
expect(commit[:author_name]).
|
513
|
-
expect(commit[:committed_at]).
|
514
|
-
expect(commit[:committer_email]).
|
515
|
-
expect(commit[:committer_name]).
|
516
|
-
expect(commit[:message]).
|
522
|
+
expect(commit[:author_email]).to eq('foobar@gmail.com')
|
523
|
+
expect(commit[:author_name]).to eq('LC')
|
524
|
+
expect(commit[:committed_at]).to eq('444-44-44 44:44:44 -0700')
|
525
|
+
expect(commit[:committer_email]).to eq('foobar@gmail.com')
|
526
|
+
expect(commit[:committer_name]).to eq('LC')
|
527
|
+
expect(commit[:message]).to eq('wow how cool is this commit')
|
517
528
|
end
|
518
529
|
|
519
|
-
it 'returns
|
520
|
-
|
530
|
+
it 'returns data from environment if commit data cannot be found' do
|
531
|
+
ENV['PERCY_BRANCH'] = 'the-coolest-branch'
|
532
|
+
ENV['PERCY_COMMIT'] = 'agreatsha'
|
533
|
+
|
534
|
+
expect(Percy::Client::Environment).to receive(:_git_commit_output).once.and_return(nil)
|
521
535
|
|
522
536
|
commit = Percy::Client::Environment.commit
|
523
|
-
expect(commit[:branch]).to
|
524
|
-
expect(commit[:sha]).to
|
537
|
+
expect(commit[:branch]).to eq('the-coolest-branch')
|
538
|
+
expect(commit[:sha]).to eq('agreatsha')
|
525
539
|
|
526
540
|
expect(commit[:author_email]).to be_nil
|
527
541
|
expect(commit[:author_name]).to be_nil
|
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: 1.13.
|
4
|
+
version: 1.13.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03
|
11
|
+
date: 2018-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|