txgh 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe316847be46da3963313952b4861525ddf6b43f
4
- data.tar.gz: 89c7ac7f13c1d2e165cdaae3f6b110cf499888d3
3
+ metadata.gz: 083d15ac3686b54241f76f3cf7da05783ed9b189
4
+ data.tar.gz: 42bbf8c31844b25f9c05a74701a6625980d3e7ea
5
5
  SHA512:
6
- metadata.gz: 6793b41001e8e2fb32c808f179d5de0b8a5f4fe0eb4736fc8998657204d6e0c760e5937f0bfb066eb216852efca0e6ab83c3bffdd48c576338719c3f61384094
7
- data.tar.gz: c1ece2694a02648b5553d7bc226b1180f6d492678b4fbc015a8c507114dbc3805f3b5e98ac3de674287676f4351f35e43a60ce07a9c5b73007faad932d869416
6
+ metadata.gz: 4117c59c816d16878946db1cc5451dfd822c7386c8347d11b952c8e68c620cf88d98ed5360f04752c781621dece4bcb9507debef086a682f38cb31baca14c391
7
+ data.tar.gz: d24d9cad4af2d0d8ee8bdf3f8a93f681650e535184d1f25a8d0e29818f7de86cc41751ab9927243de2ab04dd0406a14abc514e691c4059aab116c710690ebc5e
@@ -54,7 +54,10 @@ module Txgh
54
54
  end
55
55
 
56
56
  def execute
57
- downloader = ResourceDownloader.new(project, repo, params['branch'])
57
+ downloader = ResourceDownloader.new(
58
+ project, repo, params['branch'], languages: project.languages
59
+ )
60
+
58
61
  response_class.new(attachment, downloader.each)
59
62
  end
60
63
 
@@ -20,25 +20,38 @@ module Txgh
20
20
  def execute
21
21
  logger.info(resource_slug)
22
22
 
23
- if tx_config
24
- if tx_resource
25
- committer = ResourceCommitter.new(project, repo, logger)
26
- committer.commit_resource(tx_resource, branch, language)
23
+ check_error_response || begin
24
+ committer = ResourceCommitter.new(project, repo, logger)
25
+ committer.commit_resource(tx_resource, branch, language)
26
+ respond_with(200, true)
27
+ end
28
+ end
27
29
 
28
- respond_with(200, true)
29
- else
30
- respond_with_error(
31
- 404, "Could not find resource '#{resource_slug}' in config"
32
- )
33
- end
34
- else
30
+ private
31
+
32
+ def check_error_response
33
+ check_supported_language || check_tx_config || check_tx_resource
34
+ end
35
+
36
+ def check_supported_language
37
+ respond_with(304, true) unless supported_language?
38
+ end
39
+
40
+ def check_tx_config
41
+ unless tx_config
35
42
  respond_with_error(
36
43
  404, "Could not find configuration for branch '#{branch}'"
37
44
  )
38
45
  end
39
46
  end
40
47
 
41
- private
48
+ def check_tx_resource
49
+ unless tx_resource
50
+ respond_with_error(
51
+ 404, "Could not find resource '#{resource_slug}' in config"
52
+ )
53
+ end
54
+ end
42
55
 
43
56
  def tx_config
44
57
  @tx_config ||= Txgh::Config::TxManager.tx_config(project, repo, branch)
@@ -71,6 +84,10 @@ module Txgh
71
84
  def process_all_branches?
72
85
  repo.process_all_branches?
73
86
  end
87
+
88
+ def supported_language?
89
+ project.supported_language?(language)
90
+ end
74
91
  end
75
92
  end
76
93
  end
@@ -5,6 +5,8 @@ module Txgh
5
5
 
6
6
  def execute
7
7
  languages.each do |language|
8
+ next unless project.supported_language?(language['language_code'])
9
+
8
10
  committer.commit_resource(
9
11
  branch_resource, branch, language['language_code']
10
12
  )
