fourchette 0.0.6 → 0.0.7
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/Guardfile +5 -0
- data/fourchette.gemspec +2 -0
- data/lib/fourchette.rb +2 -1
- data/lib/fourchette/fork.rb +18 -6
- data/lib/fourchette/tarball.rb +43 -0
- data/lib/fourchette/version.rb +1 -1
- data/lib/fourchette/web.rb +2 -1
- data/lib/fourchette/web/tarball.rb +10 -0
- data/spec/factories/fake_file +1 -0
- data/spec/lib/fourchette/tarball_spec.rb +44 -0
- data/spec/lib/web/tarball_spec.rb +35 -0
- data/spec/spec_helper.rb +1 -0
- metadata +39 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3d2dcc715d8a2c65fe34a0248a6089bcfb5762a
|
4
|
+
data.tar.gz: 74456ce01a2cff7e4939f04efc7b0c49891597a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8055c8a81b2dc7253139b50b42e5fbd7188c137246ff73a44a4e0ce9a15ea9539a12dacab07f7893f56d389a7bac072aa18688f7f51357617aac2971118e4e4
|
7
|
+
data.tar.gz: 69ba6c5cc5d1e26972a865ef438168e154f879cc9e419405d760c0c881a0e58897f98adf5a8d026cf1281776c9c4b78a54162b3f87c01330f545cac63234acb9
|
data/Guardfile
ADDED
data/fourchette.gemspec
CHANGED
@@ -31,5 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency 'foreman'
|
32
32
|
spec.add_development_dependency 'pry-debugger'
|
33
33
|
spec.add_development_dependency 'rspec', '~> 2.14.1'
|
34
|
+
spec.add_development_dependency 'guard-rspec'
|
35
|
+
spec.add_development_dependency 'terminal-notifier-guard'
|
34
36
|
spec.add_development_dependency 'coveralls'
|
35
37
|
end
|
data/lib/fourchette.rb
CHANGED
@@ -40,4 +40,5 @@ require_relative 'fourchette/pull_request'
|
|
40
40
|
require_relative 'fourchette/fork'
|
41
41
|
require_relative 'fourchette/heroku'
|
42
42
|
require_relative 'fourchette/pgbackups'
|
43
|
-
require_relative 'fourchette/callbacks'
|
43
|
+
require_relative 'fourchette/callbacks'
|
44
|
+
require_relative 'fourchette/tarball'
|
data/lib/fourchette/fork.rb
CHANGED
@@ -9,10 +9,11 @@ class Fourchette::Fork
|
|
9
9
|
|
10
10
|
def update
|
11
11
|
create_unless_exists
|
12
|
-
|
12
|
+
tarball = Fourchette::Tarball.new
|
13
|
+
tarball_url = tarball.url(github_git_url, git_branch_name, ENV['FOURCHETTE_GITHUB_PROJECT'])
|
13
14
|
options = {
|
14
15
|
source_blob: {
|
15
|
-
url:
|
16
|
+
url: tarball_url
|
16
17
|
}
|
17
18
|
}
|
18
19
|
|
@@ -21,12 +22,15 @@ class Fourchette::Fork
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def monitor_build build
|
25
|
+
logger.info "Start of the build process on Heroku..."
|
24
26
|
build_info = @heroku.client.build.info(fork_name, build['id'])
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
# Let's just leave some time to Heroku to download the tarball and start
|
28
|
+
# the process. This is some random timing that seems to make sense at first.
|
29
|
+
sleep 30
|
30
|
+
if build_info['status'] == 'failed'
|
31
|
+
@github.comment_pr(pr_number, "The build failed on Herok. See the activity tab on Heroku.")
|
32
|
+
fail Fourchette::DeployException
|
28
33
|
end
|
29
|
-
fail Fourchette::DeployException if build_info['status'] == 'failed'
|
30
34
|
end
|
31
35
|
|
32
36
|
def create
|
@@ -62,4 +66,12 @@ class Fourchette::Fork
|
|
62
66
|
@github.comment_pr(pr_number, "Test URL: #{@heroku.client.app.info(fork_name)['web_url']}")
|
63
67
|
end
|
64
68
|
end
|
69
|
+
|
70
|
+
def git_branch_name
|
71
|
+
"remotes/origin/#{branch_name}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def github_git_url
|
75
|
+
@params['pull_request']['head']['repo']['clone_url'].gsub("//github.com", "//#{ENV['FOURCHETTE_GITHUB_USERNAME']}:#{ENV['FOURCHETTE_GITHUB_PERSONAL_TOKEN']}@github.com")
|
76
|
+
end
|
65
77
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
class Fourchette::Tarball
|
3
|
+
include Fourchette::Logger
|
4
|
+
|
5
|
+
def url(github_git_url, branch_name, github_repo)
|
6
|
+
filepath = prepare_tarball(github_git_url, branch_name)
|
7
|
+
tarball_to_url(filepath, github_repo)
|
8
|
+
end
|
9
|
+
|
10
|
+
def filepath(uuid, expiration)
|
11
|
+
"tmp/#{uuid}/#{expiration}.tar.gz"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def prepare_tarball(github_git_url, branch_name)
|
16
|
+
clone_path = "tmp/#{SecureRandom.uuid}"
|
17
|
+
clone(github_git_url, branch_name, clone_path)
|
18
|
+
tar(clone_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def clone(github_git_url,branch_name, clone_path)
|
22
|
+
logger.info "Cloning repository..."
|
23
|
+
repo = Git.clone(github_git_url, clone_path, recursive: true)
|
24
|
+
repo.checkout(branch_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def tar(path)
|
28
|
+
logger.info "Preparing tarball..."
|
29
|
+
filepath = "#{path}/#{expiration_timestamp}.tar.gz"
|
30
|
+
system("tar -zcvf #{filepath} -C #{path} .")
|
31
|
+
filepath
|
32
|
+
end
|
33
|
+
|
34
|
+
def expiration_timestamp
|
35
|
+
Time.now.to_i + 300
|
36
|
+
end
|
37
|
+
|
38
|
+
def tarball_to_url(filepath, github_repo)
|
39
|
+
logger.info "Tarball to URL as a service in progress..."
|
40
|
+
cleaned_path = filepath.gsub('tmp/', '').gsub('.tar.gz', '')
|
41
|
+
"#{ENV['FOURCHETTE_APP_URL']}/#{github_repo}/#{cleaned_path}"
|
42
|
+
end
|
43
|
+
end
|
data/lib/fourchette/version.rb
CHANGED
data/lib/fourchette/web.rb
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
require_relative 'web/hooks'
|
1
|
+
require_relative 'web/hooks'
|
2
|
+
require_relative 'web/tarball'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
get '/:github_user/:github_repo/:uuid/:expiration_timestamp' do
|
2
|
+
if params['expiration_timestamp'].to_i < Time.now.to_i
|
3
|
+
status 404
|
4
|
+
'Oops...'
|
5
|
+
else
|
6
|
+
logger.info('Serving a tarball!')
|
7
|
+
filepath = Fourchette::Tarball.new.filepath(params['uuid'], params['expiration_timestamp'])
|
8
|
+
send_file filepath, :type => 'application/x-tgz'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
some content...
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fourchette::Tarball do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe '#url' do
|
7
|
+
let(:git_repo_url) { 'git://github.com/jipiboily/fourchette.git' }
|
8
|
+
let(:github_repo) { 'jipiboily/fourchette' }
|
9
|
+
let(:branch_name) { 'feature/something-new' }
|
10
|
+
|
11
|
+
before do
|
12
|
+
subject.stub(:expiration_timestamp).and_return('123')
|
13
|
+
subject.stub(:clone)
|
14
|
+
subject.stub(:tar).and_return('tmp/1234567/123.tar.gz')
|
15
|
+
subject.stub(:system)
|
16
|
+
stub_const('ENV', {'FOURCHETTE_APP_URL' => 'http://example.com'})
|
17
|
+
SecureRandom.stub(:uuid).and_return('1234567')
|
18
|
+
end
|
19
|
+
|
20
|
+
it {
|
21
|
+
expect(
|
22
|
+
subject.url(git_repo_url, branch_name, github_repo)
|
23
|
+
).to eq "http://example.com/jipiboily/fourchette/1234567/123"
|
24
|
+
}
|
25
|
+
|
26
|
+
it 'clones the repo and checkout the branch' do
|
27
|
+
subject.unstub(:clone)
|
28
|
+
git_instance = double
|
29
|
+
Git.should_receive(:clone).with(git_repo_url, "tmp/1234567", recursive: true).and_return(git_instance)
|
30
|
+
git_instance.should_receive(:checkout).with(branch_name)
|
31
|
+
subject.url(git_repo_url, branch_name, github_repo)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'creates the tarball' do
|
35
|
+
subject.unstub(:tar)
|
36
|
+
subject.should_receive(:system).with 'tar -zcvf tmp/1234567/123.tar.gz -C tmp/1234567 .'
|
37
|
+
subject.url(git_repo_url, branch_name, github_repo)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#filepath' do
|
42
|
+
it { expect(subject.filepath('1234567', '123')).to eq 'tmp/1234567/123.tar.gz' }
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rack/test'
|
3
|
+
|
4
|
+
describe 'web tarball serving' do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
def app
|
8
|
+
Sinatra::Application
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'valid and not expired URL' do
|
12
|
+
it "returns the file" do
|
13
|
+
expire_in_2_secs = Time.now.to_i + 2
|
14
|
+
Fourchette::Tarball.any_instance
|
15
|
+
.should_receive(:filepath)
|
16
|
+
.with('1234567', expire_in_2_secs.to_s)
|
17
|
+
.and_return { "#{Dir.pwd}/spec/factories/fake_file" }
|
18
|
+
|
19
|
+
get "/jipiboily/fourchette/1234567/#{expire_in_2_secs}"
|
20
|
+
expect(last_response.headers['Content-Type']).to eq "application/x-tgz"
|
21
|
+
expect(last_response.body).to eq 'some content...'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'expired URL' do
|
26
|
+
it "does NOT returns the file if it is expired" do
|
27
|
+
expired_one_sec_ago = Time.now.to_i - 1
|
28
|
+
get "/jipiboily/fourchette/1234567/#{expired_one_sec_ago}"
|
29
|
+
expect(last_response).not_to be_ok
|
30
|
+
expect(last_response.body).not_to eq('Hello World')
|
31
|
+
expect(last_response.status).to eq(404)
|
32
|
+
subject.should_not_receive(:send_file)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fourchette
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean-Philippe Boily
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -178,6 +178,34 @@ dependencies:
|
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: 2.14.1
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: guard-rspec
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: terminal-notifier-guard
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
181
209
|
- !ruby/object:Gem::Dependency
|
182
210
|
name: coveralls
|
183
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -207,6 +235,7 @@ files:
|
|
207
235
|
- ".gitignore"
|
208
236
|
- ".travis.yml"
|
209
237
|
- Gemfile
|
238
|
+
- Guardfile
|
210
239
|
- LICENSE.txt
|
211
240
|
- Procfile
|
212
241
|
- README.md
|
@@ -223,11 +252,16 @@ files:
|
|
223
252
|
- lib/fourchette/pgbackups.rb
|
224
253
|
- lib/fourchette/pull_request.rb
|
225
254
|
- lib/fourchette/rake_tasks.rb
|
255
|
+
- lib/fourchette/tarball.rb
|
226
256
|
- lib/fourchette/version.rb
|
227
257
|
- lib/fourchette/web.rb
|
228
258
|
- lib/fourchette/web/hooks.rb
|
259
|
+
- lib/fourchette/web/tarball.rb
|
260
|
+
- spec/factories/fake_file
|
229
261
|
- spec/lib/fourchette/heroku_spec.rb
|
230
262
|
- spec/lib/fourchette/pull_request_spec.rb
|
263
|
+
- spec/lib/fourchette/tarball_spec.rb
|
264
|
+
- spec/lib/web/tarball_spec.rb
|
231
265
|
- spec/spec_helper.rb
|
232
266
|
- spec/support/silent-logger.rb
|
233
267
|
- templates/Gemfile
|
@@ -261,7 +295,10 @@ signing_key:
|
|
261
295
|
specification_version: 4
|
262
296
|
summary: Your new best friend for isolated testing environments on Heroku.
|
263
297
|
test_files:
|
298
|
+
- spec/factories/fake_file
|
264
299
|
- spec/lib/fourchette/heroku_spec.rb
|
265
300
|
- spec/lib/fourchette/pull_request_spec.rb
|
301
|
+
- spec/lib/fourchette/tarball_spec.rb
|
302
|
+
- spec/lib/web/tarball_spec.rb
|
266
303
|
- spec/spec_helper.rb
|
267
304
|
- spec/support/silent-logger.rb
|