phraseapp_updater 2.0.10 → 2.1.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
  SHA256:
3
- metadata.gz: 6e77fc445857a954b363ba696c6b0696121ed33fa5b4b59eddc92306f94bfa10
4
- data.tar.gz: 2433ddde7e837634c2e24f1597f8b9a5b7b1c169c84c7b72bb37fe5d76512774
3
+ metadata.gz: d37e141557fd9cc010451768633fad76cdcf752e73fa36264128cfc7131a90e4
4
+ data.tar.gz: 0b153e2ef2467716126121bb3a489123797769ac10e64bf39490c6ba1d7957d5
5
5
  SHA512:
6
- metadata.gz: 7625186b9ea217a918de59e58d686592ed117811a9ba7a380a84c635e2f9e07e3f8a2642e9f6de5c08ed3243aa9a7b698bc6f911fbf2cd62ff17c4fbd4cf50ec
7
- data.tar.gz: 87e307dd1f92b2715bd9c222927ff9a159b7c89f06399b4fa517e73e58c8753030d03ebd1604f9b7a5afa6b92620e737fbdc2c0bd6c5b5fe63474bfccc8ff028
6
+ metadata.gz: 616889fb72e2e7a0a02f1bb40c44f86d686d9832541bd1711c2d44631d3fd4dcc9fbd97967ec1995227f8213f6e67da3443320ffeb54ba5bad1d157a25ae303c
7
+ data.tar.gz: 450c888b0c7e88b6bfb6356ac1d8bf0daf73abd9444f20705a1516307b44e3a603bfc0632035fcc96cb476e1fc42f30664fc6f48b1a4521e287e6277717f07fa
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ eval "$(lorri direnv)"
data/Gemfile CHANGED
@@ -4,3 +4,5 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
  gem 'byebug'
6
6
  gem 'rspec_junit_formatter'
7
+
8
+ gem 'irb', require: false
@@ -32,6 +32,20 @@ class PhraseAppUpdaterCLI < Thor
32
32
  end
33
33
  end
34
34
 
35
+ desc 'lookup', 'Lookup a phraseapp project by name'
36
+ method_option :phraseapp_api_key, type: :string, required: true, desc: 'PhraseApp API key.'
37
+ method_option :phraseapp_project_name, type: :string, required: true, desc: 'Name for new PhraseApp project.'
38
+
39
+ def lookup
40
+ handle_errors do
41
+ project_id = PhraseAppUpdater.lookup_project(
42
+ options[:phraseapp_api_key],
43
+ options[:phraseapp_project_name])
44
+
45
+ puts project_id
46
+ end
47
+ end
48
+
35
49
  desc 'synchronize <git_checkout_path>',
36
50
  'Synchronize locales in PhraseApp with '
37
51
  method_option :phraseapp_api_key, type: :string, required: true, desc: 'PhraseApp API key.'
@@ -237,6 +251,9 @@ class PhraseAppUpdaterCLI < Thor
237
251
  rescue PhraseAppUpdater::PhraseAppAPI::BadAPIKeyError
238
252
  STDERR.puts 'Bad PhraseApp API key.'
239
253
  exit(1)
254
+ rescue PhraseAppUpdater::PhraseAppAPI::ProjectNotFoundError => e
255
+ STDERR.puts "PhraseApp project not found: '#{e.name}'"
256
+ exit(1)
240
257
  rescue PhraseAppUpdater::PhraseAppAPI::BadProjectIDError => e
241
258
  STDERR.puts "Bad PhraseApp project ID: #{e.project_id}"
242
259
  exit(1)
@@ -10,6 +10,7 @@ class PhraseAppUpdater
10
10
  using IndexBy
11
11
  class PhraseAppAPI
12
12
  GIT_TAG_PREFIX = 'gitancestor_'
13
+ PAGE_SIZE = 100
13
14
 
14
15
  def initialize(api_key, project_id, locale_file_class)
