txgh 6.8.1 → 7.0.0.beta
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/config_pair.rb +12 -4
- data/lib/txgh/config/key_manager.rb +4 -6
- data/lib/txgh/config/providers/git_provider.rb +5 -7
- data/lib/txgh/config/providers/github_provider.rb +16 -0
- data/lib/txgh/config/providers/gitlab_provider.rb +16 -0
- data/lib/txgh/config/providers.rb +5 -3
- data/lib/txgh/config/tx_manager.rb +2 -2
- data/lib/txgh/git_api.rb +85 -0
- data/lib/txgh/git_repo.rb +90 -0
- data/lib/txgh/git_status.rb +151 -0
- data/lib/txgh/github_api.rb +1 -13
- data/lib/txgh/github_repo.rb +1 -89
- data/lib/txgh/github_status.rb +1 -148
- data/lib/txgh/gitlab_api.rb +63 -0
- data/lib/txgh/gitlab_repo.rb +4 -0
- data/lib/txgh/gitlab_status.rb +4 -0
- data/lib/txgh/version.rb +1 -1
- data/lib/txgh.rb +10 -3
- data/spec/category_support_spec.rb +6 -8
- data/spec/config/config_pair_spec.rb +41 -16
- data/spec/config/key_manager_spec.rb +30 -17
- data/spec/config/provider_instance_spec.rb +3 -6
- data/spec/config/provider_support_spec.rb +2 -5
- data/spec/config/tx_config_spec.rb +2 -4
- data/spec/config/tx_manager_spec.rb +8 -11
- data/spec/diff_calculator_spec.rb +2 -4
- data/spec/events_spec.rb +2 -4
- data/spec/github_api_spec.rb +2 -4
- data/spec/github_repo_spec.rb +10 -16
- data/spec/github_status_spec.rb +5 -7
- data/spec/gitlab_api_spec.rb +112 -0
- data/spec/gitlab_repo_spec.rb +172 -0
- data/spec/gitlab_status_spec.rb +93 -0
- data/spec/helpers/standard_txgh_setup.rb +32 -6
- data/spec/merge_calculator_spec.rb +4 -6
- data/spec/parse_config_spec.rb +3 -5
- data/spec/resource_committer_spec.rb +3 -5
- data/spec/resource_contents_spec.rb +8 -10
- data/spec/resource_deleter_spec.rb +3 -5
- data/spec/resource_downloader_spec.rb +2 -4
- data/spec/resource_updater_spec.rb +3 -5
- data/spec/transifex_api_spec.rb +2 -4
- data/spec/tx_branch_resource_spec.rb +10 -12
- data/spec/tx_resource_spec.rb +2 -4
- data/spec/utils_spec.rb +22 -24
- data/txgh.gemspec +1 -1
- metadata +29 -4
data/spec/github_repo_spec.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
describe GithubRepo do
|
3
|
+
describe Txgh::GithubRepo do
|
6
4
|
let(:repo_name) { 'my_org/my_repo' }
|
7
5
|
let(:branch) { 'master' }
|
8
6
|
let(:tag) { 'tags/foo' }
|
9
7
|
let(:api) { :api }
|
10
|
-
let(:repo) {
|
8
|
+
let(:repo) { described_class.new(config, api) }
|
11
9
|
let(:diff_point) { nil }
|
12
10
|
let(:config) do
|
13
11
|
{
|
@@ -87,10 +85,6 @@ describe GithubRepo do
|
|
87
85
|
expect(repo.should_process_ref?('heads/foo')).to eq(false)
|
88
86
|
end
|
89
87
|
|
90
|
-
it 'returns true if the branch contains the special L10N text' do
|
91
|
-
expect(repo.should_process_ref?('heads/L10N_foo')).to eq(true)
|
92
|
-
end
|
93
|
-
|
94
88
|
it 'returns true if the given tag matches the configured one' do
|
95
89
|
expect(repo.should_process_ref?('tags/foo')).to eq(true)
|
96
90
|
end
|
@@ -100,12 +94,12 @@ describe GithubRepo do
|
|
100
94
|
end
|
101
95
|
end
|
102
96
|
|
103
|
-
describe '#
|
97
|
+
describe '#git_config_branch' do
|
104
98
|
context 'with all branches indicated' do
|
105
99
|
let(:branch) { 'all' }
|
106
100
|
|
107
101
|
it "doesn't modify the passed branch, i.e. returns 'all'" do
|
108
|
-
expect(repo.
|
102
|
+
expect(repo.git_config_branch).to eq('all')
|
109
103
|
end
|
110
104
|
end
|
111
105
|
|
@@ -113,7 +107,7 @@ describe GithubRepo do
|
|
113
107
|
let(:branch) { nil }
|
114
108
|
|
115
109
|
it 'chooses master by default' do
|
116
|
-
expect(repo.
|
110
|
+
expect(repo.git_config_branch).to eq('heads/master')
|
117
111
|
end
|
118
112
|
end
|
119
113
|
|
@@ -121,17 +115,17 @@ describe GithubRepo do
|
|
121
115
|
let(:branch) { 'foobar' }
|
122
116
|
|
123
117
|
it 'correctly prefixes the branch' do
|
124
|
-
expect(repo.
|
118
|
+
expect(repo.git_config_branch).to eq('heads/foobar')
|
125
119
|
end
|
126
120
|
end
|
127
121
|
end
|
128
122
|
|
129
|
-
describe '#
|
123
|
+
describe '#git_config_tag' do
|
130
124
|
context 'with all tags indicated' do
|
131
125
|
let(:tag) { 'all' }
|
132
126
|
|
133
127
|
it "doesn't modify the passed tag, i.e. returns 'all'" do
|
134
|
-
expect(repo.
|
128
|
+
expect(repo.git_config_tag).to eq('all')
|
135
129
|
end
|
136
130
|
end
|
137
131
|
|
@@ -139,7 +133,7 @@ describe GithubRepo do
|
|
139
133
|
let(:tag) { nil }
|
140
134
|
|
141
135
|
it 'returns nil' do
|
142
|
-
expect(repo.
|
136
|
+
expect(repo.git_config_tag).to be_nil
|
143
137
|
end
|
144
138
|
end
|
145
139
|
|
@@ -147,7 +141,7 @@ describe GithubRepo do
|
|
147
141
|
let(:tag) { 'tags/foobar' }
|
148
142
|
|
149
143
|
it 'leaves the prefix intact' do
|
150
|
-
expect(repo.
|
144
|
+
expect(repo.git_config_tag).to eq('tags/foobar')
|
151
145
|
end
|
152
146
|
end
|
153
147
|
end
|
data/spec/github_status_spec.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'helpers/standard_txgh_setup'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
describe GithubStatus do
|
4
|
+
describe Txgh::GithubStatus do
|
7
5
|
include StandardTxghSetup
|
8
6
|
|
9
|
-
let(:status) {
|
7
|
+
let(:status) { described_class.new(transifex_project, github_repo, branch) }
|
10
8
|
let(:resource) { tx_config.resource(resource_slug) }
|
11
9
|
let(:branch) { 'heads/master' }
|
12
10
|
let(:sha) { 'abc123shashasha' }
|
@@ -39,7 +37,7 @@ describe GithubStatus do
|
|
39
37
|
it 'reports status as success' do
|
40
38
|
expect(github_api).to receive(:create_status) do |commit_sha, state, options|
|
41
39
|
expect(commit_sha).to eq(sha)
|
42
|
-
expect(state).to eq(
|
40
|
+
expect(state).to eq(described_class::State.success)
|
43
41
|
expect(options[:description]).to eq('Translations complete!')
|
44
42
|
expect(options[:context]).to eq('continuous-localization/txgh')
|
45
43
|
expect(options[:target_url]).to eq(
|
@@ -67,7 +65,7 @@ describe GithubStatus do
|
|
67
65
|
|
68
66
|
it 'reports status as pending' do
|
69
67
|
expect(github_api).to receive(:create_status) do |commit_sha, state, options|
|
70
|
-
expect(state).to eq(
|
68
|
+
expect(state).to eq(described_class::State.pending)
|
71
69
|
expect(options[:description]).to eq('15/20 translations complete.')
|
72
70
|
end
|
73
71
|
|
@@ -83,7 +81,7 @@ describe GithubStatus do
|
|
83
81
|
|
84
82
|
expect(github_api).to receive(:create_status) do |commit_sha, state, options|
|
85
83
|
expect(commit_sha).to eq(sha)
|
86
|
-
expect(state).to eq(
|
84
|
+
expect(state).to eq(described_class::State.error)
|
87
85
|
expect(options[:description]).to eq(description)
|
88
86
|
expect(options[:context]).to eq('continuous-localization/txgh')
|
89
87
|
expect(options[:target_url]).to eq(target_url)
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
describe Txgh::GitlabApi do
|
5
|
+
let(:client) { double(:client) }
|
6
|
+
let(:api) { described_class.create_from_client(client, repo) }
|
7
|
+
let(:repo) { 'my_org/my_repo' }
|
8
|
+
let(:branch) { 'master' }
|
9
|
+
let(:sha) { 'abc123' }
|
10
|
+
let(:gitlab_response) do
|
11
|
+
OpenStruct.new({
|
12
|
+
code: 404,
|
13
|
+
request: double(base_uri: 'https://gitlab.com/api/v3', path: '/foo'),
|
14
|
+
parsed_response: Gitlab::ObjectifiedHash.new(
|
15
|
+
error_description: 'Displayed error_description',
|
16
|
+
error: 'also will not be displayed'
|
17
|
+
)
|
18
|
+
})
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#update_contents' do
|
22
|
+
let(:path) { 'path/to/file.txt' }
|
23
|
+
let(:old_contents) { 'abc123' }
|
24
|
+
let(:old_sha) { Utils.git_hash_blob(old_contents) }
|
25
|
+
|
26
|
+
it 'updates the given file contents' do
|
27
|
+
new_contents = 'def456'
|
28
|
+
|
29
|
+
expect(client).to(
|
30
|
+
receive(:get_file)
|
31
|
+
.with(repo, path, branch)
|
32
|
+
.and_return(double(content_sha256: old_sha))
|
33
|
+
)
|
34
|
+
|
35
|
+
expect(client).to(
|
36
|
+
receive(:edit_file)
|
37
|
+
.with(repo, path, branch, new_contents, 'message')
|
38
|
+
)
|
39
|
+
|
40
|
+
api.update_contents(branch, [{ path: path, contents: new_contents }], 'message')
|
41
|
+
end
|
42
|
+
|
43
|
+
it "doesn't update the file contents if the file hasn't changed" do
|
44
|
+
expect(client).to(
|
45
|
+
receive(:get_file)
|
46
|
+
.with(repo, path, branch)
|
47
|
+
.and_return(double(content_sha256: old_sha))
|
48
|
+
)
|
49
|
+
|
50
|
+
expect(client).to_not receive(:edit_file)
|
51
|
+
|
52
|
+
api.update_contents(branch, [{ path: path, contents: old_contents }], 'message')
|
53
|
+
end
|
54
|
+
|
55
|
+
it "creates the file if it doesn't already exist" do
|
56
|
+
new_contents = 'foobar'
|
57
|
+
expect(client).to receive(:get_file).and_raise(::Gitlab::Error::NotFound.new(gitlab_response))
|
58
|
+
|
59
|
+
expect(client).to(
|
60
|
+
receive(:edit_file)
|
61
|
+
.with(repo, path, branch, new_contents, 'message')
|
62
|
+
)
|
63
|
+
|
64
|
+
api.update_contents(branch, [{ path: path, contents: new_contents }], 'message')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#get_ref' do
|
69
|
+
it 'retrieves the given ref (i.e. branch) using the client' do
|
70
|
+
expect(client).to receive(:commit).with(repo, sha) { double(short_id: '0') }
|
71
|
+
api.get_ref(sha)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#download' do
|
76
|
+
let(:path) { 'path/to/file.xyz' }
|
77
|
+
|
78
|
+
it 'downloads the file from the given branch' do
|
79
|
+
expect(client).to(
|
80
|
+
receive(:get_file)
|
81
|
+
.with(repo, path, branch)
|
82
|
+
.and_return(double(content: 'content', encoding: 'utf-8'))
|
83
|
+
)
|
84
|
+
|
85
|
+
expect(api.download(path, branch)).to eq({ content: 'content' })
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'encodes the string using the encoding specified in the response' do
|
89
|
+
content = 'ありがと'.encode('UTF-16')
|
90
|
+
|
91
|
+
expect(client).to(
|
92
|
+
receive(:get_file)
|
93
|
+
.with(repo, path, branch)
|
94
|
+
.and_return(double(content: content, encoding: 'utf-16'))
|
95
|
+
)
|
96
|
+
|
97
|
+
result = api.download(path, branch)
|
98
|
+
expect(result[:content].encoding).to eq(Encoding::UTF_16)
|
99
|
+
expect(result[:content]).to eq(content)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'automatically decodes base64-encoded content' do
|
103
|
+
expect(client).to(
|
104
|
+
receive(:get_file)
|
105
|
+
.with(repo, path, branch)
|
106
|
+
.and_return(double(content: Base64.encode64('content'), encoding: 'base64'))
|
107
|
+
)
|
108
|
+
|
109
|
+
expect(api.download(path, branch)).to eq({ content: 'content' })
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Txgh::GitlabRepo do
|
4
|
+
let(:repo_name) { 'my_org/my_repo' }
|
5
|
+
let(:branch) { 'master' }
|
6
|
+
let(:tag) { 'tags/foo' }
|
7
|
+
let(:api) { :api }
|
8
|
+
let(:repo) { described_class.new(config, api) }
|
9
|
+
let(:diff_point) { nil }
|
10
|
+
let(:config) do
|
11
|
+
{
|
12
|
+
'name' => repo_name, 'branch' => branch, 'tag' => tag,
|
13
|
+
'diff_point' => diff_point
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#name' do
|
18
|
+
it 'retrieves the repo name from the config' do
|
19
|
+
expect(repo.name).to eq(repo_name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#branch' do
|
24
|
+
it 'retrieves the branch name from the config' do
|
25
|
+
expect(repo.branch).to eq(branch)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#tag' do
|
30
|
+
it 'retrieves the tag name from the config' do
|
31
|
+
expect(repo.tag).to eq(tag)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#process_all_branches?' do
|
36
|
+
it 'returns false if only one branch should be processed' do
|
37
|
+
expect(repo.process_all_branches?).to eq(false)
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with all branches indicated' do
|
41
|
+
let(:branch) { 'all' }
|
42
|
+
|
43
|
+
it 'returns true if all branches should be processed' do
|
44
|
+
expect(repo.process_all_branches?).to eq(true)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#process_all_tags?' do
|
50
|
+
it 'returns false if only one tag should be processed' do
|
51
|
+
expect(repo.process_all_tags?).to eq(false)
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'with all tags indicated' do
|
55
|
+
let(:tag) { 'all' }
|
56
|
+
|
57
|
+
it 'returns true if all tags should be processed' do
|
58
|
+
expect(repo.process_all_tags?).to eq(true)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#should_process_ref?' do
|
64
|
+
context 'with all branches indicated' do
|
65
|
+
let(:branch) { 'all' }
|
66
|
+
|
67
|
+
it 'returns true if all branches should be processed' do
|
68
|
+
expect(repo.should_process_ref?('heads/foo')).to eq(true)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'with all tags indicated' do
|
73
|
+
let(:tag) { 'all' }
|
74
|
+
|
75
|
+
it 'returns true if all tags should be processed' do
|
76
|
+
expect(repo.should_process_ref?('tags/foo')).to eq(true)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns true if the given branch matches the configured one' do
|
81
|
+
expect(repo.should_process_ref?('heads/master')).to eq(true)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "returns false if the given branch doesn't match the configured one" do
|
85
|
+
expect(repo.should_process_ref?('heads/foo')).to eq(false)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'returns true if the given tag matches the configured one' do
|
89
|
+
expect(repo.should_process_ref?('tags/foo')).to eq(true)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "returns false if the given tag doesn't match the configured one" do
|
93
|
+
expect(repo.should_process_ref?('heads/foobar')).to eq(false)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#git_config_branch' do
|
98
|
+
context 'with all branches indicated' do
|
99
|
+
let(:branch) { 'all' }
|
100
|
+
|
101
|
+
it "doesn't modify the passed branch, i.e. returns 'all'" do
|
102
|
+
expect(repo.git_config_branch).to eq('all')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'with a nil branch' do
|
107
|
+
let(:branch) { nil }
|
108
|
+
|
109
|
+
it 'chooses master by default' do
|
110
|
+
expect(repo.git_config_branch).to eq('heads/master')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'with a configured branch' do
|
115
|
+
let(:branch) { 'foobar' }
|
116
|
+
|
117
|
+
it 'correctly prefixes the branch' do
|
118
|
+
expect(repo.git_config_branch).to eq('heads/foobar')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '#git_config_tag' do
|
124
|
+
context 'with all tags indicated' do
|
125
|
+
let(:tag) { 'all' }
|
126
|
+
|
127
|
+
it "doesn't modify the passed tag, i.e. returns 'all'" do
|
128
|
+
expect(repo.git_config_tag).to eq('all')
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'with a nil tag' do
|
133
|
+
let(:tag) { nil }
|
134
|
+
|
135
|
+
it 'returns nil' do
|
136
|
+
expect(repo.git_config_tag).to be_nil
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'with a configured tag' do
|
141
|
+
let(:tag) { 'tags/foobar' }
|
142
|
+
|
143
|
+
it 'leaves the prefix intact' do
|
144
|
+
expect(repo.git_config_tag).to eq('tags/foobar')
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '#upload_diffs?' do
|
150
|
+
it 'returns false by default' do
|
151
|
+
expect(repo.upload_diffs?).to eq(false)
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'with a configured diff point' do
|
155
|
+
let(:diff_point) { 'heads/master' }
|
156
|
+
|
157
|
+
it 'returns true when a diff point is configured' do
|
158
|
+
expect(repo.upload_diffs?).to eq(true)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#diff_point' do
|
164
|
+
context 'with a configured diff point' do
|
165
|
+
let(:diff_point) { 'heads/master' }
|
166
|
+
|
167
|
+
it 'returns the provided diff point' do
|
168
|
+
expect(repo.diff_point).to eq(diff_point)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'helpers/standard_txgh_setup'
|
3
|
+
|
4
|
+
describe Txgh::GitlabStatus do
|
5
|
+
include StandardTxghSetup
|
6
|
+
|
7
|
+
let(:status) { described_class.new(transifex_project, gitlab_repo, branch) }
|
8
|
+
let(:resource) { tx_config.resource(resource_slug) }
|
9
|
+
let(:branch) { 'heads/master' }
|
10
|
+
let(:sha) { 'abc123shashasha' }
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
allow(transifex_api).to receive(:get_resources).and_return(
|
14
|
+
[{ 'slug' => resource.resource_slug }]
|
15
|
+
)
|
16
|
+
|
17
|
+
allow(gitlab_api).to receive(:get_ref).and_return(
|
18
|
+
object: { sha: sha }
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#update' do
|
23
|
+
let(:stats) do
|
24
|
+
supported_languages.each_with_object({}) do |language, ret|
|
25
|
+
ret[language] = {
|
26
|
+
'translated_entities' => 10, 'untranslated_entities' => 0,
|
27
|
+
'completed' => '100%'
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
before(:each) do
|
33
|
+
allow(transifex_api).to receive(:get_stats).and_return(stats)
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with all resources at 100%' do
|
37
|
+
it 'reports status as success' do
|
38
|
+
expect(gitlab_api).to receive(:create_status) do |commit_sha, state, options|
|
39
|
+
expect(commit_sha).to eq(sha)
|
40
|
+
expect(state).to eq(described_class::State.success)
|
41
|
+
expect(options[:description]).to eq('Translations complete!')
|
42
|
+
expect(options[:context]).to eq('continuous-localization/txgh')
|
43
|
+
expect(options[:target_url]).to eq(
|
44
|
+
"https://www.transifex.com/#{organization}/#{project_name}/content"
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
status.update
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with one language at less than 100%' do
|
53
|
+
let(:stats) do
|
54
|
+
{
|
55
|
+
'pt' => {
|
56
|
+
'translated_entities' => 10, 'untranslated_entities' => 0,
|
57
|
+
'completed' => '100%'
|
58
|
+
},
|
59
|
+
'ja' => {
|
60
|
+
'translated_entities' => 5, 'untranslated_entities' => 5,
|
61
|
+
'completed' => '50%'
|
62
|
+
}
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'reports status as pending' do
|
67
|
+
expect(gitlab_api).to receive(:create_status) do |commit_sha, state, options|
|
68
|
+
expect(state).to eq(described_class::State.pending)
|
69
|
+
expect(options[:description]).to eq('15/20 translations complete.')
|
70
|
+
end
|
71
|
+
|
72
|
+
status.update
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#error' do
|
78
|
+
it 'reports status as error' do
|
79
|
+
target_url = 'http://abc.foo.com'
|
80
|
+
description = 'The green albatross flitters in the moonlight'
|
81
|
+
|
82
|
+
expect(gitlab_api).to receive(:create_status) do |commit_sha, state, options|
|
83
|
+
expect(commit_sha).to eq(sha)
|
84
|
+
expect(state).to eq(described_class::State.error)
|
85
|
+
expect(options[:description]).to eq(description)
|
86
|
+
expect(options[:context]).to eq('continuous-localization/txgh')
|
87
|
+
expect(options[:target_url]).to eq(target_url)
|
88
|
+
end
|
89
|
+
|
90
|
+
status.error(target_url: target_url, description: description)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -6,11 +6,13 @@ module StandardTxghSetup
|
|
6
6
|
|
7
7
|
let(:logger) { NilLogger.new }
|
8
8
|
let(:github_api) { double(:github_api) }
|
9
|
+
let(:gitlab_api) { double(:gitlab_api) }
|
9
10
|
let(:transifex_api) { double(:transifex_api) }
|
10
11
|
|
11
12
|
let(:project_name) { 'my_awesome_project' }
|
12
13
|
let(:resource_slug) { 'my_resource' }
|
13
|
-
let(:
|
14
|
+
let(:github_repo_name) { 'my_org/my_repo' }
|
15
|
+
let(:gitlab_repo_name) { 'my_org/gitlab_repo' }
|
14
16
|
let(:branch) { 'master' }
|
15
17
|
let(:tag) { 'all' }
|
16
18
|
let(:ref) { 'heads/master' }
|
@@ -20,12 +22,13 @@ module StandardTxghSetup
|
|
20
22
|
let(:diff_point) { nil }
|
21
23
|
let(:organization) { 'myorg' }
|
22
24
|
let(:commit_message_template) { nil } # i.e. use the default
|
25
|
+
let(:push_translations_to) { github_repo_name }
|
23
26
|
|
24
27
|
let(:project_config) do
|
25
28
|
{
|
26
29
|
'api_username' => 'transifex_api_username',
|
27
30
|
'api_password' => 'transifex_api_password',
|
28
|
-
'push_translations_to' =>
|
31
|
+
'push_translations_to' => push_translations_to,
|
29
32
|
'name' => project_name,
|
30
33
|
'tx_config' => "raw://#{tx_config_raw}",
|
31
34
|
'webhook_secret' => 'abc123',
|
@@ -35,14 +38,28 @@ module StandardTxghSetup
|
|
35
38
|
}
|
36
39
|
end
|
37
40
|
|
38
|
-
let(:
|
41
|
+
let(:github_config) do
|
39
42
|
{
|
40
43
|
'api_username' => 'github_api_username',
|
41
44
|
'api_token' => 'github_api_token',
|
45
|
+
'git_repo_source' => 'github',
|
42
46
|
'push_source_to' => project_name,
|
43
47
|
'branch' => branch,
|
44
48
|
'tag' => tag,
|
45
|
-
'name' =>
|
49
|
+
'name' => github_repo_name,
|
50
|
+
'webhook_secret' => 'abc123',
|
51
|
+
'diff_point' => diff_point,
|
52
|
+
'commit_message' => commit_message_template
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
let(:gitlab_config) do
|
57
|
+
{
|
58
|
+
'api_token' => 'gitlab_api_token',
|
59
|
+
'git_repo_source' => 'gitlab',
|
60
|
+
'push_source_to' => project_name,
|
61
|
+
'branch' => branch,
|
62
|
+
'name' => gitlab_repo_name,
|
46
63
|
'webhook_secret' => 'abc123',
|
47
64
|
'diff_point' => diff_point,
|
48
65
|
'commit_message' => commit_message_template
|
@@ -77,7 +94,12 @@ module StandardTxghSetup
|
|
77
94
|
{
|
78
95
|
'github' => {
|
79
96
|
'repos' => {
|
80
|
-
|
97
|
+
github_repo_name => github_config
|
98
|
+
}
|
99
|
+
},
|
100
|
+
'gitlab' => {
|
101
|
+
'repos' => {
|
102
|
+
gitlab_repo_name => gitlab_config
|
81
103
|
}
|
82
104
|
},
|
83
105
|
'transifex' => {
|
@@ -93,6 +115,10 @@ module StandardTxghSetup
|
|
93
115
|
end
|
94
116
|
|
95
117
|
let(:github_repo) do
|
96
|
-
Txgh::GithubRepo.new(
|
118
|
+
Txgh::GithubRepo.new(github_config, github_api)
|
119
|
+
end
|
120
|
+
|
121
|
+
let(:gitlab_repo) do
|
122
|
+
Txgh::GitlabRepo.new(gitlab_config, gitlab_api)
|
97
123
|
end
|
98
124
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
describe MergeCalculator do
|
3
|
+
describe Txgh::MergeCalculator do
|
6
4
|
def phrase(key, string)
|
7
5
|
{ 'key' => key, 'string' => string }
|
8
6
|
end
|
@@ -15,11 +13,11 @@ describe MergeCalculator do
|
|
15
13
|
end
|
16
14
|
|
17
15
|
let(:head_contents) do
|
18
|
-
ResourceContents.from_phrase_list(resource, head_phrases)
|
16
|
+
Txgh::ResourceContents.from_phrase_list(resource, head_phrases)
|
19
17
|
end
|
20
18
|
|
21
19
|
let(:diff_point_contents) do
|
22
|
-
ResourceContents.from_phrase_list(resource, diff_point_phrases)
|
20
|
+
Txgh::ResourceContents.from_phrase_list(resource, diff_point_phrases)
|
23
21
|
end
|
24
22
|
|
25
23
|
let(:diff_hash) do
|
@@ -27,7 +25,7 @@ describe MergeCalculator do
|
|
27
25
|
end
|
28
26
|
|
29
27
|
let(:merge_result) do
|
30
|
-
|
28
|
+
described_class.merge(head_contents, diff_point_contents, diff_hash)
|
31
29
|
end
|
32
30
|
|
33
31
|
context 'with phrases added to HEAD' do
|
data/spec/parse_config_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'tempfile'
|
3
3
|
|
4
|
-
include Txgh
|
5
|
-
|
6
4
|
describe Txgh::ParseConfig do
|
7
5
|
let(:contents) do
|
8
6
|
"""
|
@@ -16,7 +14,7 @@ describe Txgh::ParseConfig do
|
|
16
14
|
|
17
15
|
shared_examples 'a correct config loader' do
|
18
16
|
it 'has correctly parsed the given config' do
|
19
|
-
expect(config).to be_a(
|
17
|
+
expect(config).to be_a(described_class)
|
20
18
|
expect(config.groups).to eq(%w(header header2))
|
21
19
|
expect(config.params).to eq(
|
22
20
|
'header' => { 'key' => 'val' },
|
@@ -27,7 +25,7 @@ describe Txgh::ParseConfig do
|
|
27
25
|
|
28
26
|
describe '.load' do
|
29
27
|
let(:config) do
|
30
|
-
|
28
|
+
described_class.load(contents)
|
31
29
|
end
|
32
30
|
|
33
31
|
it_behaves_like 'a correct config loader'
|
@@ -44,7 +42,7 @@ describe Txgh::ParseConfig do
|
|
44
42
|
end
|
45
43
|
|
46
44
|
let(:config) do
|
47
|
-
|
45
|
+
described_class.load_file(@file.path)
|
48
46
|
end
|
49
47
|
|
50
48
|
it_behaves_like 'a correct config loader'
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'helpers/standard_txgh_setup'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
describe ResourceCommitter do
|
4
|
+
describe Txgh::ResourceCommitter do
|
7
5
|
include StandardTxghSetup
|
8
6
|
|
9
7
|
let(:language) { 'es' }
|
@@ -11,7 +9,7 @@ describe ResourceCommitter do
|
|
11
9
|
let(:downloader) { instance_double(ResourceDownloader) }
|
12
10
|
let(:file_name) { "translations/#{language}/sample.yml" }
|
13
11
|
let(:committer) do
|
14
|
-
|
12
|
+
described_class.new(transifex_project, github_repo, logger)
|
15
13
|
end
|
16
14
|
|
17
15
|
let(:commit_message) do
|
@@ -51,7 +49,7 @@ describe ResourceCommitter do
|
|
51
49
|
|
52
50
|
options = event[:options]
|
53
51
|
expect(options[:project].name).to eq(project_name)
|
54
|
-
expect(options[:repo].name).to eq(
|
52
|
+
expect(options[:repo].name).to eq(github_repo_name)
|
55
53
|
expect(options[:branch]).to eq(branch)
|
56
54
|
expect(options[:resource].original_resource_slug).to eq(resource_slug)
|
57
55
|
expect(options[:language]).to eq(language)
|