txgh 5.3.4 → 5.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/txgh/resource_deleter.rb +50 -0
- data/lib/txgh/version.rb +1 -1
- data/lib/txgh.rb +1 -6
- data/spec/resource_deleter_spec.rb +48 -0
- data/spec/spec_helper.rb +0 -8
- data/txgh.gemspec +1 -5
- metadata +6 -113
- data/lib/ext/zipline/output_stream.rb +0 -62
- data/lib/txgh/app.rb +0 -140
- data/lib/txgh/github_request_auth.rb +0 -28
- data/lib/txgh/handlers/download_handler.rb +0 -87
- data/lib/txgh/handlers/github/delete_handler.rb +0 -65
- data/lib/txgh/handlers/github/handler.rb +0 -20
- data/lib/txgh/handlers/github/ping_handler.rb +0 -18
- data/lib/txgh/handlers/github/push_handler.rb +0 -124
- data/lib/txgh/handlers/github/request_handler.rb +0 -113
- data/lib/txgh/handlers/github.rb +0 -11
- data/lib/txgh/handlers/response.rb +0 -17
- data/lib/txgh/handlers/stream_response.rb +0 -39
- data/lib/txgh/handlers/tgz_stream_response.rb +0 -41
- data/lib/txgh/handlers/transifex/hook_handler.rb +0 -94
- data/lib/txgh/handlers/transifex/request_handler.rb +0 -78
- data/lib/txgh/handlers/transifex.rb +0 -8
- data/lib/txgh/handlers/triggers/handler.rb +0 -52
- data/lib/txgh/handlers/triggers/pull_handler.rb +0 -20
- data/lib/txgh/handlers/triggers/push_handler.rb +0 -20
- data/lib/txgh/handlers/triggers.rb +0 -9
- data/lib/txgh/handlers/zip_stream_response.rb +0 -21
- data/lib/txgh/handlers.rb +0 -12
- data/lib/txgh/transifex_request_auth.rb +0 -53
- data/spec/app_spec.rb +0 -347
- data/spec/github_request_auth_spec.rb +0 -39
- data/spec/handlers/download_handler_spec.rb +0 -91
- data/spec/handlers/github/delete_handler_spec.rb +0 -71
- data/spec/handlers/github/ping_handler_spec.rb +0 -16
- data/spec/handlers/github/push_handler_spec.rb +0 -106
- data/spec/handlers/tgz_stream_response_spec.rb +0 -59
- data/spec/handlers/transifex/hook_handler_spec.rb +0 -136
- data/spec/handlers/zip_stream_response_spec.rb +0 -58
- data/spec/helpers/github_payload_builder.rb +0 -141
- data/spec/helpers/integration_setup.rb +0 -47
- data/spec/integration/cassettes/github_l10n_hook_endpoint.yml +0 -536
- data/spec/integration/cassettes/pull.yml +0 -47
- data/spec/integration/cassettes/push.yml +0 -544
- data/spec/integration/cassettes/transifex_hook_endpoint.yml +0 -221
- data/spec/integration/config/tx.config +0 -10
- data/spec/integration/hooks_spec.rb +0 -159
- data/spec/integration/payloads/github_postbody.json +0 -161
- data/spec/integration/payloads/github_postbody_l10n.json +0 -136
- data/spec/integration/payloads/github_postbody_release.json +0 -136
- data/spec/integration/triggers_spec.rb +0 -45
- data/spec/transifex_request_auth_spec.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb6e3463432f659922924f0e8772d52ff629d56e
|
4
|
+
data.tar.gz: b2ae04fce6e467c3e288f4719fa6b21428e21458
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea6b213e8f7b13a610324114f192542f22ab018697373b12d5299d590f680c6cf25da29fe699a21ae8d4c391980c04ecbe89c6e97bfb615ecbaffa95a74fce4b
|
7
|
+
data.tar.gz: 00e05c87d887ce50b9fd26f252950bc7acde5511e73b29065f09197838e4d74468feebd9d2568e98771b4890df652b32543c17c49887cd6c283c3cbbd47616d7
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Txgh
|
2
|
+
class ResourceDeleter
|
3
|
+
include Txgh::CategorySupport
|
4
|
+
|
5
|
+
attr_reader :project, :repo, :branch
|
6
|
+
|
7
|
+
def initialize(project, repo, branch, options = {})
|
8
|
+
@project = project
|
9
|
+
@repo = repo
|
10
|
+
@branch = branch
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete_resources
|
14
|
+
tx_resources.each do |tx_resource|
|
15
|
+
project.api.delete_resource(tx_resource)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def tx_resources
|
22
|
+
project.api.get_resources(project.name).map do |resource_hash|
|
23
|
+
categories = deserialize_categories(resource_hash['categories'])
|
24
|
+
resource_branch = Txgh::Utils.absolute_branch(categories['branch'])
|
25
|
+
|
26
|
+
if resource_branch == branch
|
27
|
+
tx_branch_resource_from(resource_hash, branch)
|
28
|
+
end
|
29
|
+
end.compact
|
30
|
+
end
|
31
|
+
|
32
|
+
def tx_branch_resource_from(resource_hash, branch)
|
33
|
+
Txgh::TxBranchResource.new(
|
34
|
+
tx_resource_from(resource_hash, branch), branch
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
# project_slug, resource_slug, type, source_lang, source_file, lang_map, translation_file
|
39
|
+
def tx_resource_from(resource_hash, branch)
|
40
|
+
Txgh::TxResource.new(
|
41
|
+
project.name,
|
42
|
+
Txgh::TxBranchResource.deslugify(resource_hash['slug'], branch),
|
43
|
+
resource_hash['i18n_type'],
|
44
|
+
resource_hash['source_language_code'],
|
45
|
+
resource_hash['name'],
|
46
|
+
'', nil
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/txgh/version.rb
CHANGED
data/lib/txgh.rb
CHANGED
@@ -2,7 +2,6 @@ require 'txgh/errors'
|
|
2
2
|
require 'yaml'
|
3
3
|
|
4
4
|
module Txgh
|
5
|
-
autoload :Application, 'txgh/app'
|
6
5
|
autoload :CategorySupport, 'txgh/category_support'
|
7
6
|
autoload :Config, 'txgh/config'
|
8
7
|
autoload :DiffCalculator, 'txgh/diff_calculator'
|
@@ -10,23 +9,19 @@ module Txgh
|
|
10
9
|
autoload :Events, 'txgh/events'
|
11
10
|
autoload :GithubApi, 'txgh/github_api'
|
12
11
|
autoload :GithubRepo, 'txgh/github_repo'
|
13
|
-
autoload :GithubRequestAuth, 'txgh/github_request_auth'
|
14
12
|
autoload :GithubStatus, 'txgh/github_status'
|
15
|
-
autoload :Handlers, 'txgh/handlers'
|
16
|
-
autoload :Hooks, 'txgh/app'
|
17
13
|
autoload :MergeCalculator, 'txgh/merge_calculator'
|
18
14
|
autoload :ParseConfig, 'txgh/parse_config'
|
19
15
|
autoload :Puller, 'txgh/puller'
|
20
16
|
autoload :Pusher, 'txgh/pusher'
|
21
17
|
autoload :ResourceCommitter, 'txgh/resource_committer'
|
22
18
|
autoload :ResourceContents, 'txgh/resource_contents'
|
19
|
+
autoload :ResourceDeleter, 'txgh/resource_deleter'
|
23
20
|
autoload :ResourceDownloader, 'txgh/resource_downloader'
|
24
21
|
autoload :ResourceUpdater, 'txgh/resource_updater'
|
25
22
|
autoload :ResponseHelpers, 'txgh/response_helpers'
|
26
23
|
autoload :TransifexApi, 'txgh/transifex_api'
|
27
24
|
autoload :TransifexProject, 'txgh/transifex_project'
|
28
|
-
autoload :TransifexRequestAuth, 'txgh/transifex_request_auth'
|
29
|
-
autoload :Triggers, 'txgh/app'
|
30
25
|
autoload :TxBranchResource, 'txgh/tx_branch_resource'
|
31
26
|
autoload :TxLogger, 'txgh/tx_logger'
|
32
27
|
autoload :TxResource, 'txgh/tx_resource'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'helpers/standard_txgh_setup'
|
3
|
+
|
4
|
+
include Txgh
|
5
|
+
|
6
|
+
describe ResourceDeleter do
|
7
|
+
include StandardTxghSetup
|
8
|
+
|
9
|
+
# process all branches
|
10
|
+
let(:branch) { 'heads/master' }
|
11
|
+
|
12
|
+
let(:deleter) do
|
13
|
+
ResourceDeleter.new(transifex_project, github_repo, branch)
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:resource_api_response) do
|
17
|
+
[resource.to_api_h.merge('categories' => ["branch:#{branch}"])]
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:resource) { tx_config.resources.first }
|
21
|
+
|
22
|
+
let(:resource_slug_with_branch) do
|
23
|
+
"#{resource_slug}-#{Txgh::Utils.slugify(ref)}"
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'deletes the correct resource from transifex' do
|
27
|
+
expect(transifex_api).to(
|
28
|
+
receive(:get_resources).and_return(resource_api_response)
|
29
|
+
)
|
30
|
+
|
31
|
+
expect(transifex_api).to receive(:delete_resource) do |tx_resource|
|
32
|
+
expect(tx_resource.project_slug).to eq(project_name)
|
33
|
+
expect(tx_resource.resource_slug).to eq(resource_slug_with_branch)
|
34
|
+
end
|
35
|
+
|
36
|
+
deleter.delete_resources
|
37
|
+
end
|
38
|
+
|
39
|
+
it "does not delete resources that don't have a matching branch" do
|
40
|
+
deleter = ResourceDeleter.new(transifex_project, github_repo, 'heads/fake')
|
41
|
+
expect(transifex_api).to(
|
42
|
+
receive(:get_resources).and_return(resource_api_response)
|
43
|
+
)
|
44
|
+
|
45
|
+
expect(transifex_api).to_not receive(:delete)
|
46
|
+
deleter.delete_resources
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,8 +4,6 @@ require 'pry-byebug'
|
|
4
4
|
require 'rake'
|
5
5
|
require 'rspec'
|
6
6
|
require 'txgh'
|
7
|
-
require 'vcr'
|
8
|
-
require 'webmock'
|
9
7
|
require 'yaml'
|
10
8
|
|
11
9
|
require 'helpers/test_events'
|
@@ -24,15 +22,9 @@ end
|
|
24
22
|
RSpec.configure do |config|
|
25
23
|
config.filter_run(focus: true)
|
26
24
|
config.run_all_when_everything_filtered = true
|
27
|
-
config.filter_run_excluding(integration: true) unless ENV['FULL_SPEC']
|
28
25
|
config.include(SpecHelpers)
|
29
26
|
|
30
27
|
config.before(:each) do
|
31
28
|
Txgh.instance_variable_set(:@events, TestEvents.new)
|
32
29
|
end
|
33
30
|
end
|
34
|
-
|
35
|
-
VCR.configure do |config|
|
36
|
-
config.cassette_library_dir = 'spec/integration/cassettes'
|
37
|
-
config.hook_into :webmock
|
38
|
-
end
|
data/txgh.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.email = ['mattjjacko@gmail.com', 'camertron@gmail.com']
|
9
9
|
s.homepage = 'https://github.com/lumoslabs/txgh'
|
10
10
|
|
11
|
-
s.description = s.summary = 'A
|
11
|
+
s.description = s.summary = 'A library for syncing translation resources between Github and Transifex.'
|
12
12
|
|
13
13
|
s.platform = Gem::Platform::RUBY
|
14
14
|
s.has_rdoc = true
|
@@ -17,12 +17,8 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_dependency 'faraday', '~> 0.9'
|
18
18
|
s.add_dependency 'faraday_middleware', '~> 0.10'
|
19
19
|
s.add_dependency 'json', '~> 1.8'
|
20
|
-
s.add_dependency 'mime-types', '~> 2.0'
|
21
20
|
s.add_dependency 'octokit', '~> 4.2'
|
22
21
|
s.add_dependency 'parseconfig', '~> 1.0'
|
23
|
-
s.add_dependency 'sinatra', '~> 1.4'
|
24
|
-
s.add_dependency 'sinatra-contrib', '~> 1.4'
|
25
|
-
s.add_dependency 'rubyzip', '>= 1.0', '<= 1.1.2'
|
26
22
|
|
27
23
|
s.require_path = 'lib'
|
28
24
|
s.files = Dir['{lib,spec}/**/*', 'README.md', 'txgh.gemspec', 'LICENSE']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: txgh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Jackowski
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: abroad
|
@@ -67,20 +67,6 @@ dependencies:
|
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '1.8'
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: mime-types
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - "~>"
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '2.0'
|
77
|
-
type: :runtime
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - "~>"
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '2.0'
|
84
70
|
- !ruby/object:Gem::Dependency
|
85
71
|
name: octokit
|
86
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,56 +95,7 @@ dependencies:
|
|
109
95
|
- - "~>"
|
110
96
|
- !ruby/object:Gem::Version
|
111
97
|
version: '1.0'
|
112
|
-
|
113
|
-
name: sinatra
|
114
|
-
requirement: !ruby/object:Gem::Requirement
|
115
|
-
requirements:
|
116
|
-
- - "~>"
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version: '1.4'
|
119
|
-
type: :runtime
|
120
|
-
prerelease: false
|
121
|
-
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
requirements:
|
123
|
-
- - "~>"
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '1.4'
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: sinatra-contrib
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
129
|
-
requirements:
|
130
|
-
- - "~>"
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
version: '1.4'
|
133
|
-
type: :runtime
|
134
|
-
prerelease: false
|
135
|
-
version_requirements: !ruby/object:Gem::Requirement
|
136
|
-
requirements:
|
137
|
-
- - "~>"
|
138
|
-
- !ruby/object:Gem::Version
|
139
|
-
version: '1.4'
|
140
|
-
- !ruby/object:Gem::Dependency
|
141
|
-
name: rubyzip
|
142
|
-
requirement: !ruby/object:Gem::Requirement
|
143
|
-
requirements:
|
144
|
-
- - ">="
|
145
|
-
- !ruby/object:Gem::Version
|
146
|
-
version: '1.0'
|
147
|
-
- - "<="
|
148
|
-
- !ruby/object:Gem::Version
|
149
|
-
version: 1.1.2
|
150
|
-
type: :runtime
|
151
|
-
prerelease: false
|
152
|
-
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
requirements:
|
154
|
-
- - ">="
|
155
|
-
- !ruby/object:Gem::Version
|
156
|
-
version: '1.0'
|
157
|
-
- - "<="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: 1.1.2
|
160
|
-
description: A server that automatically syncs translation resources between Github
|
161
|
-
and Transifex.
|
98
|
+
description: A library for syncing translation resources between Github and Transifex.
|
162
99
|
email:
|
163
100
|
- mattjjacko@gmail.com
|
164
101
|
- camertron@gmail.com
|
@@ -168,9 +105,7 @@ extra_rdoc_files: []
|
|
168
105
|
files:
|
169
106
|
- LICENSE
|
170
107
|
- README.md
|
171
|
-
- lib/ext/zipline/output_stream.rb
|
172
108
|
- lib/txgh.rb
|
173
|
-
- lib/txgh/app.rb
|
174
109
|
- lib/txgh/category_support.rb
|
175
110
|
- lib/txgh/config.rb
|
176
111
|
- lib/txgh/config/config_pair.rb
|
@@ -189,45 +124,24 @@ files:
|
|
189
124
|
- lib/txgh/events.rb
|
190
125
|
- lib/txgh/github_api.rb
|
191
126
|
- lib/txgh/github_repo.rb
|
192
|
-
- lib/txgh/github_request_auth.rb
|
193
127
|
- lib/txgh/github_status.rb
|
194
|
-
- lib/txgh/handlers.rb
|
195
|
-
- lib/txgh/handlers/download_handler.rb
|
196
|
-
- lib/txgh/handlers/github.rb
|
197
|
-
- lib/txgh/handlers/github/delete_handler.rb
|
198
|
-
- lib/txgh/handlers/github/handler.rb
|
199
|
-
- lib/txgh/handlers/github/ping_handler.rb
|
200
|
-
- lib/txgh/handlers/github/push_handler.rb
|
201
|
-
- lib/txgh/handlers/github/request_handler.rb
|
202
|
-
- lib/txgh/handlers/response.rb
|
203
|
-
- lib/txgh/handlers/stream_response.rb
|
204
|
-
- lib/txgh/handlers/tgz_stream_response.rb
|
205
|
-
- lib/txgh/handlers/transifex.rb
|
206
|
-
- lib/txgh/handlers/transifex/hook_handler.rb
|
207
|
-
- lib/txgh/handlers/transifex/request_handler.rb
|
208
|
-
- lib/txgh/handlers/triggers.rb
|
209
|
-
- lib/txgh/handlers/triggers/handler.rb
|
210
|
-
- lib/txgh/handlers/triggers/pull_handler.rb
|
211
|
-
- lib/txgh/handlers/triggers/push_handler.rb
|
212
|
-
- lib/txgh/handlers/zip_stream_response.rb
|
213
128
|
- lib/txgh/merge_calculator.rb
|
214
129
|
- lib/txgh/parse_config.rb
|
215
130
|
- lib/txgh/puller.rb
|
216
131
|
- lib/txgh/pusher.rb
|
217
132
|
- lib/txgh/resource_committer.rb
|
218
133
|
- lib/txgh/resource_contents.rb
|
134
|
+
- lib/txgh/resource_deleter.rb
|
219
135
|
- lib/txgh/resource_downloader.rb
|
220
136
|
- lib/txgh/resource_updater.rb
|
221
137
|
- lib/txgh/response_helpers.rb
|
222
138
|
- lib/txgh/transifex_api.rb
|
223
139
|
- lib/txgh/transifex_project.rb
|
224
|
-
- lib/txgh/transifex_request_auth.rb
|
225
140
|
- lib/txgh/tx_branch_resource.rb
|
226
141
|
- lib/txgh/tx_logger.rb
|
227
142
|
- lib/txgh/tx_resource.rb
|
228
143
|
- lib/txgh/utils.rb
|
229
144
|
- lib/txgh/version.rb
|
230
|
-
- spec/app_spec.rb
|
231
145
|
- spec/category_support_spec.rb
|
232
146
|
- spec/config/config_pair_spec.rb
|
233
147
|
- spec/config/key_manager_spec.rb
|
@@ -239,41 +153,21 @@ files:
|
|
239
153
|
- spec/events_spec.rb
|
240
154
|
- spec/github_api_spec.rb
|
241
155
|
- spec/github_repo_spec.rb
|
242
|
-
- spec/github_request_auth_spec.rb
|
243
156
|
- spec/github_status_spec.rb
|
244
|
-
- spec/handlers/download_handler_spec.rb
|
245
|
-
- spec/handlers/github/delete_handler_spec.rb
|
246
|
-
- spec/handlers/github/ping_handler_spec.rb
|
247
|
-
- spec/handlers/github/push_handler_spec.rb
|
248
|
-
- spec/handlers/tgz_stream_response_spec.rb
|
249
|
-
- spec/handlers/transifex/hook_handler_spec.rb
|
250
|
-
- spec/handlers/zip_stream_response_spec.rb
|
251
|
-
- spec/helpers/github_payload_builder.rb
|
252
|
-
- spec/helpers/integration_setup.rb
|
253
157
|
- spec/helpers/nil_logger.rb
|
254
158
|
- spec/helpers/standard_txgh_setup.rb
|
255
159
|
- spec/helpers/test_events.rb
|
256
160
|
- spec/helpers/test_provider.rb
|
257
|
-
- spec/integration/cassettes/github_l10n_hook_endpoint.yml
|
258
|
-
- spec/integration/cassettes/pull.yml
|
259
|
-
- spec/integration/cassettes/push.yml
|
260
|
-
- spec/integration/cassettes/transifex_hook_endpoint.yml
|
261
|
-
- spec/integration/config/tx.config
|
262
|
-
- spec/integration/hooks_spec.rb
|
263
|
-
- spec/integration/payloads/github_postbody.json
|
264
|
-
- spec/integration/payloads/github_postbody_l10n.json
|
265
|
-
- spec/integration/payloads/github_postbody_release.json
|
266
|
-
- spec/integration/triggers_spec.rb
|
267
161
|
- spec/merge_calculator_spec.rb
|
268
162
|
- spec/parse_config_spec.rb
|
269
163
|
- spec/resource_committer_spec.rb
|
270
164
|
- spec/resource_contents_spec.rb
|
165
|
+
- spec/resource_deleter_spec.rb
|
271
166
|
- spec/resource_downloader_spec.rb
|
272
167
|
- spec/resource_updater_spec.rb
|
273
168
|
- spec/spec_helper.rb
|
274
169
|
- spec/transifex_api_spec.rb
|
275
170
|
- spec/transifex_project_spec.rb
|
276
|
-
- spec/transifex_request_auth_spec.rb
|
277
171
|
- spec/tx_branch_resource_spec.rb
|
278
172
|
- spec/tx_resource_spec.rb
|
279
173
|
- spec/txgh_spec.rb
|
@@ -301,6 +195,5 @@ rubyforge_project:
|
|
301
195
|
rubygems_version: 2.2.3
|
302
196
|
signing_key:
|
303
197
|
specification_version: 4
|
304
|
-
summary: A
|
305
|
-
Transifex.
|
198
|
+
summary: A library for syncing translation resources between Github and Transifex.
|
306
199
|
test_files: []
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# Taken from https://github.com/fringd/zipline
|
2
|
-
# Didn't include zipline gem b/c it depends directly on rails and brings in a
|
3
|
-
# ton of useless dependencies
|
4
|
-
|
5
|
-
require 'stringio'
|
6
|
-
require 'zip'
|
7
|
-
|
8
|
-
# a ZipOutputStream that never rewinds output
|
9
|
-
# in order for that to be possible we store only uncompressed files
|
10
|
-
module Zipline
|
11
|
-
class OutputStream < Zip::OutputStream
|
12
|
-
|
13
|
-
#we need to be able to hand out own custom output in order to stream to browser
|
14
|
-
def initialize(io)
|
15
|
-
# Create an io stream thing
|
16
|
-
super StringIO.new, true
|
17
|
-
# Overwrite it with my own
|
18
|
-
@output_stream = io
|
19
|
-
end
|
20
|
-
|
21
|
-
def stream
|
22
|
-
@output_stream
|
23
|
-
end
|
24
|
-
|
25
|
-
def put_next_entry(entry_name, size)
|
26
|
-
new_entry = Zip::Entry.new(@file_name, entry_name)
|
27
|
-
|
28
|
-
#THIS IS THE MAGIC, tells zip to look after data for size, crc
|
29
|
-
new_entry.gp_flags = new_entry.gp_flags | 0x0008
|
30
|
-
|
31
|
-
super(new_entry)
|
32
|
-
|
33
|
-
# Uncompressed size in the local file header must be zero when bit 3
|
34
|
-
# of the general purpose flags is set, so set the size after the header
|
35
|
-
# has been written.
|
36
|
-
new_entry.size = size
|
37
|
-
end
|
38
|
-
|
39
|
-
# just reset state, no rewinding required
|
40
|
-
def finalize_current_entry
|
41
|
-
if current_entry
|
42
|
-
entry = current_entry
|
43
|
-
super
|
44
|
-
write_local_footer(entry)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def write_local_footer(entry)
|
49
|
-
@output_stream << [ 0x08074b50, entry.crc, entry.compressed_size, entry.size].pack('VVVV')
|
50
|
-
end
|
51
|
-
|
52
|
-
#never need to do this because we set correct sizes up front
|
53
|
-
def update_local_headers
|
54
|
-
nil
|
55
|
-
end
|
56
|
-
|
57
|
-
# helper to deal with difference between rubyzip 1.0 and 1.1
|
58
|
-
def current_entry
|
59
|
-
@currentEntry || @current_entry
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/lib/txgh/app.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
require 'sinatra'
|
2
|
-
require 'sinatra/json'
|
3
|
-
require 'sinatra/reloader'
|
4
|
-
require 'sinatra/streaming'
|
5
|
-
|
6
|
-
module Txgh
|
7
|
-
module RespondWith
|
8
|
-
def respond_with(resp)
|
9
|
-
env['txgh.response'] = resp
|
10
|
-
|
11
|
-
if resp.streaming?
|
12
|
-
response.headers.merge!(resp.headers)
|
13
|
-
|
14
|
-
stream do |out|
|
15
|
-
begin
|
16
|
-
resp.write_to(out)
|
17
|
-
rescue => e
|
18
|
-
Txgh.events.publish_error(e)
|
19
|
-
raise e
|
20
|
-
end
|
21
|
-
end
|
22
|
-
else
|
23
|
-
status resp.status
|
24
|
-
json resp.body
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class Application < Sinatra::Base
|
30
|
-
include Txgh::Handlers
|
31
|
-
|
32
|
-
helpers Sinatra::Streaming
|
33
|
-
helpers RespondWith
|
34
|
-
|
35
|
-
configure do
|
36
|
-
set :logging, nil
|
37
|
-
logger = Txgh::TxLogger.logger
|
38
|
-
set :logger, logger
|
39
|
-
end
|
40
|
-
|
41
|
-
def initialize(app = nil)
|
42
|
-
super(app)
|
43
|
-
end
|
44
|
-
|
45
|
-
get '/health_check' do
|
46
|
-
respond_with(
|
47
|
-
Response.new(200, {})
|
48
|
-
)
|
49
|
-
end
|
50
|
-
|
51
|
-
get '/config' do
|
52
|
-
config = Txgh::Config::KeyManager.config_from_project(params[:project_slug])
|
53
|
-
branch = Utils.absolute_branch(params[:branch])
|
54
|
-
|
55
|
-
begin
|
56
|
-
tx_config = Txgh::Config::TxManager.tx_config(
|
57
|
-
config.transifex_project, config.github_repo, branch
|
58
|
-
)
|
59
|
-
|
60
|
-
data = tx_config.to_h
|
61
|
-
data.merge!(branch_slug: Utils.slugify(branch)) if branch
|
62
|
-
|
63
|
-
status 200
|
64
|
-
json data: data
|
65
|
-
rescue ConfigNotFoundError => e
|
66
|
-
status 404
|
67
|
-
json [{ error: e.message }]
|
68
|
-
rescue => e
|
69
|
-
status 500
|
70
|
-
json [{ error: e.message }]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
get '/download.:format' do
|
75
|
-
respond_with(
|
76
|
-
DownloadHandler.handle_request(request, settings.logger)
|
77
|
-
)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# Hooks are protected endpoints used for data integration between Github and
|
82
|
-
# Transifex. They live under the /hooks namespace (see config.ru)
|
83
|
-
class Hooks < Sinatra::Base
|
84
|
-
include Txgh::Handlers
|
85
|
-
|
86
|
-
helpers RespondWith
|
87
|
-
|
88
|
-
configure do
|
89
|
-
set :logging, nil
|
90
|
-
logger = Txgh::TxLogger.logger
|
91
|
-
set :logger, logger
|
92
|
-
end
|
93
|
-
|
94
|
-
configure :development do
|
95
|
-
register Sinatra::Reloader
|
96
|
-
end
|
97
|
-
|
98
|
-
def initialize(app = nil)
|
99
|
-
super(app)
|
100
|
-
end
|
101
|
-
|
102
|
-
post '/transifex' do
|
103
|
-
respond_with(
|
104
|
-
Transifex::RequestHandler.handle_request(request, settings.logger)
|
105
|
-
)
|
106
|
-
end
|
107
|
-
|
108
|
-
post '/github' do
|
109
|
-
respond_with(
|
110
|
-
Github::RequestHandler.handle_request(request, settings.logger)
|
111
|
-
)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
class Triggers < Sinatra::Base
|
116
|
-
helpers RespondWith
|
117
|
-
|
118
|
-
configure do
|
119
|
-
set :logging, nil
|
120
|
-
logger = Txgh::TxLogger.logger
|
121
|
-
set :logger, logger
|
122
|
-
end
|
123
|
-
|
124
|
-
configure :development do
|
125
|
-
register Sinatra::Reloader
|
126
|
-
end
|
127
|
-
|
128
|
-
patch '/push' do
|
129
|
-
respond_with(
|
130
|
-
Txgh::Handlers::Triggers::PushHandler.handle_request(request, settings.logger)
|
131
|
-
)
|
132
|
-
end
|
133
|
-
|
134
|
-
patch '/pull' do
|
135
|
-
respond_with(
|
136
|
-
Txgh::Handlers::Triggers::PullHandler.handle_request(request, settings.logger)
|
137
|
-
)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'openssl'
|
2
|
-
|
3
|
-
module Txgh
|
4
|
-
class GithubRequestAuth
|
5
|
-
HMAC_DIGEST = OpenSSL::Digest.new('sha1')
|
6
|
-
RACK_HEADER = 'HTTP_X_HUB_SIGNATURE'
|
7
|
-
GITHUB_HEADER = 'X-Hub-Signature'
|
8
|
-
|
9
|
-
class << self
|
10
|
-
def authentic_request?(request, secret)
|
11
|
-
request.body.rewind
|
12
|
-
expected_signature = header_value(request.body.read, secret)
|
13
|
-
actual_signature = request.env[RACK_HEADER]
|
14
|
-
actual_signature == expected_signature
|
15
|
-
end
|
16
|
-
|
17
|
-
def header_value(content, secret)
|
18
|
-
"sha1=#{digest(content, secret)}"
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def digest(content, secret)
|
24
|
-
OpenSSL::HMAC.hexdigest(HMAC_DIGEST, secret, content)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|