txgh 7.0.0.beta4 → 7.0.3.beta1

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
  SHA256:
3
- metadata.gz: 115f8465e3521a85f6ebb9fb137410cdef753203d30dca1343bc00261d832db9
4
- data.tar.gz: d3b5774e8a1d1699e7dd47b5537d74075004b3b2def59f8457c259ad518d8c7a
3
+ metadata.gz: c3a11b6e9eb48bcfe3241f743860dbb03ca79feabcc1fdd71003b0d63c5422e3
4
+ data.tar.gz: e242240afb44fcfaf2e02126a49e1289375ad70a2c86bdc3a90a4a1863c3e318
5
5
  SHA512:
6
- metadata.gz: 566fe97c0391c74fc21924b101f34727956bd3cc1a49c31f47b8a8c30d2a86876c9f3997ce8e8daa89584e2971bed0211843c3120e5f783293996cedaae3add9
7
- data.tar.gz: 9986dfc7e5875e0c1b0ae8534d71ba02d86f2c2b2ad995930ebb52fe92bfe723a2e0a99ea9a61b7b813dca627e94ce4002e85940b2e97065bbf917bc477b9f16
6
+ metadata.gz: bfb8768d65b42a633ae33941535267b6efac5efad04088768d53202ffb1b6d8cce2d00a5652639073e07a3768e30a85c96fb4aa4e3ee1db1a0205bc429f1919d
7
+ data.tar.gz: 1894bfaab37dea410cc31b6994e8d1a5ebeb1f0a1944db50d1990fe54d0fa8bd9c32cffe3470983912d3572bae0ca8bbb09f96f4a416b8128987842102819b7c
@@ -33,14 +33,10 @@ module Txgh
33
33
 
34
34
  private
35
35
 
36
- def download
37
- raise NotImplementedError
38
- end
39
-
40
36
  def ref
41
37
  unless @ref
42
38
  raise TxghError,
43
- "TX_CONFIG specified a file from git but did not provide a ref."
39
+ 'TX_CONFIG specified a file from git but did not provide a ref.'
44
40
  end
45
41
 
46
42
  @ref
@@ -49,7 +45,7 @@ module Txgh
49
45
  def git_repo
50
46
  unless @git_repo
51
47
  raise TxghError,
52
- "TX_CONFIG specified a file from git but did not provide a repo."
48
+ 'TX_CONFIG specified a file from git but did not provide a repo.'
53
49
  end
54
50
 
55
51
  @git_repo
@@ -1,3 +1,5 @@
1
+ require 'octokit'
2
+
1
3
  module Txgh
2
4
  module Config
3
5
  module Providers
@@ -1,3 +1,5 @@
1
+ require 'gitlab'
2
+
1
3
  module Txgh
2
4
  module Config
3
5
  module Providers
@@ -14,72 +14,5 @@ module Txgh
14
14
  @client = client
15
15
  @repo_name = repo_name
16
16
  end
17
-
18
- def tree(sha)
19
- client.tree(repo_name, sha, recursive: 1)
20
- end
21
-
22
- def blob(sha)
23
- client.blob(repo_name, sha)
24
- end
25
-
26
- def create_ref(branch, sha)
27
- client.create_ref(repo_name, branch, sha) rescue false
28
- end
29
-
30
- def update_contents(branch, content_list, message)
31
- content_list.each do |file_params|
32
- path = file_params.fetch(:path)
33
- new_contents = file_params.fetch(:contents)
34
- branch = Utils.relative_branch(branch)
35
-
36
- file_sha = file_params.fetch(:sha) do
37
- begin
38
- client.contents(repo_name, { path: path, ref: branch })[:sha]
39
- rescue Octokit::NotFound
40
- nil
41
- end
42
- end
43
-
44
- # If the file doesnt exist, then it isn't tracked by git and file_sha
45
- # will be nil. In git land, a SHA of all zeroes means create a new file
46
- # instead of updating an existing one.
47
- current_sha = file_sha || '0' * 40
48
- new_sha = Utils.git_hash_blob(new_contents)
49
- options = { branch: branch }
50
-
51
- if current_sha != new_sha
52
- client.update_contents(
53
- repo_name, path, message, current_sha, new_contents, options
54
- )
55
- end
56
- end
57
- end
58
-
59
- def get_commit(sha)
60
- client.commit(repo_name, sha)
61
- end
62
-
63
- def get_ref(ref)
64
- client.ref(repo_name, ref)
65
- end
66
-
67
- def download(path, branch)
68
- file = client.contents(repo_name, { path: path, ref: branch }).to_h
69
-
70
- file[:content] = case file[:encoding]
71
- when 'base64'
72
- Base64.decode64(file[:content])
73
- else
74
- file[:content].force_encoding(file[:encoding])
75
- end
76
-
77
- file.delete(:encoding)
78
- file
79
- end
80
-
81
- def create_status(sha, state, options = {})
82
- client.create_status(repo_name, sha, state, options)
83
- end
84
17
  end
