build_eval 0.0.12 → 0.0.13
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/travis/session_factory.rb +38 -0
- data/lib/build_eval/travis.rb +8 -20
- data/lib/build_eval/version.rb +1 -1
- data/lib/build_eval.rb +1 -0
- data/spec/lib/build_eval/travis/session_factory_spec.rb +91 -0
- data/spec/lib/build_eval/travis_spec.rb +23 -40
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWJiNTEyNDFmYTUxNmZmMGE3NjRhZWQ2MjVjNWFkMDFiNGUwZGVkYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWYyYTUxYjZlNDM2M2VlNzQ1YmY1NWIxZjdiM2YxOTQ0NmQyNDE3Yg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDI3YTlmMGI0NzI4ZGMwZjYzMjM4NjllYjcyZTBjM2RhYTcxMDA1MDc0MjM4
|
10
|
+
ZWFhYjhhMjgxNGU0ZDA0NjkxMzViZTFkMjM2YmJiZGVhNmFlNjJiYjE5YjJm
|
11
|
+
MDNlZGYxMDY1YTljODQ5YmQwNGFmYTU1MGQxNmYxNjZkM2ZkYTg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2JmMjJhODM4MzJmNzc5OTE0M2M1NjUwMmIyYjBhNWI0N2Y5NTFlZmE1MjU1
|
14
|
+
NTFkM2FmZWM0ODViMTA0ZWE0OThhMmE1MjE2Y2MwZTE4OGY2ZmI1ZDhhODdl
|
15
|
+
MzgxOTM1ODJlYmQ5Yjc1YjYwNDJjMTlhMzAyZjQyYzIxZmVlYjc=
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module BuildEval
|
2
|
+
module Travis
|
3
|
+
|
4
|
+
class SessionFactory
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def create(github_token)
|
9
|
+
find_session(github_token) || create_session(github_token)
|
10
|
+
end
|
11
|
+
|
12
|
+
def clear_cache
|
13
|
+
@sessions = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def find_session(github_token)
|
19
|
+
sessions[github_token]
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_session(github_token)
|
23
|
+
travis_uri = github_token ? ::Travis::Client::PRO_URI : ::Travis::Client::ORG_URI
|
24
|
+
sessions[github_token] = ::Travis::Client::Session.new(uri: travis_uri, ssl: {}).tap do |session|
|
25
|
+
session.github_auth(github_token) if github_token
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def sessions
|
30
|
+
@sessions ||= {}
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/build_eval/travis.rb
CHANGED
@@ -1,25 +1,13 @@
|
|
1
1
|
module BuildEval
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
"Unknown"
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def create_session(args)
|
17
|
-
travis_uri = args[:github_token] ? ::Travis::Client::PRO_URI : ::Travis::Client::ORG_URI
|
18
|
-
::Travis::Client::Session.new(uri: travis_uri, ssl: {}).tap do |session|
|
19
|
-
session.github_auth(args[:github_token]) if args[:github_token]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
3
|
+
module Travis
|
4
|
+
|
5
|
+
def self.last_build_status(args)
|
6
|
+
session = BuildEval::Travis::SessionFactory.create(args[:github_token])
|
7
|
+
repository = session.repo(args[:repository_path])
|
8
|
+
repository.recent_builds.find(&:finished?).passed? ? "Success" : "Failure"
|
9
|
+
rescue ::Travis::Client::Error
|
10
|
+
"Unknown"
|
23
11
|
end
|
24
12
|
|
25
13
|
end
|
data/lib/build_eval/version.rb
CHANGED
data/lib/build_eval.rb
CHANGED
@@ -6,6 +6,7 @@ require 'travis/client/session'
|
|
6
6
|
|
7
7
|
require_relative 'build_eval/error'
|
8
8
|
require_relative 'build_eval/http'
|
9
|
+
require_relative 'build_eval/travis/session_factory'
|
9
10
|
require_relative 'build_eval/travis'
|
10
11
|
require_relative 'build_eval/result/status'
|
11
12
|
require_relative 'build_eval/result/build_result'
|
@@ -0,0 +1,91 @@
|
|
1
|
+
describe BuildEval::Travis::SessionFactory do
|
2
|
+
|
3
|
+
describe "::create" do
|
4
|
+
|
5
|
+
let(:github_token) { nil }
|
6
|
+
let(:travis_session) { instance_double(::Travis::Client::Session) }
|
7
|
+
|
8
|
+
subject { described_class.create(github_token) }
|
9
|
+
|
10
|
+
before(:example) { allow(::Travis::Client::Session).to receive(:new).and_return(travis_session) }
|
11
|
+
after(:example) { described_class.clear_cache }
|
12
|
+
|
13
|
+
shared_examples_for "a call creating a new session" do
|
14
|
+
|
15
|
+
it "creates a Travis session with empty SSL settings to avoid using local security certificates" do
|
16
|
+
expect(::Travis::Client::Session).to receive(:new).with(hash_including(ssl: {}))
|
17
|
+
|
18
|
+
subject
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the created session" do
|
22
|
+
expect(subject).to eql(travis_session)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when a session for the GitHub token has not been retrieved previously" do
|
28
|
+
|
29
|
+
context "and a non-nil GitHub token is provided" do
|
30
|
+
|
31
|
+
let(:github_token) { "SOMEGITHUBAUTHTOKEN" }
|
32
|
+
|
33
|
+
before(:example) { allow(travis_session).to receive(:github_auth) }
|
34
|
+
|
35
|
+
it_behaves_like "a call creating a new session"
|
36
|
+
|
37
|
+
it "creates a Travis session connecting to the Travis Pro site" do
|
38
|
+
expect(::Travis::Client::Session).to receive(:new).with(hash_including(uri: ::Travis::Client::PRO_URI))
|
39
|
+
|
40
|
+
subject
|
41
|
+
end
|
42
|
+
|
43
|
+
it "logs-in using the provided GitHub token via the session" do
|
44
|
+
expect(travis_session).to receive(:github_auth).with(github_token)
|
45
|
+
|
46
|
+
subject
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context "and a nil GitHub token is provided" do
|
52
|
+
|
53
|
+
let(:github_token) { nil }
|
54
|
+
|
55
|
+
it_behaves_like "a call creating a new session"
|
56
|
+
|
57
|
+
it "creates a Travis session connecting to the Travis Org site" do
|
58
|
+
expect(::Travis::Client::Session).to receive(:new).with(hash_including(uri: ::Travis::Client::ORG_URI))
|
59
|
+
|
60
|
+
subject
|
61
|
+
end
|
62
|
+
|
63
|
+
it "does not log-in" do
|
64
|
+
expect(travis_session).to_not receive(:github_auth)
|
65
|
+
|
66
|
+
subject
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when a session for the GitHub token has been retrieved previously" do
|
74
|
+
|
75
|
+
before(:example) { subject }
|
76
|
+
|
77
|
+
it "does not create a new session" do
|
78
|
+
expect(::Travis::Client::Session).to_not receive(:new)
|
79
|
+
|
80
|
+
subject
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns the previously retrieved session" do
|
84
|
+
expect(subject).to eql(travis_session)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -18,68 +18,37 @@ describe BuildEval::Travis do
|
|
18
18
|
subject { described_class.last_build_status({ repository_path: repository_path }.merge(optional_args)) }
|
19
19
|
|
20
20
|
before(:example) do
|
21
|
-
allow(::Travis::
|
21
|
+
allow(BuildEval::Travis::SessionFactory).to receive(:create).and_return(travis_session)
|
22
22
|
allow(last_finished_build).to receive(:passed?).and_return(last_finished_build_passed_flag)
|
23
23
|
end
|
24
24
|
|
25
|
-
context "when a
|
25
|
+
context "when a Github authentication token is provided" do
|
26
26
|
|
27
27
|
let(:github_token) { "SOMEGITHUBAUTHTOKEN" }
|
28
28
|
let(:optional_args) { { github_token: github_token } }
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
it "creates a Travis session connecting to the Travis Pro site" do
|
33
|
-
expect(::Travis::Client::Session).to receive(:new).with(hash_including(uri: ::Travis::Client::PRO_URI))
|
30
|
+
it "creates a Travis session using the token" do
|
31
|
+
expect(BuildEval::Travis::SessionFactory).to receive(:create).with(github_token)
|
34
32
|
|
35
33
|
subject
|
36
34
|
end
|
37
35
|
|
38
|
-
it "logs-in using the provided GitHub token via the session" do
|
39
|
-
expect(travis_session).to receive(:github_auth).with(github_token)
|
40
|
-
|
41
|
-
subject
|
42
|
-
end
|
43
|
-
|
44
|
-
context "when an error occurs on log-in" do
|
45
|
-
|
46
|
-
before(:example) do
|
47
|
-
allow(travis_session).to receive(:github_auth).and_raise(::Travis::Client::Error.new("Forced error"))
|
48
|
-
end
|
49
|
-
|
50
|
-
it "returns 'Unknown'" do
|
51
|
-
expect(subject).to eql("Unknown")
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
36
|
end
|
57
37
|
|
58
|
-
context "when
|
38
|
+
context "when a Github authentication token is not provided" do
|
59
39
|
|
60
40
|
let(:optional_args) { {} }
|
61
41
|
|
62
|
-
it "creates a Travis session
|
63
|
-
expect(::Travis::
|
64
|
-
|
65
|
-
subject
|
66
|
-
end
|
67
|
-
|
68
|
-
it "does not log-in" do
|
69
|
-
expect(travis_session).to_not receive(:github_auth)
|
42
|
+
it "creates a Travis session for a nil token" do
|
43
|
+
expect(BuildEval::Travis::SessionFactory).to receive(:create).with(nil)
|
70
44
|
|
71
45
|
subject
|
72
46
|
end
|
73
47
|
|
74
48
|
end
|
75
49
|
|
76
|
-
it "creates a Travis session with empty SSL settings to avoid using local security certificates" do
|
77
|
-
expect(::Travis::Client::Session).to receive(:new).with(hash_including(ssl: {}))
|
78
50
|
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
it "retrieves the Travis repository for the provided repository path" do
|
51
|
+
it "retrieves the Travis repository for the provided repository path from the session" do
|
83
52
|
expect(travis_session).to receive(:repo).with(repository_path)
|
84
53
|
|
85
54
|
subject
|
@@ -117,7 +86,21 @@ describe BuildEval::Travis do
|
|
117
86
|
|
118
87
|
end
|
119
88
|
|
120
|
-
context "when an
|
89
|
+
context "when an error occurs obtaining a session" do
|
90
|
+
|
91
|
+
before(:example) do
|
92
|
+
allow(BuildEval::Travis::SessionFactory).to(
|
93
|
+
receive(:create).and_raise(::Travis::Client::Error.new("Forced error"))
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "returns 'Unknown'" do
|
98
|
+
expect(subject).to eql("Unknown")
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
context "when an error occurs retrieving the recent builds" do
|
121
104
|
|
122
105
|
before(:example) do
|
123
106
|
allow(travis_repository).to receive(:recent_builds).and_raise(::Travis::Client::Error.new("Forced error"))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: build_eval
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ueckerman
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- ./lib/build_eval/server/travis.rb
|
164
164
|
- ./lib/build_eval/server/travis_pro.rb
|
165
165
|
- ./lib/build_eval/travis.rb
|
166
|
+
- ./lib/build_eval/travis/session_factory.rb
|
166
167
|
- ./lib/build_eval/version.rb
|
167
168
|
- ./spec/lib/build_eval/error_spec.rb
|
168
169
|
- ./spec/lib/build_eval/http_shared_context.rb
|
@@ -184,6 +185,7 @@ files:
|
|
184
185
|
- ./spec/lib/build_eval/server/team_city_spec.rb
|
185
186
|
- ./spec/lib/build_eval/server/travis_pro_spec.rb
|
186
187
|
- ./spec/lib/build_eval/server/travis_spec.rb
|
188
|
+
- ./spec/lib/build_eval/travis/session_factory_spec.rb
|
187
189
|
- ./spec/lib/build_eval/travis_spec.rb
|
188
190
|
- ./spec/lib/build_eval_smoke_spec.rb
|
189
191
|
- ./spec/lib/build_eval_spec.rb
|
@@ -233,6 +235,7 @@ test_files:
|
|
233
235
|
- ./spec/lib/build_eval/server/team_city_spec.rb
|
234
236
|
- ./spec/lib/build_eval/server/travis_pro_spec.rb
|
235
237
|
- ./spec/lib/build_eval/server/travis_spec.rb
|
238
|
+
- ./spec/lib/build_eval/travis/session_factory_spec.rb
|
236
239
|
- ./spec/lib/build_eval/travis_spec.rb
|
237
240
|
- ./spec/lib/build_eval_smoke_spec.rb
|
238
241
|
- ./spec/lib/build_eval_spec.rb
|