txgh 4.0.0 → 5.0.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/config/key_manager.rb +14 -1
- data/lib/txgh/config/providers/git_provider.rb +1 -1
- data/lib/txgh/errors.rb +6 -0
- data/lib/txgh/handlers/github/push_handler.rb +14 -12
- data/lib/txgh/version.rb +1 -1
- data/spec/config/key_manager_spec.rb +34 -0
- data/spec/config/tx_manager_spec.rb +1 -1
- data/spec/handlers/github/push_handler_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fefc92295bf9e5460cce6c06f8f849f79efd567f
|
4
|
+
data.tar.gz: 92bce889063a906f1a462c5cef402fbd52892802
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
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
|
20
|
+
modified_resources += l10n_resources_for(tx_resources)
|
19
21
|
|
20
22
|
if repo.github_config_branch.include?('tags/')
|
21
|
-
modified_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.
|
38
|
-
updater.update_resource(resource,
|
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(
|
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
|
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(
|
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
|
64
|
+
ret << tx_resources[modified]
|
62
65
|
end
|
63
66
|
end
|
64
67
|
end
|
65
68
|
|
66
|
-
#
|
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(
|
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
|
78
|
+
ret << tx_resources[file]
|
77
79
|
end
|
78
80
|
end
|
79
81
|
end
|
data/lib/txgh/version.rb
CHANGED
@@ -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(
|
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
|
+
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-
|
12
|
+
date: 2016-06-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: abroad
|