evrone-ci-common 0.2.0.pre3 → 0.2.0.pre4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/evrone/ci/common/version.rb +1 -1
- data/lib/evrone/ci/scm/git.rb +25 -8
- data/spec/lib/scm/git_spec.rb +31 -9
- 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: 81ca8965c9dae40ab4566ba5d5c048a2a87b389e
|
4
|
+
data.tar.gz: 4e6d92fed51fc19fcadc01aa927f1a34682d4add
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed9a28451eee34d32576499f36d9308b93b8e41b2a0e7f8dc54fb2df7faf6c06a76e1a2508fb248202388d62c80316e64867432fb81fed19d7701f1536ce735f
|
7
|
+
data.tar.gz: 9633d1460ab29127d4a381917408f7bd4b20840b877a599dd4fd1fa515ae2bb72fdfb4579296be7ac82ab8dd59a8f684c3954dc9520ecf96e1bba3513ee93c64
|
data/lib/evrone/ci/scm/git.rb
CHANGED
@@ -11,18 +11,26 @@ module Evrone
|
|
11
11
|
|
12
12
|
COMMIT_RE = /^(.*) -:- (.*) \((.*)\) -:- (.*)$/
|
13
13
|
|
14
|
-
attr_reader :src, :sha, :path, :logger, :git_ssh
|
14
|
+
attr_reader :src, :sha, :path, :logger, :git_ssh, :pull_request_id, :branch
|
15
15
|
|
16
16
|
def initialize(src, sha, path, options = {}, &block)
|
17
|
-
@src
|
18
|
-
@sha
|
19
|
-
@path
|
20
|
-
@
|
21
|
-
@
|
17
|
+
@src = src
|
18
|
+
@sha = sha
|
19
|
+
@path = path
|
20
|
+
@branch = options[:branch]
|
21
|
+
@pull_request_id = options[:pull_request_id]
|
22
|
+
@git_ssh = GitSSH.new options[:deploy_key]
|
23
|
+
@logger = block
|
24
|
+
end
|
25
|
+
|
26
|
+
def open
|
27
|
+
git_ssh.open do
|
28
|
+
yield if block_given?
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
32
|
def fetch
|
25
|
-
code =
|
33
|
+
code = open do
|
26
34
|
repo_exist? ? update : clone
|
27
35
|
end
|
28
36
|
code = checkout if code == 0
|
@@ -36,7 +44,16 @@ module Evrone
|
|
36
44
|
def make_fetch_command
|
37
45
|
clone_cmd = "git clone -q #{src} #{path}"
|
38
46
|
checkout_cmd = "git checkout -qf #{sha}"
|
39
|
-
|
47
|
+
cmd = %{
|
48
|
+
if [ ! -d #{path} ] ; then
|
49
|
+
echo "$ #{clone_cmd}" &&
|
50
|
+
#{clone_cmd} || exit $? ;
|
51
|
+
fi ;
|
52
|
+
echo "$ #{checkout_cmd}" &&
|
53
|
+
cd #{path} &&
|
54
|
+
#{checkout_cmd}
|
55
|
+
}.gsub("\n", ' ').gsub(/\ +/, ' ').strip
|
56
|
+
cmd
|
40
57
|
end
|
41
58
|
|
42
59
|
def commit_info
|
data/spec/lib/scm/git_spec.rb
CHANGED
@@ -8,8 +8,9 @@ describe Evrone::CI::SCM::Git do
|
|
8
8
|
let(:sha) { message.sha }
|
9
9
|
let(:deploy_key) { message.deploy_key }
|
10
10
|
let(:output) { "" }
|
11
|
+
let(:options) { {} }
|
11
12
|
let(:git) {
|
12
|
-
described_class.new src, sha, path,
|
13
|
+
described_class.new src, sha, path, options, &method(:add_to_output)
|
13
14
|
}
|
14
15
|
|
15
16
|
subject { git }
|
@@ -18,13 +19,31 @@ describe Evrone::CI::SCM::Git do
|
|
18
19
|
after { FileUtils.rm_rf path }
|
19
20
|
|
20
21
|
context "just created" do
|
21
|
-
its(:src) { should eq src
|
22
|
-
its(:sha) { should eq sha
|
23
|
-
its(:path) { should eq path
|
22
|
+
its(:src) { should eq src }
|
23
|
+
its(:sha) { should eq sha }
|
24
|
+
its(:path) { should eq path }
|
25
|
+
its(:branch) { should be_nil }
|
26
|
+
its(:pull_request_id) { should be_nil }
|
27
|
+
its("git_ssh.deploy_key") { should be_nil }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "assign branch" do
|
31
|
+
let(:options) { { branch: 'master' } }
|
32
|
+
its(:branch) { should eq 'master' }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "assign pull_request_id" do
|
36
|
+
let(:options) { { pull_request_id: 1} }
|
37
|
+
its(:pull_request_id) { should eq 1 }
|
38
|
+
end
|
39
|
+
|
40
|
+
context "assign deploy_key" do
|
41
|
+
let(:options) { { deploy_key: deploy_key } }
|
24
42
|
its("git_ssh.deploy_key") { should eq deploy_key }
|
25
43
|
end
|
26
44
|
|
27
45
|
context "fetch" do
|
46
|
+
let(:options) { { deploy_key: deploy_key } }
|
28
47
|
subject { git.fetch }
|
29
48
|
|
30
49
|
it { should eq 0 }
|
@@ -61,9 +80,10 @@ describe Evrone::CI::SCM::Git do
|
|
61
80
|
context "make_fetch_command" do
|
62
81
|
include Evrone::Common::Spawn
|
63
82
|
|
83
|
+
let(:options) { { deploy_key: deploy_key } }
|
64
84
|
let(:env) { {'GIT_SSH' => git.git_ssh.location.path} }
|
65
85
|
let(:run) do
|
66
|
-
git.
|
86
|
+
git.open do
|
67
87
|
spawn(env, git.make_fetch_command, &method(:add_to_output))
|
68
88
|
end
|
69
89
|
end
|
@@ -106,9 +126,10 @@ describe Evrone::CI::SCM::Git do
|
|
106
126
|
end
|
107
127
|
|
108
128
|
context ".make_export_command" do
|
109
|
-
let(:
|
110
|
-
let(:
|
111
|
-
let(:
|
129
|
+
let(:options) { { deploy_key: deploy_key } }
|
130
|
+
let(:from) { path }
|
131
|
+
let(:to) { '/tmp/.test/export' }
|
132
|
+
let(:expected) { "(cd '#{ from }' && git checkout-index -a -f --prefix='#{ to}/')" }
|
112
133
|
subject { described_class.make_export_command from, to}
|
113
134
|
it { should eq expected }
|
114
135
|
|
@@ -129,8 +150,9 @@ describe Evrone::CI::SCM::Git do
|
|
129
150
|
end
|
130
151
|
|
131
152
|
context "commit_info" do
|
153
|
+
let(:options) { { deploy_key: deploy_key } }
|
132
154
|
subject { git.commit_info }
|
133
|
-
before { git.fetch
|
155
|
+
before { git.fetch }
|
134
156
|
|
135
157
|
it "should be" do
|
136
158
|
expect(subject.sha).to eq 'b665f90239563c030f1b280a434b3d84daeda1bd'
|