txgh 2.1.0 → 2.2.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/github_api.rb +2 -3
- data/lib/txgh/github_repo.rb +4 -0
- data/lib/txgh/handlers/github/push_handler.rb +15 -1
- data/lib/txgh/resource_committer.rb +14 -1
- data/lib/txgh/version.rb +1 -1
- data/lib/txgh.rb +6 -0
- data/spec/github_api_spec.rb +8 -8
- data/spec/handlers/github/push_handler_spec.rb +19 -1
- data/spec/handlers/transifex/hook_handler_spec.rb +13 -9
- data/spec/helpers/standard_txgh_setup.rb +3 -1
- data/spec/resource_committer_spec.rb +14 -1
- data/spec/txgh_spec.rb +25 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa8e34cc2f842b5e1d9d6998b6ddbf0ce72dfab8
|
4
|
+
data.tar.gz: 8d5dc86a7c315128114d6ff1e25b977ab908ee2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 759259034ab336dcaeae29ecc692bfa45590a9f7bd11392162bb594a067acaf5bd152f6d248c5b27bd2af153950227a722f4364ac3b93db9aeb3e1258cc21a5b
|
7
|
+
data.tar.gz: 198311603b7035fa0129cfb20e288eb5444842fd319a65d88c6bbcfb2b390829ae0819f935b91d177f145846992f1a0031a94cd78b768d48a18229af7f7e5318
|
data/lib/txgh/github_api.rb
CHANGED
@@ -33,7 +33,7 @@ module Txgh
|
|
33
33
|
client.create_ref(repo, branch, sha) rescue false
|
34
34
|
end
|
35
35
|
|
36
|
-
def commit(repo, branch, content_map, allow_empty = false)
|
36
|
+
def commit(repo, branch, content_map, message, allow_empty = false)
|
37
37
|
parent = client.ref(repo, branch)
|
38
38
|
base_commit = get_commit(repo, parent[:object][:sha])
|
39
39
|
|
@@ -46,8 +46,7 @@ module Txgh
|
|
46
46
|
|
47
47
|
tree = client.create_tree(repo, tree_data, tree_options)
|
48
48
|
commit = client.create_commit(
|
49
|
-
repo,
|
50
|
-
tree[:sha], parent[:object][:sha]
|
49
|
+
repo, message, tree[:sha], parent[:object][:sha]
|
51
50
|
)
|
52
51
|
|
53
52
|
# don't update the ref if the commit introduced no new changes
|
data/lib/txgh/github_repo.rb
CHANGED
@@ -10,7 +10,7 @@ module Txgh
|
|
10
10
|
logger.info("request github branch: #{branch}")
|
11
11
|
logger.info("config github branch: #{repo.github_config_branch}")
|
12
12
|
|
13
|
-
if
|
13
|
+
if should_process?
|
14
14
|
logger.info('found branch in github request')
|
15
15
|
|
16
16
|
tx_resources = tx_resources_for(branch)
|
@@ -102,6 +102,20 @@ module Txgh
|
|
102
102
|
@ref ||= payload['ref'].sub(/^refs\//, '')
|
103
103
|
end
|
104
104
|
|
105
|
+
def should_process?
|
106
|
+
should_process_branch? && should_process_commit?
|
107
|
+
end
|
108
|
+
|
109
|
+
def should_process_branch?
|
110
|
+
repo.should_process_ref?(branch)
|
111
|
+
end
|
112
|
+
|
113
|
+
def should_process_commit?
|
114
|
+
# return false if 'after' commit sha is all zeroes (indicates branch
|
115
|
+
# has been deleted)
|
116
|
+
!(payload.fetch('after', '') =~ /\A0+\z/)
|
117
|
+
end
|
118
|
+
|
105
119
|
end
|
106
120
|
end
|
107
121
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Txgh
|
2
2
|
class ResourceCommitter
|
3
|
+
DEFAULT_COMMIT_MESSAGE = "Updating %{language} translations in %{file_name}"
|
4
|
+
|
3
5
|
attr_reader :project, :repo, :logger
|
4
6
|
|
5
7
|
def initialize(project, repo, logger = nil)
|
@@ -13,9 +15,10 @@ module Txgh
|
|
13
15
|
|
14
16
|
unless language == tx_resource.source_lang
|
15
17
|
file_name, translations = download(tx_resource, branch, language)
|
18
|
+
message = commit_message_for(language, file_name)
|
16
19
|
|
17
20
|
if translations
|
18
|
-
repo.api.commit(repo.name, branch, { file_name => translations })
|
21
|
+
repo.api.commit(repo.name, branch, { file_name => translations }, message)
|
19
22
|
fire_event_for(tx_resource, branch, language)
|
20
23
|
end
|
21
24
|
end
|
@@ -45,6 +48,16 @@ module Txgh
|
|
45
48
|
downloader.first
|
46
49
|
end
|
47
50
|
|
51
|
+
def commit_message_for(language, file_name)
|
52
|
+
commit_message_template % {
|
53
|
+
language: language, file_name: file_name
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def commit_message_template
|
58
|
+
repo.commit_message || DEFAULT_COMMIT_MESSAGE
|
59
|
+
end
|
60
|
+
|
48
61
|
def prevent_commit_on?(branch)
|
49
62
|
project.protected_branches.include?(branch)
|
50
63
|
end
|
data/lib/txgh/version.rb
CHANGED
data/lib/txgh.rb
CHANGED
@@ -30,6 +30,8 @@ module Txgh
|
|
30
30
|
autoload :TxResource, 'txgh/tx_resource'
|
31
31
|
autoload :Utils, 'txgh/utils'
|
32
32
|
|
33
|
+
DEFAULT_ENV = 'development'
|
34
|
+
|
33
35
|
class << self
|
34
36
|
def tx_manager
|
35
37
|
Txgh::Config::TxManager
|
@@ -54,6 +56,10 @@ module Txgh
|
|
54
56
|
|
55
57
|
GithubStatus.new(project, repo, resource).update(options.fetch(:sha))
|
56
58
|
end
|
59
|
+
|
60
|
+
def env
|
61
|
+
ENV.fetch('TXGH_ENV', DEFAULT_ENV)
|
62
|
+
end
|
57
63
|
end
|
58
64
|
|
59
65
|
# default set of tx config providers
|
data/spec/github_api_spec.rb
CHANGED
@@ -49,12 +49,12 @@ describe GithubApi do
|
|
49
49
|
it 'creates a new commit and updates the branch' do
|
50
50
|
expect(client).to(
|
51
51
|
receive(:create_commit)
|
52
|
-
.with(repo,
|
52
|
+
.with(repo, 'message', :new_tree_sha, :branch_sha)
|
53
53
|
.and_return(sha: :new_commit_sha)
|
54
54
|
)
|
55
55
|
|
56
56
|
expect(client).to receive(:update_ref).with(repo, branch, :new_commit_sha, false)
|
57
|
-
api.commit(repo, branch, { path => :new_content }, true)
|
57
|
+
api.commit(repo, branch, { path => :new_content }, 'message', true)
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'updates multiple files at a time' do
|
@@ -62,13 +62,13 @@ describe GithubApi do
|
|
62
62
|
|
63
63
|
expect(client).to(
|
64
64
|
receive(:create_commit)
|
65
|
-
.with(repo,
|
65
|
+
.with(repo, 'message', :new_tree_sha, :branch_sha)
|
66
66
|
.and_return(sha: :new_commit_sha)
|
67
67
|
)
|
68
68
|
|
69
69
|
expect(client).to receive(:update_ref).with(repo, branch, :new_commit_sha, false)
|
70
70
|
content_map = { path => :new_content, other_path => :other_content }
|
71
|
-
api.commit(repo, branch, content_map, true)
|
71
|
+
api.commit(repo, branch, content_map, 'message', true)
|
72
72
|
end
|
73
73
|
|
74
74
|
context 'with an empty commit' do
|
@@ -81,14 +81,14 @@ describe GithubApi do
|
|
81
81
|
|
82
82
|
expect(client).to(
|
83
83
|
receive(:create_commit)
|
84
|
-
.with(repo,
|
84
|
+
.with(repo, 'message', :new_tree_sha, :branch_sha)
|
85
85
|
.and_return(sha: :new_commit_sha)
|
86
86
|
)
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'does not allow empty commits by default' do
|
90
90
|
expect(client).to_not receive(:update_ref)
|
91
|
-
api.commit(repo, branch, { path => :new_content })
|
91
|
+
api.commit(repo, branch, { path => :new_content }, 'message')
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -102,14 +102,14 @@ describe GithubApi do
|
|
102
102
|
|
103
103
|
expect(client).to(
|
104
104
|
receive(:create_commit)
|
105
|
-
.with(repo,
|
105
|
+
.with(repo, 'message', :new_tree_sha, :branch_sha)
|
106
106
|
.and_return(sha: :new_commit_sha)
|
107
107
|
)
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'updates the ref as expected' do
|
111
111
|
expect(client).to receive(:update_ref).with(repo, branch, :new_commit_sha, false)
|
112
|
-
api.commit(repo, branch, { path => :new_content })
|
112
|
+
api.commit(repo, branch, { path => :new_content }, 'message')
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
@@ -35,7 +35,7 @@ describe PushHandler do
|
|
35
35
|
modified: modified_files.map { |f| f['path'] }
|
36
36
|
)
|
37
37
|
|
38
|
-
|
38
|
+
allow(ResourceUpdater).to receive(:new).and_return(updater)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'correctly uploads modified resources to transifex' do
|
@@ -73,4 +73,22 @@ describe PushHandler do
|
|
73
73
|
expect(response.body).to eq(true)
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
context 'with a deleted branch' do
|
78
|
+
let(:before) { nil }
|
79
|
+
let(:after) { '0' * 40 }
|
80
|
+
|
81
|
+
let(:payload) do
|
82
|
+
GithubPayloadBuilder.push_payload(repo_name, ref, before, after)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "doesn't upload anything" do
|
86
|
+
expect(updater).to_not receive(:update_resource)
|
87
|
+
expect(github_api).to_not receive(:create_ref)
|
88
|
+
|
89
|
+
response = handler.execute
|
90
|
+
expect(response.status).to eq(200)
|
91
|
+
expect(response.body).to eq(true)
|
92
|
+
end
|
93
|
+
end
|
76
94
|
end
|
@@ -26,6 +26,10 @@ describe HookHandler do
|
|
26
26
|
instance_double(ResourceDownloader)
|
27
27
|
end
|
28
28
|
|
29
|
+
let(:file_name) do
|
30
|
+
"translations/#{language}/sample.yml"
|
31
|
+
end
|
32
|
+
|
29
33
|
before(:each) do
|
30
34
|
allow(ResourceDownloader).to receive(:new).and_return(downloader)
|
31
35
|
allow(downloader).to(receive(:first)).and_return([
|
@@ -40,9 +44,9 @@ describe HookHandler do
|
|
40
44
|
it 'downloads translations and pushes them to the correct branch (head)' do
|
41
45
|
expect(github_api).to(
|
42
46
|
receive(:commit).with(
|
43
|
-
repo_name, "heads/#{branch}",
|
44
|
-
|
45
|
-
}
|
47
|
+
repo_name, "heads/#{branch}",
|
48
|
+
{ "translations/#{language}/sample.yml" => translations },
|
49
|
+
"Updating #{language} translations in #{file_name}"
|
46
50
|
)
|
47
51
|
)
|
48
52
|
|
@@ -87,9 +91,9 @@ describe HookHandler do
|
|
87
91
|
|
88
92
|
expect(github_api).to(
|
89
93
|
receive(:commit).with(
|
90
|
-
repo_name, ref,
|
91
|
-
|
92
|
-
}
|
94
|
+
repo_name, ref,
|
95
|
+
{ "translations/#{language}/sample.yml" => translations },
|
96
|
+
"Updating #{language} translations in #{file_name}"
|
93
97
|
)
|
94
98
|
)
|
95
99
|
|
@@ -105,9 +109,9 @@ describe HookHandler do
|
|
105
109
|
it 'downloads translations and pushes them to the tag' do
|
106
110
|
expect(github_api).to(
|
107
111
|
receive(:commit).with(
|
108
|
-
repo_name, "tags/my_tag",
|
109
|
-
|
110
|
-
}
|
112
|
+
repo_name, "tags/my_tag",
|
113
|
+
{ "translations/#{language}/sample.yml" => translations },
|
114
|
+
"Updating #{language} translations in #{file_name}"
|
111
115
|
)
|
112
116
|
)
|
113
117
|
|
@@ -19,6 +19,7 @@ module StandardTxghSetup
|
|
19
19
|
let(:translations) { 'translation file contents' }
|
20
20
|
let(:diff_point) { nil }
|
21
21
|
let(:organization) { 'myorg' }
|
22
|
+
let(:commit_message_template) { nil } # i.e. use the default
|
22
23
|
|
23
24
|
let(:project_config) do
|
24
25
|
{
|
@@ -43,7 +44,8 @@ module StandardTxghSetup
|
|
43
44
|
'tag' => tag,
|
44
45
|
'name' => repo_name,
|
45
46
|
'webhook_secret' => 'abc123',
|
46
|
-
'diff_point' => diff_point
|
47
|
+
'diff_point' => diff_point,
|
48
|
+
'commit_message' => commit_message_template
|
47
49
|
}
|
48
50
|
end
|
49
51
|
|
@@ -14,6 +14,10 @@ describe ResourceCommitter do
|
|
14
14
|
ResourceCommitter.new(transifex_project, github_repo, logger)
|
15
15
|
end
|
16
16
|
|
17
|
+
let(:commit_message) do
|
18
|
+
"Updating #{language} translations in #{file_name}"
|
19
|
+
end
|
20
|
+
|
17
21
|
before(:each) do
|
18
22
|
allow(github_api).to receive(:get_ref).and_return(
|
19
23
|
object: { sha: 'abc123shashasha' }
|
@@ -28,7 +32,7 @@ describe ResourceCommitter do
|
|
28
32
|
|
29
33
|
expect(github_api).to(
|
30
34
|
receive(:commit).with(
|
31
|
-
repo_name, branch, { file_name => :translations }
|
35
|
+
repo_name, branch, { file_name => :translations }, commit_message
|
32
36
|
)
|
33
37
|
)
|
34
38
|
end
|
@@ -52,6 +56,15 @@ describe ResourceCommitter do
|
|
52
56
|
expect(options[:resource].original_resource_slug).to eq(resource_slug)
|
53
57
|
expect(options[:language]).to eq(language)
|
54
58
|
end
|
59
|
+
|
60
|
+
context 'with a custom commit message' do
|
61
|
+
let(:commit_message_template) { "foo %{language}" }
|
62
|
+
let(:commit_message) { "foo #{language}" }
|
63
|
+
|
64
|
+
it 'uses the custom commit message' do
|
65
|
+
committer.commit_resource(resource, branch, language)
|
66
|
+
end
|
67
|
+
end
|
55
68
|
end
|
56
69
|
|
57
70
|
it "doesn't commit anything if the language is the source language" do
|
data/spec/txgh_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Txgh do
|
4
|
+
def with_env(env)
|
5
|
+
# ENV can't be duped, so use select instead to make a copy
|
6
|
+
old_env = ENV.select { true }
|
7
|
+
env.each_pair { |k, v| ENV[k] = v }
|
8
|
+
yield
|
9
|
+
ensure
|
10
|
+
# reset back to old vars
|
11
|
+
env.each_pair { |k, _| ENV[k] = old_env[k] }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#env' do
|
15
|
+
it 'defaults to development' do
|
16
|
+
expect(Txgh.env).to eq('development')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'pulls the env out of ENV if set' do
|
20
|
+
with_env('TXGH_ENV' => 'production') do
|
21
|
+
expect(Txgh.env).to eq('production')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
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: 2.
|
4
|
+
version: 2.2.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-
|
12
|
+
date: 2016-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: abroad
|
@@ -274,6 +274,7 @@ files:
|
|
274
274
|
- spec/transifex_request_auth_spec.rb
|
275
275
|
- spec/tx_branch_resource_spec.rb
|
276
276
|
- spec/tx_resource_spec.rb
|
277
|
+
- spec/txgh_spec.rb
|
277
278
|
- spec/utils_spec.rb
|
278
279
|
- txgh.gemspec
|
279
280
|
homepage: https://github.com/lumoslabs/txgh
|