txgh 7.0.2 → 7.0.3

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: b38472795e9c8da01e3e429c8ac6f12e1ad2771c867f883f48ff910bedc9c5c8
4
- data.tar.gz: a2c785c97b99e29f5dc2ba57df79684f9a5d041a1ac446308062299bc4217678
3
+ metadata.gz: ab92b0da4510553d29d397e95dead92f3208647cbdf9abd0ebc0741e96d71dd9
4
+ data.tar.gz: 16a8704ab900f0bcbb56cb73b5094a93bfd82df216771d34503e50c1a8a5c25b
5
5
  SHA512:
6
- metadata.gz: 012fea33b411941e4b5f1d436a2255dfa66fe0164d61854dd38aeecc809fbefebeb0ae94e885a45a3af1c8c602cd6eaf3fa87071b8cce2d8c3e7e65cc23130c7
7
- data.tar.gz: 5c75d40e22e7789e358b9f5f3c4897e1838b5b6cc9ff0b6d37467cb8f7a1c4c771532ca5b4ce33f92e093225e2fc8196b556374438e4f8143366c5839e7ceb41
6
+ metadata.gz: ea325774adfa24465f30dce5433c06bfb4fd294fee9015d59ca7c455b8a802c471aca317f7fc7cea89e2952fc003e129f1c0f725d33ff39bf65b0e0c6c81ec26
7
+ data.tar.gz: 711c3fe5993ca817365aa161cae448295508b8946495749aead86ece337d676654562ca77a930e826bebbd0f430e120587e95aee60397bfd933051b07039a53d
@@ -1,4 +1,4 @@
1
- require 'celluloid/current'
1
+ require 'celluloid/autostart'
2
2
 
3
3
  module Txgh
4
4
  class GitStatus
@@ -42,13 +42,13 @@ 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.relative_branch(branch))
52
52
 
53
53
  # mock github response
54
54
  {
@@ -58,7 +58,7 @@ module Txgh
58
58
  end
59
59
 
60
60
  def create_status(sha, state, options = {})
61
- client.update_commit_status(repo_name, sha, state, options)
61
+ client.update_commit_status(repo_name, Utils.url_safe_relative_branch(sha), state, options)
62
62
  rescue ::Gitlab::Error::BadRequest => error
63
63
  # Gitlab pipeline may have several jobs and txgh should not override commit statuses set by others
64
64
  raise error unless error.message.include?('Cannot transition status')
data/lib/txgh/utils.rb CHANGED
@@ -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
data/lib/txgh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Txgh
2
- VERSION = '7.0.2'
2
+ VERSION = '7.0.3'
3
3
  end
@@ -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) { Txgh::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)
26
+ .with(repo, path, filtered_branch)
32
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, filtered_branch, new_contents, 'message')
38
33
  )
39
34
 
40
35
  api.update_contents(branch, [{ path: path, contents: new_contents }], 'message')
@@ -43,7 +38,7 @@ 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)
41
+ .with(repo, path, filtered_branch)
47
42
  .and_return(double(blob_id: old_sha))
48
43
  )
49
44
 
@@ -58,27 +53,18 @@ 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, filtered_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, filtered_branch)
82
68
  .and_return(double(content: 'content', encoding: 'utf-8'))
83
69
  )
84
70
 
@@ -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, filtered_branch)
94
80
  .and_return(double(content: content, encoding: 'utf-16'))
95
81
  )
96
82
 
@@ -102,7 +88,7 @@ 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, filtered_branch)
106
92
  .and_return(double(content: Base64.encode64('content'), encoding: 'base64'))
107
93
  )
108
94
 
@@ -110,6 +96,72 @@ describe Txgh::GitlabApi do
110
96
  end
111
97
  end
112
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(:filtered_branch) { 'master' }
107
+
108
+ it_behaves_like 'an update_contents flow'
109
+ end
110
+
111
+ context 'when feature branch' do
112
+ let(:branch) { 'heads/feature/foo-ticket' }
113
+ let(:filtered_branch) { 'feature/foo-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(:filtered_branch) { 'master' }
153
+
154
+ it_behaves_like 'a download flow'
155
+ end
156
+
157
+ context 'when feature branch' do
158
+ let(:branch) { 'heads/feature/foo-ticket' }
159
+ let(:filtered_branch) { 'feature/foo-ticket' }
160
+
161
+ it_behaves_like 'a download flow'
162
+ end
163
+ end
164
+
113
165
  describe '#create_status' do
114
166
  let(:gitlab_response) do
115
167
  OpenStruct.new({
data/spec/utils_spec.rb CHANGED
@@ -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)
data/txgh.gemspec CHANGED
@@ -13,12 +13,12 @@ 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
- s.add_dependency 'json', '~> 1.8'
19
+ s.add_dependency 'json', '~> 2.3'
20
20
  s.add_dependency 'octokit', '~> 4.2'
21
- s.add_dependency 'gitlab', '~> 4.14'
21
+ s.add_dependency 'gitlab', '~> 4.17'
22
22
  s.add_dependency 'parseconfig', '~> 1.0'
23
23
 
24
24
  s.require_path = 'lib'
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.2
4
+ version: 7.0.3
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-04-01 00:00:00.000000000 Z
12
+ date: 2021-02-11 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
@@ -73,14 +73,14 @@ dependencies:
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '1.8'
76
+ version: '2.3'
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '1.8'
83
+ version: '2.3'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: octokit
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -101,14 +101,14 @@ dependencies:
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '4.14'
104
+ version: '4.17'
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '4.14'
111
+ version: '4.17'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: parseconfig
114
114
  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,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
228
  - !ruby/object:Gem::Version
229
229
  version: '0'
230
230
  requirements: []
231
- rubygems_version: 3.1.2
232
- signing_key:
231
+ rubygems_version: 3.2.7
232
+ signing_key:
233
233
  specification_version: 4
234
234
  summary: A library for syncing translation resources between Github and Transifex.
235
235
  test_files: []