85
18
  end
@@ -1,4 +1,4 @@
1
- require 'celluloid/current'
1
+ require 'celluloid/autostart'
2
2
 
3
3
  module Txgh
4
4
  class GitStatus
@@ -16,11 +16,11 @@ module Txgh
16
16
  content_list.each do |file_params|
17
17
  path = file_params.fetch(:path)
18
18
  new_contents = file_params.fetch(:contents)
19
- branch = Utils.relative_branch(branch)
19
+ branch = Utils.url_safe_relative_branch(branch)
20
20
 
21
21
  file_sha = file_params.fetch(:sha) do
22
22
  begin
23
- client.get_file(repo_name, path, branch).content_sha256
23
+ client.get_file(repo_name, path, branch).blob_id
24
24
  rescue ::Gitlab::Error::NotFound
25
25
  nil
26
26
  end
@@ -42,22 +42,26 @@ module Txgh
42
42
  # mock github response
43
43
  {
44
44
  object: {
45
- sha: client.commit(repo_name, ref.gsub('heads/', '')).short_id
45
+ sha: client.commit(repo_name, Utils.url_safe_relative_branch(ref)).short_id
46
46
  }
47
47
  }
48
48
  end
49
49
 
50
50
  def download(path, branch)
51
- file = client.get_file(repo_name, path, branch.gsub('heads/', ''))
51
+ file = client.get_file(repo_name, path, Utils.url_safe_relative_branch(branch))
52
52
 
53
53
  # mock github response
54
54
  {
55
- content: file.encoding == 'base64' ? Base64.decode64(file.content) : file.content.force_encoding(file.encoding)
55
+ content: file.encoding == 'base64' ? Base64.decode64(file.content) : file.content.force_encoding(file.encoding),
56
+ path: path
56
57
  }
57
58
  end
58
59
 
59
60
  def create_status(sha, state, options = {})
60
61
  client.update_commit_status(repo_name, sha, state, options)
62
+ rescue ::Gitlab::Error::BadRequest => error
63
+ # Gitlab pipeline may have several jobs and txgh should not override commit statuses set by others
64
+ raise error unless error.message.include?('Cannot transition status')
61
65
  end
62
66
  end
63
67
  end
