ci_in_a_can 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ci_in_a_can/app.rb +49 -10
- data/lib/ci_in_a_can/build.rb +1 -1
- data/lib/ci_in_a_can/repo.rb +57 -0
- data/lib/ci_in_a_can/version.rb +1 -1
- data/spec/ci_in_a_can/build_spec.rb +15 -7
- data/spec/ci_in_a_can/repo_spec.rb +183 -0
- metadata +5 -5
- data/lib/ci_in_a_can/build_setting.rb +0 -13
- data/spec/ci_in_a_can/build_setting_spec.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93278421181c40f169823bd2a26073c13eb60c25
|
4
|
+
data.tar.gz: 1ccc1722210490cda0626af954f54333f6d9d873
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a7a9f5ad472316abc975be0da76a20c0915c1b840363d57d62ede0372beb48adc35677a0a9b8a0b46090b3523127f5c01cd869865e1b3bbd2ca9040c84d9a5b
|
7
|
+
data.tar.gz: 7393e824459eaba30c67b46137586d980cb028df7ac8bd2f508ce8819f3f826e441dc653a65bc553036091b70d1abb34473b7a824d880c6b5cc147c39eeb8a76
|
data/lib/ci_in_a_can/app.rb
CHANGED
@@ -4,44 +4,75 @@ module CiInACan
|
|
4
4
|
|
5
5
|
class App < Sinatra::Base
|
6
6
|
|
7
|
+
enable :sessions
|
8
|
+
|
9
|
+
before do
|
10
|
+
session[:authenticated] = session[:passphrase] == ENV['PASSPHRASE'].to_s
|
11
|
+
end
|
12
|
+
|
7
13
|
class << self
|
8
14
|
attr_accessor :jobs_location
|
9
15
|
end
|
10
16
|
|
17
|
+
get '/login' do
|
18
|
+
CiInACan::WebContent.full_page_of(
|
19
|
+
<<EOF
|
20
|
+
<form action="/login" method="post">
|
21
|
+
Passphrase
|
22
|
+
<input type="password" name="passphrase">
|
23
|
+
<button type="submit">Submit</button>
|
24
|
+
</form>
|
25
|
+
EOF
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
post '/login' do
|
30
|
+
session[:passphrase] = params[:passphrase]
|
31
|
+
redirect '/'
|
32
|
+
end
|
33
|
+
|
11
34
|
get '/test_result/:id.json' do
|
12
35
|
CiInACan::TestResult.find(params[:id]).to_json
|
13
36
|
end
|
14
37
|
|
15
38
|
post %r{/repo/(.+)} do
|
16
39
|
|
17
|
-
|
18
|
-
redirect '/'
|
40
|
+
unless session[:authenticated]
|
41
|
+
redirect '/login'
|
19
42
|
return
|
20
43
|
end
|
21
44
|
|
22
45
|
params[:id] = params[:captures].first
|
23
46
|
commands = params[:commands].gsub("\r\n", "\n").split("\n")
|
24
47
|
commands = commands.map { |x| x.strip }.select { |x| x != '' }
|
25
|
-
|
26
|
-
|
27
|
-
|
48
|
+
repo = CiInACan::Repo.find params[:id]
|
49
|
+
repo = CiInACan::Repo.create(id: params[:id]) unless repo
|
50
|
+
repo.build_commands = commands
|
51
|
+
repo.save
|
28
52
|
redirect "/repo/#{params[:id]}"
|
29
53
|
end
|
30
54
|
|
31
55
|
get %r{/repo/(.+)} do
|
56
|
+
|
57
|
+
unless session[:authenticated]
|
58
|
+
redirect '/login'
|
59
|
+
return
|
60
|
+
end
|
61
|
+
|
32
62
|
params[:id] = params[:captures].first
|
33
|
-
|
34
|
-
|
35
|
-
commands =
|
63
|
+
repo = CiInACan::Repo.find(params[:id])
|
64
|
+
url = repo ? repo.url : nil
|
65
|
+
commands = repo ? repo.build_commands.join("\n") : ''
|
36
66
|
CiInACan::WebContent.full_page_of(
|
37
67
|
<<EOF
|
38
68
|
<form action="/repo/#{params[:id]}" method="post">
|
69
|
+
<div>#{url}</div>
|
39
70
|
<label>Passphrase</label>
|
40
71
|
<input type="text" name="passphrase">
|
41
72
|
<textarea name="commands">
|
42
73
|
#{commands}
|
43
74
|
</textarea>
|
44
|
-
<input type="submit">Submit</
|
75
|
+
<input type="submit">Submit</input>
|
45
76
|
</form>
|
46
77
|
EOF
|
47
78
|
)
|
@@ -66,7 +97,15 @@ EOF
|
|
66
97
|
)
|
67
98
|
end
|
68
99
|
|
69
|
-
post
|
100
|
+
post %r{/push/(.+)} do
|
101
|
+
capture = params[:captures].first.split('/')
|
102
|
+
api_key = capture.shift
|
103
|
+
id = capture.join('/')
|
104
|
+
|
105
|
+
repo = CiInACan::Repo.find id
|
106
|
+
raise 'Could not find this repo' unless repo
|
107
|
+
raise 'Invalid API Key' unless repo.api_key == api_key
|
108
|
+
|
70
109
|
write_a_file_with params
|
71
110
|
end
|
72
111
|
|
data/lib/ci_in_a_can/build.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
module CiInACan
|
2
|
+
|
3
|
+
class Repo
|
4
|
+
|
5
|
+
params_constructor do
|
6
|
+
@api_key = UUID.new.generate unless @api_key
|
7
|
+
@build_commands = [] unless @build_commands
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :id
|
11
|
+
attr_accessor :name
|
12
|
+
attr_accessor :api_key
|
13
|
+
attr_accessor :build_commands
|
14
|
+
|
15
|
+
def self.create data
|
16
|
+
data[:api_key] ||= UUID.new.generate
|
17
|
+
repo_data = { id: data[:id],
|
18
|
+
name: data[:name],
|
19
|
+
api_key: data[:api_key],
|
20
|
+
build_commands: data[:build_commands] }
|
21
|
+
CiInACan::Persistence.save('repos', data[:id], repo_data)
|
22
|
+
find data[:id]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.find id
|
26
|
+
data = CiInACan::Persistence.find('repos', id)
|
27
|
+
return nil unless data
|
28
|
+
CiInACan::Repo.new(data)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.find_by_api_key api_key
|
32
|
+
all.select { |x| x.api_key == api_key }.first
|
33
|
+
end
|
34
|
+
|
35
|
+
def save
|
36
|
+
data = { id: id, name: name, api_key: api_key, build_commands: build_commands }
|
37
|
+
CiInACan::Persistence.save('repos', id, data)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.all
|
41
|
+
blah = CiInACan::Persistence.hash_for("repos")
|
42
|
+
blah.sort_by { |x| x[0] }.reverse.map { |x| new x[1] }
|
43
|
+
end
|
44
|
+
|
45
|
+
def reset_api_key
|
46
|
+
data = CiInACan::Persistence.find('repos', id)
|
47
|
+
data[:api_key] = UUID.new.generate
|
48
|
+
CiInACan::Persistence.save('repos', data[:id], data)
|
49
|
+
end
|
50
|
+
|
51
|
+
def url
|
52
|
+
"/push/#{id}/#{api_key}"
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/lib/ci_in_a_can/version.rb
CHANGED
@@ -20,12 +20,23 @@ describe CiInACan::Build do
|
|
20
20
|
|
21
21
|
describe "commands" do
|
22
22
|
|
23
|
-
|
23
|
+
let(:repo_name) { Object.new }
|
24
|
+
let(:repo) { CiInACan::Repo.new }
|
25
|
+
|
26
|
+
let(:build) do
|
27
|
+
b = CiInACan::Build.new
|
28
|
+
b.repo = repo_name
|
29
|
+
b
|
30
|
+
end
|
24
31
|
|
25
|
-
|
32
|
+
before do
|
33
|
+
CiInACan::Repo.stubs(:find).with(repo_name).returns repo
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "when no build settings exist for the build" do
|
26
37
|
|
27
38
|
before do
|
28
|
-
|
39
|
+
repo.stubs(:build_commands).returns []
|
29
40
|
end
|
30
41
|
|
31
42
|
it "should default commands to the basic ruby conventions" do
|
@@ -39,13 +50,10 @@ describe CiInACan::Build do
|
|
39
50
|
|
40
51
|
describe "when a build setting exists" do
|
41
52
|
|
42
|
-
let(:build) { CiInACan::Build.new }
|
43
53
|
let(:commands_for_build) { [Object.new] }
|
44
54
|
|
45
55
|
before do
|
46
|
-
|
47
|
-
.with(build)
|
48
|
-
.returns commands_for_build
|
56
|
+
repo.stubs(:build_commands).returns commands_for_build
|
49
57
|
end
|
50
58
|
|
51
59
|
it "should return those commands" do
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe CiInACan::Repo do
|
4
|
+
|
5
|
+
before do
|
6
|
+
clear_all_persisted_data
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "create and find" do
|
10
|
+
|
11
|
+
before do
|
12
|
+
uuid = Object.new
|
13
|
+
uuid.stubs(:generate).returns api_key
|
14
|
+
UUID.stubs(:new).returns uuid
|
15
|
+
end
|
16
|
+
|
17
|
+
[:id, :name, :api_key].to_objects {[
|
18
|
+
['abc', 'apple', 'test1'],
|
19
|
+
['123', 'orang', 'test2']
|
20
|
+
]}.each do |data|
|
21
|
+
|
22
|
+
describe "create" do
|
23
|
+
|
24
|
+
let(:api_key) { data.api_key }
|
25
|
+
|
26
|
+
it "should return the repo" do
|
27
|
+
repo = CiInACan::Repo.create(id: data.id)
|
28
|
+
repo.is_a?(CiInACan::Repo).must_equal true
|
29
|
+
repo.id.must_equal data.id
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "finding a record by id" do
|
34
|
+
|
35
|
+
let(:api_key) { data.api_key }
|
36
|
+
|
37
|
+
it "should return a repo with that id" do
|
38
|
+
|
39
|
+
CiInACan::Repo.create( { id: data.id } )
|
40
|
+
|
41
|
+
repo = CiInACan::Repo.find data.id
|
42
|
+
repo.is_a?(CiInACan::Repo).must_equal true
|
43
|
+
repo.id.must_equal data.id
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return the right record if many exist" do
|
47
|
+
|
48
|
+
CiInACan::Repo.create(id: UUID.new.generate)
|
49
|
+
CiInACan::Repo.create(id: data.id)
|
50
|
+
CiInACan::Repo.create(id: UUID.new.generate)
|
51
|
+
|
52
|
+
repo = CiInACan::Repo.find data.id
|
53
|
+
repo.is_a?(CiInACan::Repo).must_equal true
|
54
|
+
repo.id.must_equal data.id
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "finding a record that does not exist" do
|
61
|
+
let(:api_key) { data.api_key }
|
62
|
+
it "should return nil" do
|
63
|
+
CiInACan::Repo.find(data.id).nil?.must_equal true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "attributes" do
|
68
|
+
|
69
|
+
let(:api_key) { data.api_key }
|
70
|
+
|
71
|
+
it "should allow the stamping by name" do
|
72
|
+
CiInACan::Repo.create(id: data.id, name: data.name)
|
73
|
+
|
74
|
+
repo = CiInACan::Repo.find data.id
|
75
|
+
repo.name.must_equal data.name
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should create a unique api key" do
|
79
|
+
CiInACan::Repo.create(id: data.id)
|
80
|
+
|
81
|
+
repo = CiInACan::Repo.find data.id
|
82
|
+
repo.api_key.must_equal data.api_key
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not override the existing api key" do
|
86
|
+
CiInACan::Repo.create(id: data.id,
|
87
|
+
api_key: 'previously set value')
|
88
|
+
|
89
|
+
repo = CiInACan::Repo.find data.id
|
90
|
+
repo.api_key.must_equal 'previously set value'
|
91
|
+
end
|
92
|
+
|
93
|
+
[['one'], ['one', 'two', 'three']].each do |build_commands|
|
94
|
+
describe "different build commands" do
|
95
|
+
it "should store an array of build commands" do
|
96
|
+
repo = CiInACan::Repo.create(id: data.id, build_commands: build_commands)
|
97
|
+
repo.build_commands.must_equal build_commands
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "build commands" do
|
103
|
+
it "should default to an empty array" do
|
104
|
+
CiInACan::Repo.new.build_commands.must_equal []
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "save" do
|
115
|
+
it "should update all of the fields" do
|
116
|
+
repo = CiInACan::Repo.create(id: 'test')
|
117
|
+
repo.name = UUID.new.generate
|
118
|
+
repo.api_key = UUID.new.generate
|
119
|
+
repo.build_commands = [UUID.new.generate]
|
120
|
+
repo.save
|
121
|
+
|
122
|
+
new_repo = CiInACan::Repo.find('test')
|
123
|
+
|
124
|
+
[:name, :api_key, :build_commands].each do |field|
|
125
|
+
new_repo.send(field).must_equal repo.send(field)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "resetting an api key" do
|
131
|
+
it "should reset the api key" do
|
132
|
+
r = CiInACan::Repo.create(id: 'test')
|
133
|
+
original_api_key = r.api_key
|
134
|
+
|
135
|
+
r.reset_api_key
|
136
|
+
|
137
|
+
r = CiInACan::Repo.find('test')
|
138
|
+
new_api_key = r.api_key
|
139
|
+
|
140
|
+
new_api_key.wont_equal original_api_key
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
['test', 'test2'].each do |id|
|
145
|
+
describe "url" do
|
146
|
+
it "should return push/id/api_key" do
|
147
|
+
repo = CiInACan::Repo.create(id: id)
|
148
|
+
repo.url.must_equal "/push/#{repo.id}/#{repo.api_key}"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "all" do
|
154
|
+
it "should return all of the repos" do
|
155
|
+
repo_ids = [CiInACan::Repo.create(id: UUID.new.generate),
|
156
|
+
CiInACan::Repo.create(id: UUID.new.generate),
|
157
|
+
CiInACan::Repo.create(id: UUID.new.generate)].map { |x| x.id }
|
158
|
+
|
159
|
+
actual_ids = CiInACan::Repo.all.map { |x| x.id }.sort_by { |x| x }
|
160
|
+
|
161
|
+
repo_ids.sort_by! { |x| x }
|
162
|
+
actual_ids.sort_by! { |x| x }
|
163
|
+
|
164
|
+
repo_ids.must_equal actual_ids
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "find by api key" do
|
169
|
+
it "should return the repo with the matching api key" do
|
170
|
+
repos = (1..3).to_a.map do |_|
|
171
|
+
CiInACan::Repo.create(id: UUID.new.generate,
|
172
|
+
api_key: UUID.new.generate)
|
173
|
+
end
|
174
|
+
|
175
|
+
repos.each do |repo|
|
176
|
+
found = CiInACan::Repo.find_by_api_key repo.api_key
|
177
|
+
repo.id.must_equal found.id
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ci_in_a_can
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darren Cauthon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -226,12 +226,12 @@ files:
|
|
226
226
|
- lib/ci_in_a_can/bash.rb
|
227
227
|
- lib/ci_in_a_can/bash_result.rb
|
228
228
|
- lib/ci_in_a_can/build.rb
|
229
|
-
- lib/ci_in_a_can/build_setting.rb
|
230
229
|
- lib/ci_in_a_can/cloner.rb
|
231
230
|
- lib/ci_in_a_can/daemon.rb
|
232
231
|
- lib/ci_in_a_can/github.rb
|
233
232
|
- lib/ci_in_a_can/github_build_parser.rb
|
234
233
|
- lib/ci_in_a_can/persistence.rb
|
234
|
+
- lib/ci_in_a_can/repo.rb
|
235
235
|
- lib/ci_in_a_can/run.rb
|
236
236
|
- lib/ci_in_a_can/runner.rb
|
237
237
|
- lib/ci_in_a_can/test_result.rb
|
@@ -246,11 +246,11 @@ files:
|
|
246
246
|
- sample.json
|
247
247
|
- spec/ci_in_a_can/bash_result_spec.rb
|
248
248
|
- spec/ci_in_a_can/bash_spec.rb
|
249
|
-
- spec/ci_in_a_can/build_setting_spec.rb
|
250
249
|
- spec/ci_in_a_can/build_spec.rb
|
251
250
|
- spec/ci_in_a_can/cloner_spec.rb
|
252
251
|
- spec/ci_in_a_can/github_build_parser_spec.rb
|
253
252
|
- spec/ci_in_a_can/github_spec.rb
|
253
|
+
- spec/ci_in_a_can/repo_spec.rb
|
254
254
|
- spec/ci_in_a_can/run_spec.rb
|
255
255
|
- spec/ci_in_a_can/runner_spec.rb
|
256
256
|
- spec/ci_in_a_can/test_result_notifier_spec.rb
|
@@ -287,11 +287,11 @@ summary: Fast CI. Still a WIP.
|
|
287
287
|
test_files:
|
288
288
|
- spec/ci_in_a_can/bash_result_spec.rb
|
289
289
|
- spec/ci_in_a_can/bash_spec.rb
|
290
|
-
- spec/ci_in_a_can/build_setting_spec.rb
|
291
290
|
- spec/ci_in_a_can/build_spec.rb
|
292
291
|
- spec/ci_in_a_can/cloner_spec.rb
|
293
292
|
- spec/ci_in_a_can/github_build_parser_spec.rb
|
294
293
|
- spec/ci_in_a_can/github_spec.rb
|
294
|
+
- spec/ci_in_a_can/repo_spec.rb
|
295
295
|
- spec/ci_in_a_can/run_spec.rb
|
296
296
|
- spec/ci_in_a_can/runner_spec.rb
|
297
297
|
- spec/ci_in_a_can/test_result_notifier_spec.rb
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe CiInACan::BuildSetting do
|
4
|
-
|
5
|
-
let(:persistence_type) { 'build_commands' }
|
6
|
-
|
7
|
-
before do
|
8
|
-
clear_all_persisted_data
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "commands for a build" do
|
12
|
-
|
13
|
-
describe "bad build" do
|
14
|
-
it "should default to nothing" do
|
15
|
-
CiInACan::BuildSetting.commands_for(nil).must_equal []
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
[:repo, :commands].to_objects {[
|
20
|
-
['abc', ['1', '2', '3']],
|
21
|
-
['def', ['4', '5', '6']]
|
22
|
-
]}.each do |test|
|
23
|
-
|
24
|
-
describe "settings for the build repo exist" do
|
25
|
-
|
26
|
-
it "should return the settings" do
|
27
|
-
|
28
|
-
CiInACan::Persistence.save(persistence_type, test.repo, { commands: test.commands } )
|
29
|
-
|
30
|
-
build = CiInACan::Build.new(repo: test.repo)
|
31
|
-
|
32
|
-
commands = CiInACan::BuildSetting.commands_for build
|
33
|
-
|
34
|
-
commands.must_equal test.commands
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|