15
16
  @client = PhraseApp::Client.new(PhraseApp::Auth::Credentials.new(token: api_key))
@@ -30,11 +31,19 @@ class PhraseAppUpdater
30
31
  project.id
31
32
  end
32
33
 
34
+ def lookup_project_id(name)
35
+ result, = paginate_request(:projects_list, limit: 1) { |p| p.name == name }
36
+ raise ProjectNotFoundError.new(name) if result.nil?
37
+
38
+ result.id
39
+ end
40
+
33
41
  # We mark projects with their parent git commit using a tag with a
34
42
  # well-known prefix. We only allow one tag with this prefix at once.
35
43
  def read_parent_commit
36
- tags = phraseapp_request { @client.tags_list(@project_id, 1, 100) }
37
- git_tag = tags.detect { |t| t.name.start_with?(GIT_TAG_PREFIX) }
44
+ git_tag, = paginate_request(:tags_list, @project_id, limit: 1) do |t|
45
+ t.name.start_with?(GIT_TAG_PREFIX)
46
+ end
38
47
  raise MissingGitParentError.new if git_tag.nil?
39
48
 
40
49
  git_tag.name.delete_prefix(GIT_TAG_PREFIX)
@@ -146,6 +155,32 @@ class PhraseAppUpdater
146
155
  phraseapp_request { @client.tag_create(@project_id, params) }
147
156
  end
148
157
 
158
+ def paginate_request(method, *params, limit: nil, &filter)
159
+ page = 1
160
+ results = []
161
+
162
+ loop do
163
+ response = phraseapp_request do
164
+ @client.public_send(method, *params, page, PAGE_SIZE)
165
+ end
166
+
167
+ break if response.empty?
168
+
169
+ matches = response.filter(&filter)
170
+ matches = matches[0, limit - results.size] if limit
171
+
172
+ unless matches.empty?
173
+ results.concat(matches)
174
+
175
+ break if results.size == limit
176
+ end
177
+
178
+ page += 1
179
+ end
180
+
181
+ results
182
+ end
183
+
149
184
  def phraseapp_request(&block)
150
185
  res, err = block.call
151
186
 
@@ -219,6 +254,15 @@ class PhraseAppUpdater
219
254
  end
220
255
  end
221
256
 
257
+ class ProjectNotFoundError < RuntimeError
258
+ attr_reader :name
259
+
260
+ def initialize(name)
261
+ @name = name
262
+ super("Project '#{name}' not found")
263
+ end
264
+ end
265
+
222
266
  class BadAPIKeyError < RuntimeError
223
267
  def initialize(original_error)
224
268
  super(original_error.message)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class PhraseAppUpdater
4
- VERSION = '2.0.10'
4
+ VERSION = '2.1.0'
5
5
  end
@@ -16,6 +16,11 @@ class PhraseAppUpdater
16
16
  return self.new(phraseapp_api_key, project_id, file_format, verbose: verbose), project_id
17
17
  end
18
18
 
19
+ def self.lookup_project(phraseapp_api_key, phraseapp_project_name)
20
+ api = PhraseAppAPI.new(phraseapp_api_key, nil, nil)
21
+ api.lookup_project_id(phraseapp_project_name)
22
+ end
23
+
19
24
  def initialize(phraseapp_api_key, phraseapp_project_id, file_format, default_locale: 'en', verbose: false)
20
25
  @locale_file_class = LocaleFile.class_for_file_format(file_format)
21
26
  @default_locale = default_locale
