txgh-server 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/txgh-server/application.rb +141 -0
- data/lib/txgh-server/download_handler.rb +85 -0
- data/lib/txgh-server/github_request_auth.rb +28 -0
- data/lib/txgh-server/response.rb +15 -0
- data/lib/txgh-server/response_helpers.rb +26 -0
- data/lib/txgh-server/stream_response.rb +37 -0
- data/lib/txgh-server/tgz_stream_response.rb +39 -0
- data/lib/txgh-server/transifex_request_auth.rb +53 -0
- data/lib/txgh-server/triggers/handler.rb +50 -0
- data/lib/txgh-server/triggers/pull_handler.rb +18 -0
- data/lib/txgh-server/triggers/push_handler.rb +18 -0
- data/lib/txgh-server/triggers.rb +7 -0
- data/lib/txgh-server/version.rb +3 -0
- data/lib/txgh-server/webhooks/github/delete_handler.rb +37 -0
- data/lib/txgh-server/webhooks/github/handler.rb +20 -0
- data/lib/txgh-server/webhooks/github/ping_handler.rb +18 -0
- data/lib/txgh-server/webhooks/github/push_handler.rb +124 -0
- data/lib/txgh-server/webhooks/github/request_handler.rb +113 -0
- data/lib/txgh-server/webhooks/github.rb +11 -0
- data/lib/txgh-server/webhooks/transifex/hook_handler.rb +94 -0
- data/lib/txgh-server/webhooks/transifex/request_handler.rb +78 -0
- data/lib/txgh-server/webhooks/transifex.rb +8 -0
- data/lib/txgh-server/webhooks.rb +6 -0
- data/lib/txgh-server/zip_stream_response.rb +19 -0
- data/lib/txgh-server.rb +23 -0
- data/spec/application_spec.rb +347 -0
- data/spec/download_handler_spec.rb +91 -0
- data/spec/github_request_auth_spec.rb +39 -0
- data/spec/helpers/github_payload_builder.rb +141 -0
- data/spec/helpers/integration_setup.rb +47 -0
- data/spec/integration/cassettes/github_l10n_hook_endpoint.yml +536 -0
- data/spec/integration/cassettes/pull.yml +47 -0
- data/spec/integration/cassettes/push.yml +544 -0
- data/spec/integration/cassettes/transifex_hook_endpoint.yml +221 -0
- data/spec/integration/config/tx.config +10 -0
- data/spec/integration/hooks_spec.rb +159 -0
- data/spec/integration/payloads/github_postbody.json +161 -0
- data/spec/integration/payloads/github_postbody_l10n.json +136 -0
- data/spec/integration/payloads/github_postbody_release.json +136 -0
- data/spec/integration/triggers_spec.rb +45 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/tgz_stream_response_spec.rb +59 -0
- data/spec/transifex_request_auth_spec.rb +39 -0
- data/spec/webhooks/github/delete_handler_spec.rb +38 -0
- data/spec/webhooks/github/ping_handler_spec.rb +16 -0
- data/spec/webhooks/github/push_handler_spec.rb +106 -0
- data/spec/webhooks/transifex/hook_handler_spec.rb +136 -0
- data/spec/zip_stream_response_spec.rb +58 -0
- data/txgh-server.gemspec +24 -0
- metadata +170 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'helpers/nil_logger'
|
3
|
+
require 'helpers/standard_txgh_setup'
|
4
|
+
|
5
|
+
include TxghServer
|
6
|
+
include TxghServer::Webhooks::Transifex
|
7
|
+
|
8
|
+
describe HookHandler do
|
9
|
+
include StandardTxghSetup
|
10
|
+
|
11
|
+
let(:requested_resource_slug) do
|
12
|
+
resource_slug
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:handler) do
|
16
|
+
HookHandler.new(
|
17
|
+
project: transifex_project,
|
18
|
+
repo: github_repo,
|
19
|
+
resource_slug: requested_resource_slug,
|
20
|
+
language: language,
|
21
|
+
logger: logger
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:downloader) do
|
26
|
+
instance_double(Txgh::ResourceDownloader)
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:file_name) do
|
30
|
+
"translations/#{language}/sample.yml"
|
31
|
+
end
|
32
|
+
|
33
|
+
before(:each) do
|
34
|
+
allow(Txgh::ResourceDownloader).to receive(:new).and_return(downloader)
|
35
|
+
allow(downloader).to(receive(:first)).and_return([
|
36
|
+
"translations/#{language}/sample.yml", translations
|
37
|
+
])
|
38
|
+
|
39
|
+
allow(github_api).to receive(:get_ref).and_return(
|
40
|
+
object: { sha: '123abcshashasha' }
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'downloads translations and pushes them to the correct branch (head)' do
|
45
|
+
expect(github_api).to(
|
46
|
+
receive(:update_contents).with(
|
47
|
+
repo_name, "heads/#{branch}",
|
48
|
+
{ "translations/#{language}/sample.yml" => translations },
|
49
|
+
"Updating #{language} translations in #{file_name}"
|
50
|
+
)
|
51
|
+
)
|
52
|
+
|
53
|
+
response = handler.execute
|
54
|
+
expect(response.status).to eq(200)
|
55
|
+
expect(response.body).to eq(true)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "responds with an error if the config can't be found" do
|
59
|
+
expect(handler).to receive(:tx_config).and_return(nil)
|
60
|
+
response = handler.execute
|
61
|
+
expect(response.status).to eq(404)
|
62
|
+
expect(response.body).to eq([
|
63
|
+
{ error: "Could not find configuration for branch 'heads/#{branch}'" }
|
64
|
+
])
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'with a non-existent resource' do
|
68
|
+
let(:requested_resource_slug) { 'foobarbazboo' }
|
69
|
+
|
70
|
+
it "responds with an error if the resource can't be found" do
|
71
|
+
response = handler.execute
|
72
|
+
expect(response.status).to eq(404)
|
73
|
+
expect(response.body).to eq(
|
74
|
+
[{ error: "Could not find resource '#{requested_resource_slug}' in config" }]
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when asked to process all branches' do
|
80
|
+
let(:branch) { 'all' }
|
81
|
+
let(:ref) { 'heads/my_branch' }
|
82
|
+
|
83
|
+
let(:requested_resource_slug) do
|
84
|
+
'my_resource-heads_my_branch'
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'pushes to the individual branch' do
|
88
|
+
expect(transifex_api).to receive(:get_resource) do
|
89
|
+
{ 'categories' => ["branch:#{ref}"] }
|
90
|
+
end
|
91
|
+
|
92
|
+
expect(github_api).to(
|
93
|
+
receive(:update_contents).with(
|
94
|
+
repo_name, ref,
|
95
|
+
{ "translations/#{language}/sample.yml" => translations },
|
96
|
+
"Updating #{language} translations in #{file_name}"
|
97
|
+
)
|
98
|
+
)
|
99
|
+
|
100
|
+
response = handler.execute
|
101
|
+
expect(response.status).to eq(200)
|
102
|
+
expect(response.body).to eq(true)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'with a tag instead of a branch' do
|
107
|
+
let(:branch) { 'tags/my_tag' }
|
108
|
+
|
109
|
+
it 'downloads translations and pushes them to the tag' do
|
110
|
+
expect(github_api).to(
|
111
|
+
receive(:update_contents).with(
|
112
|
+
repo_name, "tags/my_tag",
|
113
|
+
{ "translations/#{language}/sample.yml" => translations },
|
114
|
+
"Updating #{language} translations in #{file_name}"
|
115
|
+
)
|
116
|
+
)
|
117
|
+
|
118
|
+
response = handler.execute
|
119
|
+
expect(response.status).to eq(200)
|
120
|
+
expect(response.body).to eq(true)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'with an unsupported language' do
|
125
|
+
let(:language) { 'pt' }
|
126
|
+
let(:supported_languages) { ['ja'] }
|
127
|
+
|
128
|
+
it "doesn't make a commit" do
|
129
|
+
expect(github_api).to_not receive(:update_contents)
|
130
|
+
|
131
|
+
response = handler.execute
|
132
|
+
expect(response.status).to eq(304)
|
133
|
+
expect(response.body).to eq(true)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
include TxghServer
|
5
|
+
|
6
|
+
describe ZipStreamResponse do
|
7
|
+
def read_zip_from(file)
|
8
|
+
contents = {}
|
9
|
+
|
10
|
+
Zip::File.open(file) do |zipfile|
|
11
|
+
zipfile.each do |entry|
|
12
|
+
contents[entry.name] = entry.get_input_stream.read
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
contents
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:attachment) { 'abc123' }
|
20
|
+
|
21
|
+
let(:enum) do
|
22
|
+
{
|
23
|
+
'first_file.yml' => "first\nfile\ncontents\n",
|
24
|
+
'second_file.yml' => "wowowow\nanother file!\n"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:response) do
|
29
|
+
ZipStreamResponse.new(attachment, enum)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#write_to' do
|
33
|
+
it 'writes a zip file with the correct entries to the stream' do
|
34
|
+
# this does NOT WORK with a StringIO - zip contents MUST be written to a file
|
35
|
+
io = Tempfile.new('testzip')
|
36
|
+
response.write_to(io)
|
37
|
+
contents = read_zip_from(io.path)
|
38
|
+
expect(contents).to eq(enum)
|
39
|
+
io.close
|
40
|
+
io.unlink
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#headers' do
|
45
|
+
it 'includes the correct content type and disposition headers' do
|
46
|
+
expect(response.headers).to eq({
|
47
|
+
'Content-Disposition' => "attachment; filename=\"#{attachment}.zip\"",
|
48
|
+
'Content-Type' => 'application/zip'
|
49
|
+
})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#streaming?' do
|
54
|
+
it 'returns true' do
|
55
|
+
expect(response).to be_streaming
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/txgh-server.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), 'lib')
|
2
|
+
require 'txgh-server/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'txgh-server'
|
6
|
+
s.version = ::TxghServer::VERSION
|
7
|
+
s.authors = ['Matthew Jackowski', 'Cameron Dutro']
|
8
|
+
s.email = ['mattjjacko@gmail.com', 'camertron@gmail.com']
|
9
|
+
s.homepage = 'https://github.com/lumoslabs/txgh-server'
|
10
|
+
|
11
|
+
s.description = s.summary = 'An HTTP server for interacting with txgh.'
|
12
|
+
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.has_rdoc = true
|
15
|
+
|
16
|
+
s.add_dependency 'mime-types', '~> 2.0'
|
17
|
+
s.add_dependency 'sinatra', '~> 1.4'
|
18
|
+
s.add_dependency 'sinatra-contrib', '~> 1.4'
|
19
|
+
s.add_dependency 'rubyzip', '>= 1.0', '<= 1.1.2'
|
20
|
+
s.add_dependency 'txgh', '~> 5.0'
|
21
|
+
|
22
|
+
s.require_path = 'lib'
|
23
|
+
s.files = Dir['{lib,spec}/**/*', 'README.md', 'txgh-server.gemspec', 'LICENSE']
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: txgh-server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.beta1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Jackowski
|
8
|
+
- Cameron Dutro
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-08-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mime-types
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sinatra
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.4'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.4'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: sinatra-contrib
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.4'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.4'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rubyzip
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.0'
|
63
|
+
- - "<="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.1.2
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '1.0'
|
73
|
+
- - "<="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.1.2
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: txgh
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
type: :runtime
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
description: An HTTP server for interacting with txgh.
|
91
|
+
email:
|
92
|
+
- mattjjacko@gmail.com
|
93
|
+
- camertron@gmail.com
|
94
|
+
executables: []
|
95
|
+
extensions: []
|
96
|
+
extra_rdoc_files: []
|
97
|
+
files:
|
98
|
+
- lib/txgh-server.rb
|
99
|
+
- lib/txgh-server/application.rb
|
100
|
+
- lib/txgh-server/download_handler.rb
|
101
|
+
- lib/txgh-server/github_request_auth.rb
|
102
|
+
- lib/txgh-server/response.rb
|
103
|
+
- lib/txgh-server/response_helpers.rb
|
104
|
+
- lib/txgh-server/stream_response.rb
|
105
|
+
- lib/txgh-server/tgz_stream_response.rb
|
106
|
+
- lib/txgh-server/transifex_request_auth.rb
|
107
|
+
- lib/txgh-server/triggers.rb
|
108
|
+
- lib/txgh-server/triggers/handler.rb
|
109
|
+
- lib/txgh-server/triggers/pull_handler.rb
|
110
|
+
- lib/txgh-server/triggers/push_handler.rb
|
111
|
+
- lib/txgh-server/version.rb
|
112
|
+
- lib/txgh-server/webhooks.rb
|
113
|
+
- lib/txgh-server/webhooks/github.rb
|
114
|
+
- lib/txgh-server/webhooks/github/delete_handler.rb
|
115
|
+
- lib/txgh-server/webhooks/github/handler.rb
|
116
|
+
- lib/txgh-server/webhooks/github/ping_handler.rb
|
117
|
+
- lib/txgh-server/webhooks/github/push_handler.rb
|
118
|
+
- lib/txgh-server/webhooks/github/request_handler.rb
|
119
|
+
- lib/txgh-server/webhooks/transifex.rb
|
120
|
+
- lib/txgh-server/webhooks/transifex/hook_handler.rb
|
121
|
+
- lib/txgh-server/webhooks/transifex/request_handler.rb
|
122
|
+
- lib/txgh-server/zip_stream_response.rb
|
123
|
+
- spec/application_spec.rb
|
124
|
+
- spec/download_handler_spec.rb
|
125
|
+
- spec/github_request_auth_spec.rb
|
126
|
+
- spec/helpers/github_payload_builder.rb
|
127
|
+
- spec/helpers/integration_setup.rb
|
128
|
+
- spec/integration/cassettes/github_l10n_hook_endpoint.yml
|
129
|
+
- spec/integration/cassettes/pull.yml
|
130
|
+
- spec/integration/cassettes/push.yml
|
131
|
+
- spec/integration/cassettes/transifex_hook_endpoint.yml
|
132
|
+
- spec/integration/config/tx.config
|
133
|
+
- spec/integration/hooks_spec.rb
|
134
|
+
- spec/integration/payloads/github_postbody.json
|
135
|
+
- spec/integration/payloads/github_postbody_l10n.json
|
136
|
+
- spec/integration/payloads/github_postbody_release.json
|
137
|
+
- spec/integration/triggers_spec.rb
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
- spec/tgz_stream_response_spec.rb
|
140
|
+
- spec/transifex_request_auth_spec.rb
|
141
|
+
- spec/webhooks/github/delete_handler_spec.rb
|
142
|
+
- spec/webhooks/github/ping_handler_spec.rb
|
143
|
+
- spec/webhooks/github/push_handler_spec.rb
|
144
|
+
- spec/webhooks/transifex/hook_handler_spec.rb
|
145
|
+
- spec/zip_stream_response_spec.rb
|
146
|
+
- txgh-server.gemspec
|
147
|
+
homepage: https://github.com/lumoslabs/txgh-server
|
148
|
+
licenses: []
|
149
|
+
metadata: {}
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">"
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: 1.3.1
|
164
|
+
requirements: []
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 2.2.3
|
167
|
+
signing_key:
|
168
|
+
specification_version: 4
|
169
|
+
summary: An HTTP server for interacting with txgh.
|
170
|
+
test_files: []
|