txgh 6.0.6 → 6.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
  SHA1:
3
- metadata.gz: c09a127e480f748597f205e922b8010f1ec4fc5a
4
- data.tar.gz: 9cf2e06fab1d3cf62292a4a54df2155dcc6a044c
3
+ metadata.gz: b8ae06a79685c5a616fd334f7c4148b54377b840
4
+ data.tar.gz: f10e42acd8b9300f96182ebe1dc8786def18a224
5
5
  SHA512:
6
- metadata.gz: a5eb1b5415dac949bcf25b5d21607824614d57d45a7d66cf08583887096a260151ad0b3db142b7238d222de1fc08acca580c7a1d0cf87c080cb46d2e3eda6f72
7
- data.tar.gz: 18591ac6ed42c03c7920f0ac16b47d1d067c74696aab6936601deefd5605aaee7751880138389f811f19c53c7f9c94e8e32457890c4bc28645f697a38195cc72
6
+ metadata.gz: 5f8cfe3fe65b5e0c637e115c4f45d52cb4fc184fe581fabd4259b60060578c430f476fe3b9f13d0f184d620f1fa9657057a35f24ab915349563b2af9ab7519ea
7
+ data.tar.gz: d09b4cd10c3ee78012536adafc821806e5e9d7f35f043635b4de3a5e26b77d5fe47f58f845dfd7f18fe9c1800e3dcc66df3b3d3dcf0708dae42bd7c02e2f7a13
data/lib/txgh.rb CHANGED
@@ -45,18 +45,6 @@ module Txgh
45
45
  @events ||= Events.new
46
46
  end
47
47
 
48
- def update_status_callback(options)
49
- project = options.fetch(:project)
50
- repo = options.fetch(:repo)
51
- resource = options.fetch(:resource)
52
-
53
- GithubStatus.new(project, repo, resource).update(options.fetch(:sha))
54
- rescue Octokit::UnprocessableEntity
55
- # raised because we've tried to create too many statuses for the commit
56
- rescue Txgh::TransifexNotFoundError
57
- # raised if transifex resource can't be found
58
- end
59
-
60
48
  def env
61
49
  ENV.fetch('TXGH_ENV', DEFAULT_ENV)
62
50
  end
@@ -70,12 +58,4 @@ module Txgh
70
58
  # default set of base config providers
71
59
  key_manager.register_provider(providers::FileProvider, YAML)
72
60
  key_manager.register_provider(providers::RawProvider, YAML)
73
-
74
- events.subscribe('transifex.resource.updated') do |options|
75
- update_status_callback(options)
76
- end
77
-
78
- events.subscribe('github.resource.committed') do |options|
79
- update_status_callback(options)
80
- end
81
61
  end
@@ -1,3 +1,5 @@
1
+ require 'celluloid/current'
2
+
1
3
  module Txgh
2
4
  class GithubStatus
3
5
  class State
@@ -15,19 +17,29 @@ module Txgh
15
17
  end
16
18
 
17
19
  ALL_COMPLETE_DESCRIPTION = "Translations complete!"
18
- TARGET_URL_TEMPLATE = "https://www.transifex.com/%{organization}/%{project_slug}/%{resource_slug}/"
20
+ TARGET_URL_TEMPLATE = "https://www.transifex.com/%{organization}/%{project_slug}/content"
19
21
  DESCRIPTION_TEMPLATE = "%{complete}/%{total} translations complete."
20
22
  CONTEXT = 'continuous-localization/txgh'
21
23
 
22
- attr_reader :project, :repo, :tx_resource
24
+ class << self
25
+ def update(project, repo, branch)
26
+ new(project, repo, branch).update
27
+ end
28
+ end
23
29
 
24
- def initialize(project, repo, tx_resource)
30
+ attr_reader :project, :repo, :branch
31
+
32
+ def initialize(project, repo, branch)
25
33
  @project = project
26
34
  @repo = repo
27
- @tx_resource = tx_resource
35
+ @branch = branch
28
36
  end
29
37
 
