txgh 2.0.1 → 2.1.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/events.rb +35 -0
- data/lib/txgh/github_api.rb +4 -0
- data/lib/txgh/github_status.rb +87 -0
- data/lib/txgh/resource_committer.rb +13 -0
- data/lib/txgh/resource_updater.rb +10 -0
- data/lib/txgh/transifex_api.rb +7 -1
- data/lib/txgh/version.rb +1 -1
- data/lib/txgh.rb +22 -0
- data/spec/events_spec.rb +45 -0
- data/spec/github_status_spec.rb +68 -0
- data/spec/handlers/transifex/hook_handler_spec.rb +4 -0
- data/spec/helpers/standard_txgh_setup.rb +3 -1
- data/spec/helpers/test_events.rb +12 -0
- data/spec/integration/cassettes/transifex_hook_endpoint.yml +210 -137
- data/spec/resource_committer_spec.rb +34 -8
- data/spec/resource_updater_spec.rb +17 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/transifex_api_spec.rb +16 -1
- metadata +7 -2
@@ -14,18 +14,44 @@ describe ResourceCommitter do
|
|
14
14
|
ResourceCommitter.new(transifex_project, github_repo, logger)
|
15
15
|
end
|
16
16
|
|
17
|
+
before(:each) do
|
18
|
+
allow(github_api).to receive(:get_ref).and_return(
|
19
|
+
object: { sha: 'abc123shashasha' }
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
17
23
|
describe '#commit_resource' do
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
context 'with apis available' do
|
25
|
+
before(:each) do
|
26
|
+
expect(ResourceDownloader).to receive(:new).and_return(downloader)
|
27
|
+
expect(downloader).to receive(:first).and_return([file_name, :translations])
|
28
|
+
|
29
|
+
expect(github_api).to(
|
30
|
+
receive(:commit).with(
|
31
|
+
repo_name, branch, { file_name => :translations }
|
32
|
+
)
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'commits translations to the git repo' do
|
37
|
+
committer.commit_resource(resource, branch, language)
|
38
|
+
end
|
21
39
|
|
22
|
-
|
23
|
-
|
24
|
-
|
40
|
+
it 'fires the github.resource.committed event' do
|
41
|
+
expect { committer.commit_resource(resource, branch, language) }.to(
|
42
|
+
change { Txgh.events.published.size }.by(1)
|
25
43
|
)
|
26
|
-
)
|
27
44
|
|
28
|
-
|
45
|
+
event = Txgh.events.published.first
|
46
|
+
expect(event[:channel]).to eq('github.resource.committed')
|
47
|
+
|
48
|
+
options = event[:options]
|
49
|
+
expect(options[:project].name).to eq(project_name)
|
50
|
+
expect(options[:repo].name).to eq(repo_name)
|
51
|
+
expect(options[:sha]).to eq('abc123shashasha')
|
52
|
+
expect(options[:resource].original_resource_slug).to eq(resource_slug)
|
53
|
+
expect(options[:language]).to eq(language)
|
54
|
+
end
|
29
55
|
end
|
30
56
|
|
31
57
|
it "doesn't commit anything if the language is the source language" do
|
@@ -65,6 +65,23 @@ describe ResourceUpdater do
|
|
65
65
|
updater.update_resource(resource, commit_sha)
|
66
66
|
end
|
67
67
|
|
68
|
+
it 'fires the transifex.resource.updated event' do
|
69
|
+
allow(transifex_api).to receive(:create_or_update)
|
70
|
+
|
71
|
+
expect { updater.update_resource(resource, commit_sha) }.to(
|
72
|
+
change { Txgh.events.published.size }.by(1)
|
73
|
+
)
|
74
|
+
|
75
|
+
event = Txgh.events.published.first
|
76
|
+
expect(event[:channel]).to eq('transifex.resource.updated')
|
77
|
+
|
78
|
+
options = event[:options]
|
79
|
+
expect(options[:project].name).to eq(project_name)
|
80
|
+
expect(options[:repo].name).to eq(repo_name)
|
81
|
+
expect(options[:sha]).to eq(commit_sha)
|
82
|
+
expect(options[:resource].original_resource_slug).to eq(resource_slug)
|
83
|
+
end
|
84
|
+
|
68
85
|
context 'when asked to process all branches' do
|
69
86
|
let(:branch) { 'all' }
|
70
87
|
let(:ref) { 'heads/master' }
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,8 @@ require 'vcr'
|
|
8
8
|
require 'webmock'
|
9
9
|
require 'yaml'
|
10
10
|
|
11
|
+
require 'helpers/test_events'
|
12
|
+
|
11
13
|
module SpecHelpers
|
12
14
|
def outdent(str)
|
13
15
|
# The special YAML pipe operator treats the text that follows as literal,
|
@@ -24,6 +26,10 @@ RSpec.configure do |config|
|
|
24
26
|
config.run_all_when_everything_filtered = true
|
25
27
|
config.filter_run_excluding(integration: true) unless ENV['FULL_SPEC']
|
26
28
|
config.include(SpecHelpers)
|
29
|
+
|
30
|
+
config.before(:each) do
|
31
|
+
Txgh.instance_variable_set(:@events, TestEvents.new)
|
32
|
+
end
|
27
33
|
end
|
28
34
|
|
29
35
|
VCR.configure do |config|
|
data/spec/transifex_api_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe TransifexApi do
|
|
8
8
|
|
9
9
|
let(:connection) { double(:connection) }
|
10
10
|
let(:api) { TransifexApi.create_from_connection(connection) }
|
11
|
-
let(:resource) { tx_config.
|
11
|
+
let(:resource) { tx_config.resource(resource_slug) }
|
12
12
|
let(:response) { double(:response) }
|
13
13
|
|
14
14
|
describe '#create_or_update' do
|
@@ -77,6 +77,7 @@ describe TransifexApi do
|
|
77
77
|
end_with("project/#{project_name}/resources/")
|
78
78
|
)
|
79
79
|
|
80
|
+
expect(payload[:name]).to eq('sample.yml')
|
80
81
|
expect(payload[:content].io.string).to eq('new_content')
|
81
82
|
expect(payload[:categories]).to eq('abc def')
|
82
83
|
response
|
@@ -102,6 +103,20 @@ describe TransifexApi do
|
|
102
103
|
allow(response).to receive(:body).and_return('{}')
|
103
104
|
expect { api.create(resource, 'new_content') }.to raise_error(TransifexApiError)
|
104
105
|
end
|
106
|
+
|
107
|
+
context 'with a branch-based resource' do
|
108
|
+
let(:resource) { tx_config.resource(resource_slug, ref) }
|
109
|
+
|
110
|
+
it "includes the branch in the resource's name" do
|
111
|
+
expect(connection).to receive(:post) do |url, payload|
|
112
|
+
expect(payload[:name]).to eq('sample.yml (heads/master)')
|
113
|
+
response
|
114
|
+
end
|
115
|
+
|
116
|
+
allow(response).to receive(:status).and_return(200)
|
117
|
+
api.create(resource, 'new_content')
|
118
|
+
end
|
119
|
+
end
|
105
120
|
end
|
106
121
|
|
107
122
|
describe '#delete' do
|
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: 2.0
|
4
|
+
version: 2.1.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-04
|
12
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: abroad
|
@@ -186,9 +186,11 @@ files:
|
|
186
186
|
- lib/txgh/diff_calculator.rb
|
187
187
|
- lib/txgh/empty_resource_contents.rb
|
188
188
|
- lib/txgh/errors.rb
|
189
|
+
- lib/txgh/events.rb
|
189
190
|
- lib/txgh/github_api.rb
|
190
191
|
- lib/txgh/github_repo.rb
|
191
192
|
- lib/txgh/github_request_auth.rb
|
193
|
+
- lib/txgh/github_status.rb
|
192
194
|
- lib/txgh/handlers.rb
|
193
195
|
- lib/txgh/handlers/download_handler.rb
|
194
196
|
- lib/txgh/handlers/github.rb
|
@@ -232,9 +234,11 @@ files:
|
|
232
234
|
- spec/config/tx_config_spec.rb
|
233
235
|
- spec/config/tx_manager_spec.rb
|
234
236
|
- spec/diff_calculator_spec.rb
|
237
|
+
- spec/events_spec.rb
|
235
238
|
- spec/github_api_spec.rb
|
236
239
|
- spec/github_repo_spec.rb
|
237
240
|
- spec/github_request_auth_spec.rb
|
241
|
+
- spec/github_status_spec.rb
|
238
242
|
- spec/handlers/download_handler_spec.rb
|
239
243
|
- spec/handlers/github/delete_handler_spec.rb
|
240
244
|
- spec/handlers/github/ping_handler_spec.rb
|
@@ -246,6 +250,7 @@ files:
|
|
246
250
|
- spec/helpers/integration_setup.rb
|
247
251
|
- spec/helpers/nil_logger.rb
|
248
252
|
- spec/helpers/standard_txgh_setup.rb
|
253
|
+
- spec/helpers/test_events.rb
|
249
254
|
- spec/helpers/test_provider.rb
|
250
255
|
- spec/integration/cassettes/github_l10n_hook_endpoint.yml
|
251
256
|
- spec/integration/cassettes/pull.yml
|