percy-client 0.1.2 → 0.1.3
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.rb +0 -1
- data/lib/percy/client/builds.rb +11 -11
- data/lib/percy/client/local_git.rb +4 -5
- data/lib/percy/client/version.rb +1 -1
- data/lib/percy/config.rb +6 -0
- data/spec/lib/percy/client/local_git_spec.rb +4 -4
- data/spec/lib/percy/client_spec.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdab0f8284a32f328fb7dc4741ca66373dbf05ae
|
4
|
+
data.tar.gz: 1d43a124e5727b0fe60d20b51a7bc370af2d5b3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39677cbd0273d1f524160396a5a422146c2277a906a85c4ec7d41922c12b64df450a3dc02c85f40b9612e6fce96ad54161522ab125654461d5659b4e2e025bec
|
7
|
+
data.tar.gz: 6368f16f4aade526c1389aa1da24a800c35cef56607cee402d9e61ea398fc1de5c5f41a0c4f0c7bcf2aac9fbdb6a7a678530f6981aa386cb9e0ce93c785ee44d
|
data/lib/percy/client.rb
CHANGED
data/lib/percy/client/builds.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
module Percy
|
2
2
|
class Client
|
3
3
|
module Builds
|
4
|
-
def create_build(
|
5
|
-
|
4
|
+
def create_build(repo, options = {})
|
5
|
+
commit_data = options[:commit_data] || Percy::Client::LocalGit.commit
|
6
6
|
data = {
|
7
7
|
'data' => {
|
8
8
|
'type' => 'builds',
|
9
9
|
'attributes' => {
|
10
|
-
'commit-sha' =>
|
11
|
-
'commit-branch' =>
|
12
|
-
'commit-committed-at' =>
|
13
|
-
'commit-author-name' =>
|
14
|
-
'commit-author-email' =>
|
15
|
-
'commit-committer-name' =>
|
16
|
-
'commit-committer-email' =>
|
17
|
-
'commit-message' =>
|
10
|
+
'commit-sha' => commit_data[:sha],
|
11
|
+
'commit-branch' => commit_data[:branch],
|
12
|
+
'commit-committed-at' => commit_data[:committed_at],
|
13
|
+
'commit-author-name' => commit_data[:author_name],
|
14
|
+
'commit-author-email' => commit_data[:author_email],
|
15
|
+
'commit-committer-name' => commit_data[:committer_name],
|
16
|
+
'commit-committer-email' => commit_data[:committer_email],
|
17
|
+
'commit-message' => commit_data[:message],
|
18
18
|
'pull-request-number' => nil,
|
19
19
|
},
|
20
20
|
}
|
21
21
|
}
|
22
|
-
post("#{config.api_url}/repos/#{
|
22
|
+
post("#{config.api_url}/repos/#{repo}/builds/", data)
|
23
23
|
end
|
24
24
|
|
25
25
|
def finalize_build(build_id)
|
@@ -3,12 +3,11 @@ module Percy
|
|
3
3
|
module LocalGit
|
4
4
|
GIT_FORMAT_LINES = [
|
5
5
|
'COMMIT_SHA:%H',
|
6
|
-
'AUTHOR_DATE:%ai',
|
7
6
|
'AUTHOR_NAME:%an',
|
8
7
|
'AUTHOR_EMAIL:%ae',
|
9
8
|
'COMMITTER_NAME:%an',
|
10
9
|
'COMMITTER_EMAIL:%ae',
|
11
|
-
'
|
10
|
+
'COMMITTED_DATE:%ai',
|
12
11
|
# Note: order is important, this must come last because the regex is a multiline match.
|
13
12
|
'COMMIT_MESSAGE:%B'
|
14
13
|
].freeze
|
@@ -16,7 +15,7 @@ module Percy
|
|
16
15
|
class Error < Exception; end
|
17
16
|
class NoLocalRepo < Exception; end
|
18
17
|
|
19
|
-
def
|
18
|
+
def self.commit
|
20
19
|
commit = ENV['PERCY_COMMIT'] || 'HEAD'
|
21
20
|
branch = ENV['PERCY_BRANCH'] || `git rev-parse --abbrev-ref HEAD`.strip
|
22
21
|
if branch == ''
|
@@ -28,7 +27,7 @@ module Percy
|
|
28
27
|
data = {
|
29
28
|
sha: output.match(/COMMIT_SHA:(.*)/)[1],
|
30
29
|
branch: branch,
|
31
|
-
committed_at: output.match(/
|
30
|
+
committed_at: output.match(/COMMITTED_DATE:(.*)/)[1],
|
32
31
|
author_name: output.match(/AUTHOR_NAME:(.*)/)[1],
|
33
32
|
author_email: output.match(/AUTHOR_EMAIL:(.*)/)[1],
|
34
33
|
committer_name: output.match(/COMMITTER_NAME:(.*)/)[1],
|
@@ -37,7 +36,7 @@ module Percy
|
|
37
36
|
}
|
38
37
|
end
|
39
38
|
|
40
|
-
def
|
39
|
+
def self.repo
|
41
40
|
origin_url = `git config --get remote.origin.url`
|
42
41
|
if origin_url == ''
|
43
42
|
raise Percy::Client::LocalGit::NoLocalRepo.new('No local git repository found.')
|
data/lib/percy/client/version.rb
CHANGED
data/lib/percy/config.rb
CHANGED
@@ -7,6 +7,7 @@ module Percy
|
|
7
7
|
|
8
8
|
attr_accessor :access_token
|
9
9
|
attr_accessor :api_url
|
10
|
+
attr_accessor :repo
|
10
11
|
|
11
12
|
# List of configurable keys for {Percy::Client}
|
12
13
|
# @return [Array] Option keys.
|
@@ -14,6 +15,7 @@ module Percy
|
|
14
15
|
@keys ||= [
|
15
16
|
:access_token,
|
16
17
|
:api_url,
|
18
|
+
:repo,
|
17
19
|
]
|
18
20
|
end
|
19
21
|
|
@@ -24,5 +26,9 @@ module Percy
|
|
24
26
|
def api_url
|
25
27
|
@api_url ||= ENV['PERCY_API'] || 'https://percy.io/api/v1'
|
26
28
|
end
|
29
|
+
|
30
|
+
def repo
|
31
|
+
@repo ||= ENV['PERCY_REPO'] || Percy::Client::LocalGit.repo
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
RSpec.describe Percy::Client::LocalGit do
|
2
|
-
describe '#
|
2
|
+
describe '#repo' do
|
3
3
|
it 'returns the current local repo name' do
|
4
|
-
expect(Percy.
|
4
|
+
expect(Percy::Client::LocalGit.repo).to eq('percy/percy-client')
|
5
5
|
end
|
6
6
|
end
|
7
|
-
describe '#
|
7
|
+
describe '#commit' do
|
8
8
|
it 'returns current local commit data' do
|
9
|
-
commit = Percy.
|
9
|
+
commit = Percy::Client::LocalGit.commit
|
10
10
|
expect(commit[:author_email]).to match(/.+@.+\..+/)
|
11
11
|
expect(commit[:author_name]).to_not be_empty
|
12
12
|
expect(commit[:branch]).to_not be_empty
|
@@ -4,6 +4,14 @@ RSpec.describe Percy::Client do
|
|
4
4
|
config = Percy::Config.new
|
5
5
|
client = Percy::Client.new(config: config)
|
6
6
|
expect(client.config).to eq(config)
|
7
|
+
expect(client.config.keys).to eq([
|
8
|
+
:access_token,
|
9
|
+
:api_url,
|
10
|
+
:repo,
|
11
|
+
])
|
12
|
+
expect(client.config.access_token).to be_nil
|
13
|
+
expect(client.config.api_url).to eq(ENV['PERCY_API'])
|
14
|
+
expect(client.config.repo).to eq('percy/percy-client')
|
7
15
|
end
|
8
16
|
end
|
9
17
|
end
|