30
- def update(sha)
38
+ def update
39
+ return if tx_resources.empty?
40
+
41
+ sha = repo.api.get_ref(branch)[:object][:sha]
42
+
31
43
  repo.api.create_status(
32
44
  sha, state, {
33
45
  context: context, target_url: target_url, description: description
@@ -42,10 +54,10 @@ module Txgh
42
54
  end
43
55
 
44
56
  def target_url
57
+ # assume all resources are from the same project
45
58
  TARGET_URL_TEMPLATE % {
46
59
  organization: project.organization,
47
- project_slug: tx_resource.project_slug,
48
- resource_slug: tx_resource.resource_slug
60
+ project_slug: tx_resources.first.project_slug
49
61
  }
50
62
  end
51
63
 
@@ -66,22 +78,54 @@ module Txgh
66
78
  end
67
79
 
68
80
  def all_complete?
69
- stats.all? do |locale, details|
70
- details['completed'] == '100%'
81
+ stats.all? do |resource_stats|
82
+ resource_stats.all? do |locale, details|
83
+ details['completed'] == '100%'
84
+ end
71
85
  end
72
86
  end
73
87
 
74
88
  def stat_totals
75
89
  @stat_totals ||= { complete: 0, total: 0 }.tap do |counts|
76
- stats.each_pair do |locale, details|
77
- counts[:total] += details['translated_entities'] + details['untranslated_entities']
78
- counts[:complete] += details['translated_entities']
90
+ stats.each do |resource_stats|
91
+ resource_stats.each_pair do |locale, details|
92
+ counts[:total] += details['translated_entities'] + details['untranslated_entities']
93
+ counts[:complete] += details['translated_entities']
94
+ end
79
95
  end
80
96
  end
81
97
  end
82
98
 
83
99
  def stats
84
- @stats ||= project.api.get_stats(*tx_resource.slugs)
100
+ @stats ||= tx_resources.map do |tx_resource|
101
+ Celluloid::Future.new { project.api.get_stats(*tx_resource.slugs) }
102
+ end.map(&:value)
103
+ end
104
+
105
+ def tx_resources
106
+ @tx_resources ||=
107
+ tx_config.resources.each_with_object([]) do |tx_resource, ret|
108
+ if repo.process_all_branches?
109
+ tx_resource = Txgh::TxBranchResource.new(tx_resource, branch)
110
+ end
111
+
112
+ next unless existing_slugs.include?(tx_resource.resource_slug)
113
+ ret << tx_resource
114
+ end
115
+ end
116
+
117
+ def existing_slugs
118
+ @existing_slugs ||= existing_resources.map do |resource|
119
+ resource['slug']
120
+ end
121
+ end
122
+
123
+ def existing_resources
124
+ @existing_resources ||= project.api.get_resources(project.name)
125
+ end
126
+
127
+ def tx_config
128
+ @tx_config ||= Txgh::Config::TxManager.tx_config(project, repo, branch)
85
129
  end
86
130
  end
87
131
  end
data/lib/txgh/puller.rb CHANGED
@@ -9,23 +9,35 @@ module Txgh
9
9
  end
10
10
 
11
11
  def pull
12
- tx_config.resources.each do |tx_resource|
12
+ existing_resources = project.api.get_resources(project.name)
13
+ slugs = existing_resources.map { |resource| resource['slug'] }
14
+
15
+ resources = tx_config.resources.each_with_object([]) do |tx_resource, ret|
13
16
  if repo.process_all_branches?
14
17
  tx_resource = Txgh::TxBranchResource.new(tx_resource, branch)
15
18
  end
16
19
 
17
- pull_resource(tx_resource)
20
+ next unless slugs.include?(tx_resource.resource_slug)
21
+ ret << tx_resource
22
+ end
23
+
24
+ pull_resources(resources, &block)
25
+ end
26
+
27
+ def pull_resources(tx_resources, languages = nil)
28
+ tx_resources.each do |tx_resource|
29
+ pull_resource(tx_resource, languages)
18
30
  end
19
31
  end
20
32
 
21
- def pull_resource(tx_resource)
22
- each_language do |language_code|
23
- committer.commit_resource(tx_resource, branch, language_code)
33
+ def pull_resource(tx_resource, languages = nil)
34
+ (languages || project.languages).each do |language|
35
+ committer.commit_resource(tx_resource, branch, language)
24
36
  end
25
37
  end
26
38
 
27
- def pull_slug(resource_slug)
28
- pull_resource(tx_config.resource(resource_slug, branch))
39
+ def pull_slug(resource_slug, languages = nil)
40
+ pull_resource(tx_config.resource(resource_slug, branch), languages)
29
41
  end
30
42
 
31
43
  private
@@ -34,18 +46,6 @@ module Txgh
34
46
  @committer ||= Txgh::ResourceCommitter.new(project, repo)
35
47
  end
36
48
 
37
- def each_language
38
- return to_enum(__method__) unless block_given?
39
-
40
- languages.each do |language|
41
- language_code = language['language_code']
42
-
43
- if project.supported_language?(language_code)
44
- yield language_code
45
- end
46
- end
47
- end
48
-
49
49
  def languages
50
50
  @languages ||= project.api.get_languages(project.name)
51
51
  end
data/lib/txgh/pusher.rb CHANGED
@@ -8,22 +8,35 @@ module Txgh
8
8
  @branch = branch
9
9
  end
10
10
 
11
- def push
12
- tx_config.resources.each do |tx_resource|
11
+ def push(&block)
12
+ existing_resources = project.api.get_resources(project.name)
13
+ slugs = existing_resources.map { |resource| resource['slug'] }
14
+
15
+ resources = tx_config.resources.each_with_object([]) do |tx_resource, ret|
13
16
  if repo.process_all_branches?
14
17
  tx_resource = Txgh::TxBranchResource.new(tx_resource, branch)
15
18
  end
16
19
 
17
- push_resource(tx_resource)
20
+ next unless slugs.include?(tx_resource.resource_slug)
21
+ ret << tx_resource
22
+ end
23
+
24
+ push_resources(resources, &block)
25
+ end
26
+
27
+ def push_resources(tx_resources, &block)
28
+ tx_resources.each do |tx_resource|
29
+ categories = block_given? ? yield(tx_resource) : {}
30
+ push_resource(tx_resource, categories)
18
31
  end
19
32
  end
20
33
 
21
- def push_resource(tx_resource)
22
- updater.update_resource(tx_resource)
34
+ def push_resource(tx_resource, categories = {})
35
+ updater.update_resource(tx_resource, categories)
23
36
  end
24
37
 
25
- def push_slug(resource_slug)
26
- push_resource(tx_config.resource(resource_slug, branch))
38
+ def push_slug(resource_slug, categories = {})
39
+ push_resource(tx_config.resource(resource_slug, branch), categories)
27
40
  end
28
41
 
29
42
  private
@@ -12,35 +12,27 @@ module Txgh
12
12
 
13
13
  def commit_resource(tx_resource, branch, language)
14
14
  return if prevent_commit_on?(branch)
15
+ return if language == tx_resource.source_lang
15
16
 
16
- unless language == tx_resource.source_lang
17
- file_name, translations = download(tx_resource, branch, language)
18
- message = commit_message_for(language, file_name)
17
+ file_name, translations = download(tx_resource, branch, language)
18
+ message = commit_message_for(language, file_name)
19
19
 
20
- if translations
21
- repo.api.update_contents(
22
- branch, [{ path: file_name, contents: translations }], message
23
- )
20
+ return unless translations
24
21
 
25
- fire_event_for(tx_resource, branch, language)
26
- end
27
- end
28
- end
29
-
30
- private
31
-
32
- def fire_event_for(tx_resource, branch, language)
33
- head = repo.api.get_ref(branch)
34
- sha = head[:object][:sha]
22
+ repo.api.update_contents(
23
+ branch, [{ path: file_name, contents: translations }], message
24
+ )
35
25
 
36
26
  Txgh.events.publish(
37
27
  'github.resource.committed', {
38
- project: project, repo: repo, resource: tx_resource, sha: sha,
39
- language: language
28
+ project: project, repo: repo, resource: tx_resource,
29
+ language: language, branch: branch
40
30
  }
41
31
  )
42
32
  end
43
33
 
34
+ private
35
+
44
36
  def download(tx_resource, branch, language)
45
37
  downloader = ResourceDownloader.new(
46
38
  project, repo, branch, {
@@ -24,24 +24,16 @@ module Txgh
24
24
  upload_whole(tx_resource, file, categories)
25
25
  end
26
26
 
27
- fire_event_for(tx_resource, branch)
28
- end
29
-
30
- private
31
-
32
- def fire_event_for(tx_resource, branch)
33
- ref = repo.api.get_ref(branch)
34
-
35
27
  Txgh.events.publish(
36
28
  'transifex.resource.updated', {
37
- project: project,
38
- repo: repo,
39
- resource: tx_resource,
40
- sha: ref[:object][:sha]
29
+ project: project, repo: repo, resource: tx_resource,
30
+ branch: tx_resource.branch
41
31
  }
42
32
  )
43
33
  end
44
34
 
35
+ private
36
+
45
37
  def upload_whole(tx_resource, file, categories)
46
38
  if repo.process_all_branches?
47
39
  upload_by_branch(tx_resource, file[:content], categories)
data/lib/txgh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Txgh
2
- VERSION = '6.0.6'
2
+ VERSION = '6.1.0'
3
3
  end
@@ -7,8 +7,9 @@ describe GithubStatus do
7
7
  include StandardTxghSetup
8
8
 
9
9
  describe '#update' do
10
- let(:status) { GithubStatus.new(transifex_project, github_repo, resource) }
10
+ let(:status) { GithubStatus.new(transifex_project, github_repo, branch) }
11
11
  let(:resource) { tx_config.resource(resource_slug) }
12
+ let(:branch) { 'heads/master' }
12
13
  let(:sha) { 'abc123shashasha' }
13
14
 
14
15
  let(:stats) do
@@ -22,6 +23,14 @@ describe GithubStatus do
22
23
 
23
24
  before(:each) do
24
25
  allow(transifex_api).to receive(:get_stats).and_return(stats)
26
+
27
+ allow(transifex_api).to receive(:get_resources).and_return(
28
+ [{ 'slug' => resource.resource_slug }]
29
+ )
30
+
31
+ allow(github_api).to receive(:get_ref).and_return(
32
+ object: { sha: sha }
33
+ )
25
34
  end
26
35
 
27
36
  context 'with all resources at 100%' do
@@ -32,11 +41,11 @@ describe GithubStatus do
32
41
  expect(options[:description]).to eq('Translations complete!')
33
42
  expect(options[:context]).to eq('continuous-localization/txgh')
34
43
  expect(options[:target_url]).to eq(
35
- "https://www.transifex.com/#{organization}/#{project_name}/#{resource_slug}/"
44
+ "https://www.transifex.com/#{organization}/#{project_name}/content"
36
45
  )
37
46
  end
38
47
 
39
- status.update(sha)
48
+ status.update
40
49
  end
41
50
  end
42
51
 
@@ -60,7 +69,7 @@ describe GithubStatus do
60
69
  expect(options[:description]).to eq('15/20 translations complete.')
61
70
  end
62
71
 
63
- status.update(sha)
72
+ status.update
64
73
  end
65
74
  end
66
75
  end
@@ -52,7 +52,7 @@ describe ResourceCommitter do
52
52
  options = event[:options]
53
53
  expect(options[:project].name).to eq(project_name)
54
54
  expect(options[:repo].name).to eq(repo_name)
55
- expect(options[:sha]).to eq('abc123shashasha')
55
+ expect(options[:branch]).to eq(branch)
56
56
  expect(options[:resource].original_resource_slug).to eq(resource_slug)
57
57
  expect(options[:language]).to eq(language)
58
58
  end
@@ -67,7 +67,7 @@ describe ResourceUpdater do
67
67
  options = event[:options]
68
68
  expect(options[:project].name).to eq(project_name)
69
69
  expect(options[:repo].name).to eq(repo_name)
70
- expect(options[:sha]).to eq(commit_sha)
70
+ expect(options[:branch]).to eq(ref)
71
71
  expect(options[:resource].original_resource_slug).to eq(resource_slug)
72
72
  end
73
73
 
data/spec/txgh_spec.rb CHANGED
@@ -30,30 +30,4 @@ describe Txgh do
30
30
  expect(instance.provider.scheme).to eq('raw')
31
31
  end
32
32
  end
33
-
34
- describe '#update_status_callback' do
35
- it 'handles github errors' do
36
- expect_any_instance_of(Txgh::GithubStatus).to(
37
- receive(:update).and_raise(Octokit::UnprocessableEntity)
38
- )
39
-
40
- expect do
41
- Txgh.update_status_callback(
42
- project: nil, repo: nil, resource: nil, sha: nil
43
- )
44
- end.to_not raise_error
45
- end
46
-
47
- it 'handles transifex errors' do
48
- expect_any_instance_of(Txgh::GithubStatus).to(
49
- receive(:update).and_raise(Txgh::TransifexNotFoundError)
50
- )
51
-
52
- expect do
53
- Txgh.update_status_callback(
54
- project: nil, repo: nil, resource: nil, sha: nil
55
- )
56
- end.to_not raise_error
57
- end
58
- end
59
33
  end
data/txgh.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.has_rdoc = true
15
15
 
16
16
  s.add_dependency 'abroad', '~> 4.1'
17
+ s.add_dependency 'celluloid'
17
18
  s.add_dependency 'faraday', '~> 0.9'
18
19
  s.add_dependency 'faraday_middleware', '~> 0.10'
19
20
  s.add_dependency 'json', '~> 1.8'
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: 6.0.6
4
+ version: 6.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-10-03 00:00:00.000000000 Z
12
+ date: 2016-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: abroad
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '4.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: celluloid
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: faraday
30
44
  requirement: !ruby/object:Gem::Requirement