@@ -24,6 +24,10 @@ module Txgh
24
24
  branch.strip.sub(/\A(heads|tags)\//, '')
25
25
  end
26
26
 
27
+ def url_safe_relative_branch(branch)
28
+ CGI.escape(relative_branch(branch))
29
+ end
30
+
27
31
  def branches_equal?(first, second)
28
32
  absolute_branch(first) == absolute_branch(second)
29
33
  end
@@ -1,3 +1,3 @@
1
1
  module Txgh
2
- VERSION = '7.0.0.beta4'
2
+ VERSION = '7.0.3.beta1'
3
3
  end
@@ -37,7 +37,7 @@ describe Txgh::GithubApi do
37
37
  describe '#update_contents' do
38
38
  let(:path) { 'path/to/file.txt' }
39
39
  let(:old_contents) { 'abc123' }
40
- let(:old_sha) { Utils.git_hash_blob(old_contents) }
40
+ let(:old_sha) { Txgh::Utils.git_hash_blob(old_contents) }
41
41
 
42
42
  it 'updates the given file contents' do
43
43
  new_contents = 'def456'
@@ -5,7 +5,6 @@ describe Txgh::GitlabApi do
5
5
  let(:client) { double(:client) }
6
6
  let(:api) { described_class.create_from_client(client, repo) }
7
7
  let(:repo) { 'my_org/my_repo' }
8
- let(:branch) { 'master' }
9
8
  let(:sha) { 'abc123' }
10
9
  let(:gitlab_response) do
11
10
  OpenStruct.new({
@@ -18,23 +17,19 @@ describe Txgh::GitlabApi do
18
17
  })
19
18
  end
20
19
 
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
-
20
+ shared_examples 'an update_contents flow' do
26
21
  it 'updates the given file contents' do
27
22
  new_contents = 'def456'
28
23
 
29
24
  expect(client).to(
30
25
  receive(:get_file)
31
- .with(repo, path, branch)
32
- .and_return(double(content_sha256: old_sha))
26
+ .with(repo, path, url_safe_branch)
27
+ .and_return(double(blob_id: old_sha))
33
28
  )
34
29
 
35
30
  expect(client).to(
36
31
  receive(:edit_file)
37
- .with(repo, path, branch, new_contents, 'message')
32
+ .with(repo, path, url_safe_branch, new_contents, 'message')
38
33
  )
39
34
 
40
35
  api.update_contents(branch, [{ path: path, contents: new_contents }], 'message')
@@ -43,8 +38,8 @@ describe Txgh::GitlabApi do
43
38
  it "doesn't update the file contents if the file hasn't changed" do
44
39
  expect(client).to(
45
40
  receive(:get_file)
46
- .with(repo, path, branch)
47
- .and_return(double(content_sha256: old_sha))
41
+ .with(repo, path, url_safe_branch)
42
+ .and_return(double(blob_id: old_sha))
48
43
  )
49
44
 
50
45
  expect(client).to_not receive(:edit_file)
@@ -58,31 +53,22 @@ describe Txgh::GitlabApi do
58
53
 
59
54
  expect(client).to(
60
55
  receive(:edit_file)
61
- .with(repo, path, branch, new_contents, 'message')
56
+ .with(repo, path, url_safe_branch, new_contents, 'message')
62
57
  )
63
58
 
64
59
  api.update_contents(branch, [{ path: path, contents: new_contents }], 'message')
65
60
  end
66
61
  end
67
62
 
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
-
63
+ shared_examples 'a download flow' do
78
64
  it 'downloads the file from the given branch' do
79
65
  expect(client).to(
80
66
  receive(:get_file)
81
- .with(repo, path, branch)
67
+ .with(repo, path, url_safe_branch)
82
68
  .and_return(double(content: 'content', encoding: 'utf-8'))
83
69
  )
84
70
 
85
- expect(api.download(path, branch)).to eq({ content: 'content' })
71
+ expect(api.download(path, branch)).to eq({ content: 'content', path: path })
86
72
  end
87
73
 
88
74
  it 'encodes the string using the encoding specified in the response' do
@@ -90,7 +76,7 @@ describe Txgh::GitlabApi do
90
76
 
91
77
  expect(client).to(
92
78
  receive(:get_file)
93
- .with(repo, path, branch)
79
+ .with(repo, path, url_safe_branch)
94
80
  .and_return(double(content: content, encoding: 'utf-16'))
95
81
  )
96
82
 
@@ -102,11 +88,96 @@ describe Txgh::GitlabApi do
102
88
  it 'automatically decodes base64-encoded content' do
103
89
  expect(client).to(
104
90
  receive(:get_file)
105
- .with(repo, path, branch)
91
+ .with(repo, path, url_safe_branch)
106
92
  .and_return(double(content: Base64.encode64('content'), encoding: 'base64'))
107
93
  )
108
94
 
109
- expect(api.download(path, branch)).to eq({ content: 'content' })
95
+ expect(api.download(path, branch)).to eq({ content: 'content', path: path })
96
+ end
97
+ end
98
+
99
+ describe '#update_contents' do
100
+ let(:path) { 'path/to/file.txt' }
101
+ let(:old_contents) { 'abc123' }
102
+ let(:old_sha) { Txgh::Utils.git_hash_blob(old_contents) }
103
+
104
+ context 'when master branch' do
105
+ let(:branch) { 'master' }
106
+ let(:url_safe_branch) { 'master' }
107
+
108
+ it_behaves_like 'an update_contents flow'
109
+ end
110
+
111
+ context 'when feature branch' do
112
+ let(:branch) { 'feature/foo-ticket' }
113
+ let(:url_safe_branch) { 'feature%2Ffoo-ticket' }
114
+
115
+ it_behaves_like 'an update_contents flow'
116
+ end
117
+ end
118
+
119
+ describe '#get_ref' do
120
+ context 'when ref is a sha' do
121
+ it 'retrieves the given ref (i.e. branch) using the client' do
122
+ expect(client).to receive(:commit).with(repo, sha) { double(short_id: '0') }
123
+ api.get_ref(sha)
124
+ end
125
+ end
126
+
127
+ context 'when ref is a master branch' do
128
+ let(:sha) { 'master' }
129
+
130
+ it 'retrieves the given ref (i.e. branch) using the client' do
131
+ expect(client).to receive(:commit).with(repo, sha) { double(short_id: '0') }
132
+ api.get_ref(sha)
133
+ end
134
+ end
135
+
136
+ context 'when ref is a feature branch' do
137
+ let(:sha) { 'feature/foo-ticket' }
138
+ let(:url_safe_sha) { 'feature%2Ffoo-ticket' }
139
+
140
+ it 'retrieves the given ref (i.e. branch) using the client' do
141
+ expect(client).to receive(:commit).with(repo, url_safe_sha) { double(short_id: '0') }
142
+ api.get_ref(sha)
143
+ end
144
+ end
145
+ end
146
+
147
+ describe '#download' do
148
+ let(:path) { 'path/to/file.xyz' }
149
+
150
+ context 'when master branch' do
151
+ let(:branch) { 'master' }
152
+ let(:url_safe_branch) { 'master' }
153
+
154
+ it_behaves_like 'a download flow'
155
+ end
156
+
157
+ context 'when feature branch' do
158
+ let(:branch) { 'feature/foo-ticket' }
159
+ let(:url_safe_branch) { 'feature%2Ffoo-ticket' }
160
+
161
+ it_behaves_like 'a download flow'
162
+ end
163
+ end
164
+
165
+ describe '#create_status' do
166
+ let(:gitlab_response) do
167
+ OpenStruct.new({
168
+ code: 404,
169
+ request: double(base_uri: 'https://gitlab.com/api/v3', path: '/foo'),
170
+ parsed_response: Gitlab::ObjectifiedHash.new(
171
+ error_description: 'Cannot transition status via :enqueue from :pending',
172
+ error: 'also will not be displayed'
173
+ )
174
+ })
175
+ end
176
+
177
+ it 'does not raise error if cannot change status' do
178
+ expect(client).to receive(:update_commit_status).and_raise(::Gitlab::Error::BadRequest.new(gitlab_response))
179
+
180
+ api.create_status('sha', 'state', {})
110
181
  end
111
182
  end
112
183
  end
@@ -47,6 +47,20 @@ describe Txgh::Utils do
47
47
  end
48
48
  end
49
49
 
50
+ describe '.url_safe_relative_branch' do
51
+ it 'removes tags/ if present' do
52
+ expect(described_class.url_safe_relative_branch('tags/feature/foobar')).to eq('feature%2Ffoobar')
53
+ end
54
+
55
+ it 'removes heads/ if present' do
56
+ expect(described_class.url_safe_relative_branch('heads/foobar')).to eq('foobar')
57
+ end
58
+
59
+ it 'does nothing if no prefix can be removed' do
60
+ expect(described_class.url_safe_relative_branch('feature/foo-ticket')).to eq('feature%2Ffoo-ticket')
61
+ end
62
+ end
63
+
50
64
  describe '.is_tag?' do
51
65
  it 'returns true if given a tag' do
52
66
  expect(described_class.is_tag?('tags/foo')).to eq(true)
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.platform = Gem::Platform::RUBY
14
14
 
15
15
  s.add_dependency 'abroad', '~> 4.6'
16
- s.add_dependency 'celluloid'
16
+ s.add_dependency 'celluloid', '~> 0.18.0'
17
17
  s.add_dependency 'faraday', '0.17.3'
18
18
  s.add_dependency 'faraday_middleware', '0.14.0'
19
19
  s.add_dependency 'json', '~> 1.8'
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: txgh
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0.beta4
4
+ version: 7.0.3.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Jackowski
8
8
  - Cameron Dutro
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-03-26 00:00:00.000000000 Z
12
+ date: 2020-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: abroad
@@ -29,16 +29,16 @@ dependencies:
29
29
  name: celluloid
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: 0.18.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '0'
41
+ version: 0.18.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: faraday
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -213,7 +213,7 @@ files:
213
213
  homepage: https://github.com/lumoslabs/txgh
214
214
  licenses: []
215
215
  metadata: {}
216
- post_install_message:
216
+ post_install_message:
217
217
  rdoc_options: []
218
218
  require_paths:
219
219
  - lib
@@ -228,8 +228,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
228
  - !ruby/object:Gem::Version
229
229
  version: 1.3.1
230
230
  requirements: []
231
- rubygems_version: 3.0.6
232
- signing_key:
231
+ rubyforge_project:
232
+ rubygems_version: 2.7.6
233
+ signing_key:
233
234
  specification_version: 4
234
235
  summary: A library for syncing translation resources between Github and Transifex.
235
236
  test_files: []