@@ -33,5 +33,13 @@ module Txgh
33
33
  def tx_config_uri
34
34
  config['tx_config']
35
35
  end
36
+
37
+ def languages
38
+ config.fetch('languages', [])
39
+ end
40
+
41
+ def supported_language?(language)
42
+ languages.include?(language)
43
+ end
36
44
  end
37
45
  end
data/lib/txgh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Txgh
2
- VERSION = '1.1.0'
2
+ VERSION = '2.0.0'
3
3
  end
data/spec/app_spec.rb CHANGED
@@ -310,6 +310,7 @@ describe Txgh::Triggers do
310
310
  it 'updates translations (in all locales) in the expected repo' do
311
311
  committer = double(:committer)
312
312
  languages = [{ 'language_code' => 'pt' }, { 'language_code' => 'ja' }]
313
+ project_config['languages'] = %w(pt ja)
313
314
  expect(Txgh::ResourceCommitter).to receive(:new).and_return(committer)
314
315
  expect(Txgh::TransifexApi).to receive(:new).and_return(transifex_api)
315
316
  expect(transifex_api).to receive(:get_languages).and_return(languages)
@@ -77,5 +77,15 @@ describe DownloadHandler do
77
77
  expect(handler.execute).to be_a(TgzStreamResponse)
78
78
  end
79
79
  end
80
+
81
+ context 'with a set of languages' do
82
+ let(:supported_languages) { %w(is fr) }
83
+
84
+ it "downloads translations for the project's supported languages" do
85
+ allow(transifex_api).to receive(:download)
86
+ files = handler.execute.enum.to_a.map(&:first)
87
+ expect(files).to eq(%w(translations/is/sample.yml translations/fr/sample.yml))
88
+ end
89
+ end
80
90
  end
81
91
  end
@@ -112,4 +112,17 @@ describe HookHandler do
112
112
  expect(response.body).to eq(true)
113
113
  end
114
114
  end
115
+
116
+ context 'with an unsupported language' do
117
+ let(:language) { 'pt' }
118
+ let(:supported_languages) { ['ja'] }
119
+
120
+ it "doesn't make a commit" do
121
+ expect(github_api).to_not receive(:commit)
122
+
123
+ response = handler.execute
124
+ expect(response.status).to eq(304)
125
+ expect(response.body).to eq(true)
126
+ end
127
+ end
115
128
  end
@@ -15,6 +15,7 @@ module StandardTxghSetup
15
15
  let(:tag) { 'all' }
16
16
  let(:ref) { 'heads/master' }
17
17
  let(:language) { 'ko_KR' }
18
+ let(:supported_languages) { [language] }
18
19
  let(:translations) { 'translation file contents' }
19
20
  let(:diff_point) { nil }
20
21
 
@@ -26,7 +27,8 @@ module StandardTxghSetup
26
27
  'name' => project_name,
27
28
  'tx_config' => "raw://#{tx_config_raw}",
28
29
  'webhook_secret' => 'abc123',
29
- 'auto_delete_resources' => 'true'
30
+ 'auto_delete_resources' => 'true',
31
+ 'languages' => supported_languages
30
32
  }
31
33
  end
32
34
 
@@ -45,7 +45,8 @@ describe 'hook integration tests', integration: true do
45
45
  'api_username' => 'txgh.bot',
46
46
  'api_password' => '2aqFGW99fPRKWvXBPjbrxkdiR',
47
47
  'push_translations_to' => 'txgh-bot/txgh-test-resources',
48
- 'webhook_secret' => 'fce95b1748fd638c22174d34200f10cf'
48
+ 'webhook_secret' => 'fce95b1748fd638c22174d34200f10cf',
49
+ 'languages' => ['el_GR']
49
50
  }
50
51
  }
51
52
  }
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: 1.1.0
4
+ version: 2.0.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-20 00:00:00.000000000 Z
12
+ date: 2016-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: abroad