txgh 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 500294b033cfebc1c6c9c52a28b75cc5e564bd13
4
- data.tar.gz: 5a3b866c7976246ec5e0c5532c69d044ff7b7dc2
3
+ metadata.gz: fefc92295bf9e5460cce6c06f8f849f79efd567f
4
+ data.tar.gz: 92bce889063a906f1a462c5cef402fbd52892802
5
5
  SHA512:
6
- metadata.gz: 56e81d08e7020c5c9aa292d5eb7801da5afab2d28509cffbe8b261c0248d0e48c9dea7aeb694b7694f6a8e689efa480454d325e6570caaeb1a4a386086d9ade2
7
- data.tar.gz: c2b1b2ff73af79c5aa0bfd0acc29e7fbfba37ef839c30ef7c4c7c90241fc9024e280f33fc1bb2eba007368fb47cf323cb65e37297dd04276c920c9796ef022aa
6
+ metadata.gz: f633fc680b9e5b37676b0cb5e3b9c0425fd3f7f45eb6a666f9d2f9d97d89d4047ae5712f1c9612e41cfcf1b067e022d23e68bbc9a2d02987d20e5722fcd068ae
7
+ data.tar.gz: e79103fdac87e6ba1a03172932c988acafddb8b4f11060a0e25d19a3df7985f65f9a77d72074a1029e9a2a2c0c2159f7ffc19cedfbf80cab6131194072db6436
@@ -36,18 +36,31 @@ module Txgh
36
36
 
37
37
  def base_config
38
38
  scheme, payload = split_uri(raw_config)
39
- provider_for(scheme).load(payload)
39
+
40
+ if provider = provider_for(scheme)
41
+ provider.load(payload)
42
+ else
43
+ raise Txgh::InvalidProviderError,
44
+ "Couldn't find a provider for the '#{scheme}' scheme. Please "\
45
+ "make sure txgh is configured properly."
46
+ end
40
47
  end
41
48
 
42
49
  def project_config_for(project_name)
43
50
  if config = base_config['transifex']['projects'][project_name]
44
51
  config.merge('name' => project_name)
52
+ else
53
+ raise Txgh::ProjectConfigNotFoundError,
54
+ "Couldn't find any configuration for the '#{project_name}' project."
45
55
  end
46
56
  end
47
57
 
48
58
  def repo_config_for(repo_name)
49
59
  if config = base_config['github']['repos'][repo_name]
50
60
  config.merge('name' => repo_name)
61
+ else
62
+ raise Txgh::RepoConfigNotFoundError,
63
+ "Couldn't find any configuration for the '#{repo_name}' repo."
51
64
  end
52
65
  end
53
66
  end
@@ -36,7 +36,7 @@ module Txgh
36
36
  def download
37
37
  github_repo.api.download(github_repo.name, payload, ref)
38
38
  rescue Octokit::NotFound
39
- raise ConfigNotFoundError, "Config file #{payload} not found in #{ref}"
39
+ raise Txgh::GitConfigNotFoundError, "Config file #{payload} not found in #{ref}"
40
40
  end
41
41
 
42
42
  def ref
data/lib/txgh/errors.rb CHANGED
@@ -5,5 +5,11 @@ module Txgh
5
5
  class TransifexApiError < StandardError; end
6
6
  class TransifexNotFoundError < TransifexApiError; end
7
7
  class TransifexUnauthorizedError < TransifexApiError; end
8
+
9
+ class InvalidProviderError < StandardError; end
10
+
8
11
  class ConfigNotFoundError < StandardError; end
12
+ class ProjectConfigNotFoundError < ConfigNotFoundError; end
13
+ class RepoConfigNotFoundError < ConfigNotFoundError; end
14
+ class GitConfigNotFoundError < ConfigNotFoundError; end
9
15
  end
@@ -1,4 +1,5 @@
1
1
  require 'base64'
2
+ require 'set'
2
3
 
3
4
  module Txgh
4
5
  module Handlers
@@ -14,11 +15,12 @@ module Txgh
14
15
  logger.info('found branch in github request')
15
16
 
16
17
  tx_resources = tx_resources_for(branch)
18
+
17
19
  modified_resources = added_and_modified_resources_for(tx_resources)
18
- modified_resources.merge!(l10n_resources_for(tx_resources))
20
+ modified_resources += l10n_resources_for(tx_resources)
19
21
 
20
22
  if repo.github_config_branch.include?('tags/')
21
- modified_resources.merge!(tag_resources_for(tx_resources))
23
+ modified_resources += tag_resources_for(tx_resources)
22
24
  end
23
25
 
24
26
  # Handle DBZ 'L10N' special case
@@ -33,9 +35,10 @@ module Txgh
33
35
 
34
36
  updater = ResourceUpdater.new(project, repo, logger)
35
37
  categories = { 'author' => payload['head_commit']['committer']['name'] }
38
+ ref = repo.api.get_ref(repo.name, branch)
36
39
 
37
- modified_resources.each_pair do |resource, commit_sha|
38
- updater.update_resource(resource, commit_sha, categories)
40
+ modified_resources.each do |resource|
41
+ updater.update_resource(resource, ref[:object][:sha], categories)
39
42
  end
40
43
  end
41
44
 
@@ -45,35 +48,34 @@ module Txgh
45
48
  private