data/nix/gem/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source "https://rubygems.org/"
2
+
3
+ gem "byebug", "11.0.1"
4
+ gem "coderay", "1.1.2"
5
+ gem "deep_merge", "1.2.1"
6
+ gem "diff-lcs", "1.3"
7
+ gem "hashdiff", "0.4.0"
8
+ gem "io-console", "0.5.4"
9
+ gem "irb", "1.2.1"
10
+ gem "method_source", "0.9.2"
11
+ gem "multi_json", "1.14.1"
12
+ gem "oj", "2.18.5"
13
+ gem "parallel", "1.19.1"
14
+ gem "phraseapp-ruby", "1.6.0"
15
+ gem "pry", "0.12.2"
16
+ gem "rake", "10.5.0"
17
+ gem "reline", "0.1.2"
18
+ gem "rspec", "3.8.0"
19
+ gem "rspec-core", "3.8.0"
20
+ gem "rspec-expectations", "3.8.3"
21
+ gem "rspec-mocks", "3.8.0"
22
+ gem "rspec-support", "3.8.0"
23
+ gem "rspec_junit_formatter", "0.4.1"
24
+ gem "thor", "0.20.3"
@@ -0,0 +1,68 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ byebug (11.0.1)
5
+ coderay (1.1.2)
6
+ deep_merge (1.2.1)
7
+ diff-lcs (1.3)
8
+ hashdiff (0.4.0)
9
+ io-console (0.5.4)
10
+ irb (1.2.1)
11
+ reline (>= 0.0.1)
12
+ method_source (0.9.2)
13
+ multi_json (1.14.1)
14
+ oj (2.18.5)
15
+ parallel (1.19.1)
16
+ phraseapp-ruby (1.6.0)
17
+ pry (0.12.2)
18
+ coderay (~> 1.1.0)
19
+ method_source (~> 0.9.0)
20
+ rake (10.5.0)
21
+ reline (0.1.2)
22
+ io-console (~> 0.5)
23
+ rspec (3.8.0)
24
+ rspec-core (~> 3.8.0)
25
+ rspec-expectations (~> 3.8.0)
26
+ rspec-mocks (~> 3.8.0)
27
+ rspec-core (3.8.0)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-expectations (3.8.3)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-mocks (3.8.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-support (3.8.0)
36
+ rspec_junit_formatter (0.4.1)
37
+ rspec-core (>= 2, < 4, != 2.12.0)
38
+ thor (0.20.3)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ byebug (= 11.0.1)
45
+ coderay (= 1.1.2)
46
+ deep_merge (= 1.2.1)
47
+ diff-lcs (= 1.3)
48
+ hashdiff (= 0.4.0)
49
+ io-console (= 0.5.4)
50
+ irb (= 1.2.1)
51
+ method_source (= 0.9.2)
52
+ multi_json (= 1.14.1)
53
+ oj (= 2.18.5)
54
+ parallel (= 1.19.1)
55
+ phraseapp-ruby (= 1.6.0)
56
+ pry (= 0.12.2)
57
+ rake (= 10.5.0)
58
+ reline (= 0.1.2)
59
+ rspec (= 3.8.0)
60
+ rspec-core (= 3.8.0)
61
+ rspec-expectations (= 3.8.3)
62
+ rspec-mocks (= 3.8.0)
63
+ rspec-support (= 3.8.0)
64
+ rspec_junit_formatter (= 0.4.1)
65
+ thor (= 0.20.3)
66
+
67
+ BUNDLED WITH
68
+ 1.17.3
@@ -0,0 +1,230 @@
1
+ {
2
+ byebug = {
3
+ groups = ["default"];
4
+ platforms = [];
5
+ source = {
6
+ remotes = ["https://rubygems.org"];
7
+ sha256 = "1mmkls9n56l4gx2k0dnyianwz36z2zgpxli5bpsbr7jbw7hn2x6j";
8
+ type = "gem";
9
+ };
10
+ version = "11.0.1";
11
+ };
12
+ coderay = {
13
+ groups = ["default"];
14
+ platforms = [];
15
+ source = {
16
+ remotes = ["https://rubygems.org"];
17
+ sha256 = "15vav4bhcc2x3jmi3izb11l4d9f3xv8hp2fszb7iqmpsccv1pz4y";
18
+ type = "gem";
19
+ };
20
+ version = "1.1.2";
21
+ };
22
+ deep_merge = {
23
+ groups = ["default"];
24
+ platforms = [];
25
+ source = {
26
+ remotes = ["https://rubygems.org"];
27
+ sha256 = "1q3picw7zx1xdkybmrnhmk2hycxzaa0jv4gqrby1s90dy5n7fmsb";
28
+ type = "gem";
29
+ };
30
+ version = "1.2.1";
31
+ };
32
+ diff-lcs = {
33
+ groups = ["default"];
34
+ platforms = [];
35
+ source = {
36
+ remotes = ["https://rubygems.org"];
37
+ sha256 = "18w22bjz424gzafv6nzv98h0aqkwz3d9xhm7cbr1wfbyas8zayza";
38
+ type = "gem";
39
+ };
40
+ version = "1.3";
41
+ };
42
+ hashdiff = {
43
+ groups = ["default"];
44
+ platforms = [];
45
+ source = {
46
+ remotes = ["https://rubygems.org"];
47
+ sha256 = "1ncwxv7jbm3jj9phv6dd514463bkjwggxk10n2z100wf4cjcicrk";
48
+ type = "gem";
49
+ };
50
+ version = "0.4.0";
51
+ };
52
+ io-console = {
53
+ groups = ["default"];
54
+ platforms = [];
55
+ source = {
56
+ remotes = ["https://rubygems.org"];
57
+ sha256 = "109yzpv9kslwra2mxnjsg3r6mwxkbqmxihj266qdvccapghi05wg";
58
+ type = "gem";
59
+ };
60
+ version = "0.5.4";
61
+ };
62
+ irb = {
63
+ dependencies = ["reline"];
64
+ groups = ["default"];
65
+ platforms = [];
66
+ source = {
67
+ remotes = ["https://rubygems.org"];
68
+ sha256 = "1r1y8i46qd5izdszzzn5jxvwvq00m89rk0hm8cs8f21p7nlwmh5w";
69
+ type = "gem";
70
+ };
71
+ version = "1.2.1";
72
+ };
73
+ method_source = {
74
+ groups = ["default"];
75
+ platforms = [];
76
+ source = {
77
+ remotes = ["https://rubygems.org"];
78
+ sha256 = "1pviwzvdqd90gn6y7illcdd9adapw8fczml933p5vl739dkvl3lq";
79
+ type = "gem";
80
+ };
81
+ version = "0.9.2";
82
+ };
83
+ multi_json = {
84
+ groups = ["default"];
85
+ platforms = [];
86
+ source = {
87
+ remotes = ["https://rubygems.org"];
88
+ sha256 = "0xy54mjf7xg41l8qrg1bqri75agdqmxap9z466fjismc1rn2jwfr";
89
+ type = "gem";
90
+ };
91
+ version = "1.14.1";
92
+ };
93
+ oj = {
94
+ groups = ["default"];
95
+ platforms = [];
96
+ source = {
97
+ remotes = ["https://rubygems.org"];
98
+ sha256 = "1jli4mi1xpmm8564pc09bfvv7znzqghidwa3zfw21r365ihmbv2p";
99
+ type = "gem";
100
+ };
101
+ version = "2.18.5";
102
+ };
103
+ parallel = {
104
+ groups = ["default"];
105
+ platforms = [];
106
+ source = {
107
+ remotes = ["https://rubygems.org"];
108
+ sha256 = "12jijkap4akzdv11lm08dglsc8jmc87xcgq6947i1s3qb69f4zn2";
109
+ type = "gem";
110
+ };
111
+ version = "1.19.1";
112
+ };
113
+ phraseapp-ruby = {
114
+ groups = ["default"];
115
+ platforms = [];
116
+ source = {
117
+ remotes = ["https://rubygems.org"];
118
+ sha256 = "14n2hhwjn32xk0qk6rprs3awnrddhnd4zckyd0a4j8lv8k648pnn";
119
+ type = "gem";
120
+ };
121
+ version = "1.6.0";
122
+ };
123
+ pry = {
124
+ dependencies = ["coderay" "method_source"];
125
+ groups = ["default"];
126
+ platforms = [];
127
+ source = {
128
+ remotes = ["https://rubygems.org"];
129
+ sha256 = "00rm71x0r1jdycwbs83lf9l6p494m99asakbvqxh8rz7zwnlzg69";
130
+ type = "gem";
131
+ };
132
+ version = "0.12.2";
133
+ };
134
+ rake = {
135
+ groups = ["default"];
136
+ platforms = [];
137
+ source = {
138
+ remotes = ["https://rubygems.org"];
139
+ sha256 = "0jcabbgnjc788chx31sihc5pgbqnlc1c75wakmqlbjdm8jns2m9b";
140
+ type = "gem";
141
+ };
142
+ version = "10.5.0";
143
+ };
144
+ reline = {
145
+ dependencies = ["io-console"];
146
+ groups = ["default"];
147
+ platforms = [];
148
+ source = {
149
+ remotes = ["https://rubygems.org"];
150
+ sha256 = "0908ijrngc3wkn5iny7d0kxkp74w6ixk2nwzzngplplfla1vkp8x";
151
+ type = "gem";
152
+ };
153
+ version = "0.1.2";
154
+ };
155
+ rspec = {
156
+ dependencies = ["rspec-core" "rspec-expectations" "rspec-mocks"];
157
+ groups = ["default"];
158
+ platforms = [];
159
+ source = {
160
+ remotes = ["https://rubygems.org"];
161
+ sha256 = "15ppasvb9qrscwlyjz67ppw1lnxiqnkzx5vkx1bd8x5n3dhikxc3";
162
+ type = "gem";
163
+ };
164
+ version = "3.8.0";
165
+ };
166
+ rspec-core = {
167
+ dependencies = ["rspec-support"];
168
+ groups = ["default"];
169
+ platforms = [];
170
+ source = {
171
+ remotes = ["https://rubygems.org"];
172
+ sha256 = "1p1s5bnbqp3sxk67y0fh0x884jjym527r0vgmhbm81w7aq6b7l4p";
173
+ type = "gem";
174
+ };
175
+ version = "3.8.0";
176
+ };
177
+ rspec-expectations = {
178
+ dependencies = ["diff-lcs" "rspec-support"];
179
+ groups = ["default"];
180
+ platforms = [];
181
+ source = {
182
+ remotes = ["https://rubygems.org"];
183
+ sha256 = "1c4gs5ybf7km0qshdm92p38zvg32n1j2kr5fgs2icacz7xf2y6fy";
184
+ type = "gem";
185
+ };
186
+ version = "3.8.3";
187
+ };
188
+ rspec-mocks = {
189
+ dependencies = ["diff-lcs" "rspec-support"];
190
+ groups = ["default"];
191
+ platforms = [];
192
+ source = {
193
+ remotes = ["https://rubygems.org"];
194
+ sha256 = "06y508cjqycb4yfhxmb3nxn0v9xqf17qbd46l1dh4xhncinr4fyp";
195
+ type = "gem";
196
+ };
197
+ version = "3.8.0";
198
+ };
199
+ rspec-support = {
200
+ groups = ["default"];
201
+ platforms = [];
202
+ source = {
203
+ remotes = ["https://rubygems.org"];
204
+ sha256 = "0p3m7drixrlhvj2zpc38b11x145bvm311x6f33jjcxmvcm0wq609";
205
+ type = "gem";
206
+ };
207
+ version = "3.8.0";
208
+ };
209
+ rspec_junit_formatter = {
210
+ dependencies = ["rspec-core"];
211
+ groups = ["default"];
212
+ platforms = [];
213
+ source = {
214
+ remotes = ["https://rubygems.org"];
215
+ sha256 = "1aynmrgnv26pkprrajvp7advb8nbh0x4pkwk6jwq8qmwzarzk21p";
216
+ type = "gem";
217
+ };
218
+ version = "0.4.1";
219
+ };
220
+ thor = {
221
+ groups = ["default"];
222
+ platforms = [];
223
+ source = {
224
+ remotes = ["https://rubygems.org"];
225
+ sha256 = "1yhrnp9x8qcy5vc7g438amd5j9sw83ih7c30dr6g6slgw9zj3g29";
226
+ type = "gem";
227
+ };
228
+ version = "0.20.3";
229
+ };
230
+ }
data/nix/generate.rb ADDED
@@ -0,0 +1,41 @@
1
+ #! /usr/bin/env nix-shell
2
+ #! nix-shell -i ruby -p ruby -p bundler -p bundix
3
+ # frozen_string_literal: true
4
+
5
+ # Bundix doesn't support `gemspec` directive in Gemfiles, as it doesn't copy the
6
+ # gemspec (and its dependencies) into the store.
7
+ # This workaround is from https://github.com/manveru/bundix/issues/10#issuecomment-405879379
8
+
9
+ require 'shellwords'
10
+
11
+ def sh(*args)
12
+ warn args.shelljoin
13
+ system(*args) || raise
14
+ end
15
+
16
+ sh 'bundle', 'lock'
17
+
18
+ require 'fileutils'
19
+ require 'bundler'
20
+
21
+ lockfile = Bundler::LockfileParser.new(File.read('Gemfile.lock'))
22
+ gems = lockfile.specs.select { |spec| spec.source.is_a?(Bundler::Source::Rubygems) }
23
+ sources = [URI('https://rubygems.org/')] | gems.map(&:source).flat_map(&:remotes)
24
+
25
+ FileUtils.mkdir_p 'nix/gem'
26
+ Dir.chdir 'nix/gem' do
27
+ ['Gemfile', 'Gemfile.lock', 'gemset.nix'].each do |f|
28
+ File.delete(f) if File.exist?(f)
29
+ end
30
+
31
+ File.open('Gemfile', 'w') do |gemfile|
32
+ sources.each { |source| gemfile.puts "source #{source.to_s.inspect}" }
33
+ gemfile.puts
34
+
35
+ gems.each do |gem|
36
+ gemfile.puts "gem #{gem.name.inspect}, #{gem.version.to_s.inspect}"
37
+ end
38
+ end
39
+
40
+ sh 'bundix', '-l'
41
+ end
data/shell.nix ADDED
@@ -0,0 +1,10 @@
1
+ with (import <nixpkgs> {});
2
+ let
3
+ env = bundlerEnv {
4
+ name = "bundler-env";
5
+ gemdir = ./nix/gem;
6
+ };
7
+ in stdenv.mkDerivation {
8
+ name = "shell";
9
+ buildInputs = [ env ];
10
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phraseapp_updater
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.10
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Griffin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-07 00:00:00.000000000 Z
11
+ date: 2020-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -174,6 +174,7 @@ extensions: []
174
174
  extra_rdoc_files: []
175
175
  files:
176
176
  - ".circleci/config.yml"
177
+ - ".envrc"
177
178
  - ".gitignore"
178
179
  - ".rspec"
179
180
  - ".travis.yml"
@@ -196,7 +197,12 @@ files:
196
197
  - lib/phraseapp_updater/phraseapp_api.rb
197
198
  - lib/phraseapp_updater/version.rb
198
199
  - lib/phraseapp_updater/yml_config_loader.rb
200
+ - nix/gem/Gemfile
201
+ - nix/gem/Gemfile.lock
202
+ - nix/gem/gemset.nix
203
+ - nix/generate.rb
199
204
  - phraseapp_updater.gemspec
205
+ - shell.nix
200
206
  homepage: https://app.engoo.com
201
207
  licenses:
202
208
  - MIT