build_eval 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/build_eval/server/travis.rb +1 -2
- data/lib/build_eval/server/travis_pro.rb +4 -9
- data/lib/build_eval/travis.rb +18 -10
- data/lib/build_eval/version.rb +1 -1
- data/spec/lib/build_eval/server/travis_pro_spec.rb +10 -13
- data/spec/lib/build_eval/server/travis_spec.rb +6 -11
- data/spec/lib/build_eval/travis_shared_context.rb +45 -2
- data/spec/lib/build_eval/travis_spec.rb +51 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTdkM2EyNDlhMjZkNzZmNTNhOTg0YmMxNzVkZmEzMjY1YzQzZmU4NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2M2NmIwYjQ1NjNkYmE4YTZjZDYyYTBkN2I2NzIzNjNhNTU5ZDE4Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWVhYWUzOTNhMmEyY2Y2ZjNkNWVkYmE3ZGQ4Nzk0ZTVlZTM5MjUwN2UyNmMw
|
10
|
+
ZmY4YjY1MjJkNjA5ZjYxODUyZjE3NzJmYzk0Y2VmZTExYTg4MDFhOWNjNjRh
|
11
|
+
ZmY3NmVjY2UyNWIwMmVkMjk1M2Y0YzU2NTc0YjA2ZjQ1NDVhOWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTkzNzE4M2UxN2U0ODJmZmQ1MTFlNmI4YWJjYjgzYmRlMGQ1Y2Q3ZTBhNWVk
|
14
|
+
ODY3ZjJhODI2Y2U5OGI0OTIyZjI3OWNhM2Y5NmM3OGZhNzdkMTQzZTk4YTcy
|
15
|
+
ZmIwNWM4YzExYWIxZTVlMDQzZDY1MTA4MzU5NWYyNmQ4YzcxOTg=
|
@@ -5,14 +5,13 @@ module BuildEval
|
|
5
5
|
|
6
6
|
def initialize(args)
|
7
7
|
@username = args[:username]
|
8
|
-
@travis = BuildEval::Travis.new(::Travis)
|
9
8
|
end
|
10
9
|
|
11
10
|
def build_result(name)
|
12
11
|
build_path = "#{@username}/#{name}"
|
13
12
|
BuildEval::Result::BuildResult.create(
|
14
13
|
build_name: build_path,
|
15
|
-
status_name:
|
14
|
+
status_name: BuildEval::Travis.last_build_status(build_path: build_path)
|
16
15
|
)
|
17
16
|
end
|
18
17
|
|
@@ -6,25 +6,20 @@ module BuildEval
|
|
6
6
|
def initialize(args)
|
7
7
|
@username = args[:username]
|
8
8
|
@github_token = args[:github_token]
|
9
|
-
@travis = BuildEval::Travis.new(::Travis::Pro)
|
10
9
|
end
|
11
10
|
|
12
11
|
def build_result(name)
|
13
12
|
build_path = "#{@username}/#{name}"
|
14
|
-
BuildEval::Result::BuildResult.create(
|
13
|
+
BuildEval::Result::BuildResult.create(
|
14
|
+
build_name: build_path,
|
15
|
+
status_name: BuildEval::Travis.last_build_status(github_token: @github_token, build_path: build_path)
|
16
|
+
)
|
15
17
|
end
|
16
18
|
|
17
19
|
def to_s
|
18
20
|
"Travis CI Pro #{@username}"
|
19
21
|
end
|
20
22
|
|
21
|
-
private
|
22
|
-
|
23
|
-
def last_status_name(build_path)
|
24
|
-
@travis.login(@github_token)
|
25
|
-
@travis.last_build_status_for(build_path)
|
26
|
-
end
|
27
|
-
|
28
23
|
end
|
29
24
|
|
30
25
|
end
|
data/lib/build_eval/travis.rb
CHANGED
@@ -2,18 +2,26 @@ module BuildEval
|
|
2
2
|
|
3
3
|
class Travis
|
4
4
|
|
5
|
-
|
6
|
-
@travis_module = travis_module
|
7
|
-
end
|
5
|
+
class << self
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
def last_build_status(args)
|
8
|
+
repository = travis_module_for(args)::Repository.find(args[:build_path])
|
9
|
+
repository.recent_builds.find(&:finished?).passed? ? "Success" : "Failure"
|
10
|
+
rescue ::Travis::Client::Error
|
11
|
+
"Unknown"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def travis_module_for(args)
|
17
|
+
travis_module = ::Travis
|
18
|
+
if args[:github_token]
|
19
|
+
travis_module = ::Travis::Pro
|
20
|
+
travis_module.github_auth(args[:github_token])
|
21
|
+
end
|
22
|
+
travis_module
|
23
|
+
end
|
12
24
|
|
13
|
-
def last_build_status_for(build_path)
|
14
|
-
@travis_module::Repository.find(build_path).recent_builds.find(&:finished?).passed? ? "Success" : "Failure"
|
15
|
-
rescue ::Travis::Client::Error
|
16
|
-
"Unknown"
|
17
25
|
end
|
18
26
|
|
19
27
|
end
|
data/lib/build_eval/version.rb
CHANGED
@@ -16,35 +16,32 @@ describe BuildEval::Server::TravisPro do
|
|
16
16
|
|
17
17
|
let(:build_name) { "some_build_name" }
|
18
18
|
let(:last_build_status) { "Unknown" }
|
19
|
-
let(:travis) { instance_double(BuildEval::Travis, login: nil, last_build_status_for: last_build_status) }
|
20
19
|
let(:build_result) { instance_double(BuildEval::Result::BuildResult) }
|
21
20
|
|
22
21
|
subject { travis_pro_server.build_result(build_name) }
|
23
22
|
|
24
23
|
before(:example) do
|
25
|
-
allow(BuildEval::Travis).to receive(:
|
24
|
+
allow(BuildEval::Travis).to receive(:last_build_status).and_return(last_build_status)
|
26
25
|
allow(BuildEval::Result::BuildResult).to receive(:create).and_return(build_result)
|
27
26
|
end
|
28
27
|
|
29
|
-
it "
|
30
|
-
expect(BuildEval::Travis).to
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
it "logs-in to the Travis API using the provided GitHub token" do
|
36
|
-
expect(travis).to receive(:login).with(github_token)
|
28
|
+
it "retrieves the last build status from Travis using the provided GitHub token" do
|
29
|
+
expect(BuildEval::Travis).to(
|
30
|
+
receive(:last_build_status).with(hash_including(github_token: github_token))
|
31
|
+
)
|
37
32
|
|
38
33
|
subject
|
39
34
|
end
|
40
35
|
|
41
|
-
it "retrieves the last build status for the
|
42
|
-
expect(
|
36
|
+
it "retrieves the last build status from Travis for the users build" do
|
37
|
+
expect(BuildEval::Travis).to(
|
38
|
+
receive(:last_build_status).with(hash_including(build_path: "#{username}/#{build_name}"))
|
39
|
+
)
|
43
40
|
|
44
41
|
subject
|
45
42
|
end
|
46
43
|
|
47
|
-
it "creates a build result whose build name is the path to
|
44
|
+
it "creates a build result whose build name is the path to users build" do
|
48
45
|
expect(BuildEval::Result::BuildResult).to(
|
49
46
|
receive(:create).with(hash_including(build_name: "#{username}/#{build_name}"))
|
50
47
|
)
|
@@ -10,29 +10,24 @@ describe BuildEval::Server::Travis do
|
|
10
10
|
|
11
11
|
let(:build_name) { "some_build_name" }
|
12
12
|
let(:last_build_status) { "Failure" }
|
13
|
-
let(:travis) { instance_double(BuildEval::Travis, last_build_status_for: last_build_status) }
|
14
13
|
let(:build_result) { instance_double(BuildEval::Result::BuildResult) }
|
15
14
|
|
16
15
|
subject { travis_server.build_result(build_name) }
|
17
16
|
|
18
17
|
before(:example) do
|
19
|
-
allow(BuildEval::Travis).to receive(:
|
18
|
+
allow(BuildEval::Travis).to receive(:last_build_status).and_return(last_build_status)
|
20
19
|
allow(BuildEval::Result::BuildResult).to receive(:create).and_return(build_result)
|
21
20
|
end
|
22
21
|
|
23
|
-
it "
|
24
|
-
expect(BuildEval::Travis).to
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
it "retrieves the last build status for the GitHub repository" do
|
30
|
-
expect(travis).to receive(:last_build_status_for).with("#{username}/#{build_name}")
|
22
|
+
it "retrieves the last build status from Travis for the users build" do
|
23
|
+
expect(BuildEval::Travis).to(
|
24
|
+
receive(:last_build_status).with(hash_including(build_path: "#{username}/#{build_name}"))
|
25
|
+
)
|
31
26
|
|
32
27
|
subject
|
33
28
|
end
|
34
29
|
|
35
|
-
it "creates a build result whose build name is the path to
|
30
|
+
it "creates a build result whose build name is the path to users build" do
|
36
31
|
expect(BuildEval::Result::BuildResult).to(
|
37
32
|
receive(:create).with(hash_including(build_name: "#{username}/#{build_name}"))
|
38
33
|
)
|
@@ -1,7 +1,50 @@
|
|
1
1
|
shared_context "stubbed Travis API interactions" do
|
2
2
|
|
3
|
-
|
3
|
+
module StubTravisBuild
|
4
4
|
|
5
|
-
|
5
|
+
def finished?
|
6
|
+
# Intentionally blank
|
7
|
+
end
|
8
|
+
|
9
|
+
def passed?
|
10
|
+
# Intentionally blank
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
module StubTravisRepository
|
16
|
+
|
17
|
+
def recent_builds
|
18
|
+
# Intentionally blank
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
module StubTravisPro
|
24
|
+
|
25
|
+
Repository = StubTravisRepository
|
26
|
+
|
27
|
+
def self.github_auth(auth_token)
|
28
|
+
# Intentionally blank
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
module StubTravis
|
34
|
+
|
35
|
+
Repository = StubTravisRepository
|
36
|
+
Pro = StubTravisPro
|
37
|
+
|
38
|
+
module Client
|
39
|
+
Repository = StubTravisRepository
|
40
|
+
Build = StubTravisBuild
|
41
|
+
Error = ::StandardError
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
before(:context) do
|
47
|
+
::Travis = StubTravis
|
48
|
+
end
|
6
49
|
|
7
50
|
end
|
@@ -1,27 +1,10 @@
|
|
1
1
|
describe BuildEval::Travis do
|
2
2
|
include_context "stubbed Travis API interactions"
|
3
3
|
|
4
|
-
|
4
|
+
describe "::last_build_status" do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
describe "#login" do
|
9
|
-
|
10
|
-
let(:github_token) { "SOMEGITHUBTOKEN" }
|
11
|
-
|
12
|
-
subject { travis.login(github_token) }
|
13
|
-
|
14
|
-
it "logs-in to Travis using the GitHub Auth token provided" do
|
15
|
-
expect(travis_module).to receive(:github_auth).with(github_token)
|
16
|
-
|
17
|
-
subject
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#last_build_status_for" do
|
23
|
-
|
24
|
-
let(:build_path) { "some/build_path" }
|
6
|
+
let(:build_path) { "some/build_path" }
|
7
|
+
let(:optional_args) { {} }
|
25
8
|
|
26
9
|
let(:recent_builds) do
|
27
10
|
(1..3).map { |i| instance_double(::Travis::Client::Build, finished?: i > 1) }
|
@@ -32,20 +15,63 @@ describe BuildEval::Travis do
|
|
32
15
|
instance_double(::Travis::Client::Repository, recent_builds: recent_builds)
|
33
16
|
end
|
34
17
|
|
35
|
-
subject {
|
18
|
+
subject { described_class.last_build_status({ build_path: build_path }.merge(optional_args)) }
|
36
19
|
|
37
20
|
before(:example) do
|
38
|
-
allow(
|
21
|
+
allow(::Travis::Repository).to receive(:find).and_return(travis_repository)
|
39
22
|
allow(last_finished_build).to receive(:passed?).and_return(last_finished_build_passed_flag)
|
40
23
|
end
|
41
24
|
|
42
|
-
|
43
|
-
|
25
|
+
context "when a GitHub token is provided" do
|
26
|
+
|
27
|
+
let(:github_token) { "SOMEGITHUBAUTHTOKEN" }
|
28
|
+
let(:optional_args) { { github_token: github_token } }
|
29
|
+
|
30
|
+
it "logs-in to the Travis Pro API with the provided GitHub token" do
|
31
|
+
expect(::Travis::Pro).to receive(:github_auth).with(github_token)
|
32
|
+
|
33
|
+
subject
|
34
|
+
end
|
35
|
+
|
36
|
+
it "uses the Travis Pro modules Repository" do
|
37
|
+
expect(::Travis::Pro::Repository).to receive(:find)
|
38
|
+
|
39
|
+
subject
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when a Travis Client error occurs on log-in" do
|
43
|
+
|
44
|
+
before(:example) do
|
45
|
+
allow(::Travis::Pro).to receive(:github_auth).and_raise(::Travis::Client::Error.new("Forced error"))
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns 'Unknown'" do
|
49
|
+
expect(subject).to eql("Unknown")
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when no GitHub token is provided" do
|
57
|
+
|
58
|
+
let(:optional_args) { {} }
|
59
|
+
|
60
|
+
it "uses the Travis modules Repository" do
|
61
|
+
expect(::Travis::Repository).to receive(:find)
|
62
|
+
|
63
|
+
subject
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
it "retrieves the repository for the provided build path" do
|
69
|
+
expect(::Travis::Repository).to receive(:find).with(build_path)
|
44
70
|
|
45
71
|
subject
|
46
72
|
end
|
47
73
|
|
48
|
-
it "retrieves the recent builds from the
|
74
|
+
it "retrieves the recent builds from the repository" do
|
49
75
|
expect(travis_repository).to receive(:recent_builds)
|
50
76
|
|
51
77
|
subject
|