46
49
 
47
50
  def tag_resources_for(tx_resources)
48
- payload['head_commit']['modified'].each_with_object({}) do |modified, ret|
51
+ payload['head_commit']['modified'].each_with_object(Set.new) do |modified, ret|
49
52
  logger.info("processing modified file: #{modified}")
50
53
 
51
54
  if tx_resources.include?(modified)
52
- ret[tx_resources[modified]] = payload['head_commit']['id']
55
+ ret << tx_resources[modified]
53
56
  end
54
57
  end
55
58
  end
56
59
 
57
60
  def l10n_resources_for(tx_resources)
58
- payload['head_commit']['modified'].each_with_object({}) do |modified, ret|
61
+ payload['head_commit']['modified'].each_with_object(Set.new) do |modified, ret|
59
62
  if tx_resources.include?(modified)
60
63
  logger.info("setting new resource: #{tx_resources[modified].L10N_resource_slug}")
61
- ret[tx_resources[modified]] = payload['head_commit']['id']
64
+ ret << tx_resources[modified]
62
65
  end
63
66
  end
64
67
  end
65
68
 
66
- # Finds the updated resources and maps the most recent commit in which
67
- # each was modified
69
+ # finds the resources that were updated in each commit
68
70
  def added_and_modified_resources_for(tx_resources)
69
- payload['commits'].each_with_object({}) do |commit, ret|
71
+ payload['commits'].each_with_object(Set.new) do |commit, ret|
70
72
  logger.info('processing commit')
71
73
 
72
74
  (commit['modified'] + commit['added']).each do |file|
73
75
  logger.info("processing added/modified file: #{file}")
74
76
 
75
77
  if tx_resources.include?(file)
76
- ret[tx_resources[file]] = commit['id']
78
+ ret << tx_resources[file]
77
79
  end
78
80
  end
79
81
  end
data/lib/txgh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Txgh
2
- VERSION = '4.0.0'
2
+ VERSION = '5.0.0'
3
3
  end
@@ -18,6 +18,23 @@ describe KeyManager do
18
18
  expect(config.project_config).to eq(project_config)
19
19
  expect(config.repo_config).to eq(repo_config)
20
20
  end
21
+
22
+ it "raises an error if config can't be found" do
23
+ expect { KeyManager.config_from_project('justkidding') }.to(
24
+ raise_error(Txgh::ProjectConfigNotFoundError)
25
+ )
26
+ end
27
+
28
+ it "raises an error if the scheme can't be recognized" do
29
+ # remove the scheme
30
+ allow(Txgh::Config::KeyManager).to(
31
+ receive(:raw_config).and_return(YAML.dump(base_config))
32
+ )
33
+
34
+ expect { KeyManager.config_from_project(project_name) }.to(
35
+ raise_error(Txgh::InvalidProviderError)
36
+ )
37
+ end
21
38
  end
22
39
 
23
40
  describe '.config_from_repo' do
@@ -31,6 +48,23 @@ describe KeyManager do
31
48
  expect(config.project_config).to eq(project_config)
32
49
  expect(config.repo_config).to eq(repo_config)
33
50
  end
51
+
52
+ it "raises an error if config can't be found" do
53
+ expect { KeyManager.config_from_repo('hahayeahright') }.to(
54
+ raise_error(Txgh::RepoConfigNotFoundError)
55
+ )
56
+ end
57
+
58
+ it "raises an error if the scheme can't be recognized" do
59
+ # remove the scheme
60
+ allow(Txgh::Config::KeyManager).to(
61
+ receive(:raw_config).and_return(YAML.dump(base_config))
62
+ )
63
+
64
+ expect { KeyManager.config_from_repo(repo_name) }.to(
65
+ raise_error(InvalidProviderError)
66
+ )
67
+ end
34
68
  end
35
69
 
36
70
  describe '.config_from' do
@@ -32,7 +32,7 @@ describe TxManager do
32
32
  it "raises an error if the git repo doesn't contain the requested config file" do
33
33
  expect(repo.api).to receive(:download).and_raise(Octokit::NotFound)
34
34
  expect { TxManager.tx_config(project, repo, 'my_branch') }.to(
35
- raise_error(ConfigNotFoundError)
35
+ raise_error(GitConfigNotFoundError)
36
36
  )
37
37
  end
38
38
 
@@ -48,6 +48,12 @@ describe PushHandler do
48
48
  expect(categories).to eq('author' => 'Test User')
49
49
  end
50
50
  )
51
+
52
+ expect(github_api).to(
53
+ receive(:get_ref).with(repo_name, ref).and_return(
54
+ object: { sha: payload.head_commit[:id] }
55
+ )
56
+ )
51
57
  end
52
58
 
53
59
  response = handler.execute
@@ -68,6 +74,12 @@ describe PushHandler do
68
74
  )
69
75
  )
70
76
 
77
+ expect(github_api).to(
78
+ receive(:get_ref).with(repo_name, ref).and_return(
79
+ object: { sha: payload.head_commit[:id] }
80
+ )
81
+ )
82
+
71
83
  response = handler.execute
72
84
  expect(response.status).to eq(200)
73
85
  expect(response.body).to eq(true)
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: 4.0.0
4
+ version: 5.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-05-26 00:00:00.000000000 Z
12
+ date: 2016-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: abroad