Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BRD-1348] Use url encoded branch name for gitlab #76

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
67 changes: 26 additions & 41 deletions docker/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,24 @@ GEM
yaml-write-stream (~> 2.0)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
aws-eventstream (1.0.3)
aws-sdk (2.11.480)
aws-sdk-resources (= 2.11.480)
aws-sdk-core (2.11.480)
aws-eventstream (1.1.0)
aws-sdk (2.11.632)
aws-sdk-resources (= 2.11.632)
aws-sdk-core (2.11.632)
aws-sigv4 (~> 1.0)
jmespath (~> 1.0)
aws-sdk-resources (2.11.480)
aws-sdk-core (= 2.11.480)
aws-sigv4 (1.1.1)
aws-eventstream (~> 1.0, >= 1.0.2)
backports (3.17.0)
celluloid (0.17.4)
celluloid-essentials
celluloid-extras
celluloid-fsm
celluloid-pool
celluloid-supervision
timers (>= 4.1.1)
celluloid-essentials (0.20.5)
timers (>= 4.1.1)
celluloid-extras (0.20.5)
timers (>= 4.1.1)
celluloid-fsm (0.20.5)
timers (>= 4.1.1)
celluloid-pool (0.20.5)
timers (>= 4.1.1)
celluloid-supervision (0.20.6)
timers (>= 4.1.1)
aws-sdk-resources (2.11.632)
aws-sdk-core (= 2.11.632)
aws-sigv4 (1.2.2)
aws-eventstream (~> 1, >= 1.0.2)
backports (3.18.2)
celluloid (0.18.0)
timers (~> 4)
faraday (0.17.3)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.14.0)
faraday (>= 0.7.4, < 1.0)
gitlab (4.14.1)
gitlab (4.16.1)
httparty (~> 0.14, >= 0.14.0)
terminal-table (~> 1.5, >= 1.5.1)
htmlentities (4.3.4)
Expand All @@ -56,16 +41,16 @@ GEM
json_pure (1.8.6)
mime-types (2.99.3)
mini_portile2 (2.4.0)
multi_json (1.14.1)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
nokogiri (1.10.9)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
octokit (4.18.0)
octokit (4.19.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
parseconfig (1.0.8)
public_suffix (4.0.3)
public_suffix (4.0.6)
puma (3.11.4)
rack (1.6.10)
rack-protection (1.5.5)
Expand All @@ -91,8 +76,8 @@ GEM
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
tilt (2.0.10)
timers (4.3.0)
txgh (7.0.1)
timers (4.3.2)
txgh (7.0.2)
abroad (~> 4.6)
celluloid
faraday (= 0.17.3)
Expand All @@ -101,18 +86,18 @@ GEM
json (~> 1.8)
octokit (~> 4.2)
parseconfig (~> 1.0)
txgh-queue (3.0.2)
txgh-queue (3.0.3)
aws-sdk (~> 2.0)
sinatra (~> 1.4)
sinatra-contrib (~> 1.4)
txgh (= 7.0.1)
txgh-server (= 4.0.2)
txgh-server (4.0.2)
txgh (>= 7.0.2)
txgh-server (>= 4.0.3)
txgh-server (4.0.3)
mime-types (~> 2.0)
rubyzip (>= 1.0, <= 1.1.2)
sinatra (~> 1.4)
sinatra-contrib (~> 1.4)
txgh (= 7.0.1)
txgh (>= 7.0.2)
unicode-display_width (1.7.0)
xml-write-stream (1.1.0)
yaml-write-stream (2.0.2)
Expand All @@ -125,9 +110,9 @@ DEPENDENCIES
puma
rack
rake
txgh (= 7.0.1)
txgh-queue (= 3.0.2)
txgh-server (= 4.0.2)
txgh (= 7.0.2)
txgh-queue (= 3.0.3)
txgh-server (= 4.0.3)

BUNDLED WITH
1.17.3
3 changes: 3 additions & 0 deletions txgh/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 7.0.3
* Use url encoded branch name for gitlab.

# 7.0.2
* Don't raise error when cannot update GitLab status.

Expand Down
2 changes: 1 addition & 1 deletion txgh/lib/txgh/git_status.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'celluloid/current'
require 'celluloid'

module Txgh
class GitStatus
Expand Down
6 changes: 3 additions & 3 deletions txgh/lib/txgh/gitlab_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def update_contents(branch, content_list, message)
content_list.each do |file_params|
path = file_params.fetch(:path)
new_contents = file_params.fetch(:contents)
branch = Utils.relative_branch(branch)
branch = Utils.url_safe_relative_branch(branch)

file_sha = file_params.fetch(:sha) do
begin
Expand All @@ -42,13 +42,13 @@ def get_ref(ref)
# mock github response
{
object: {
sha: client.commit(repo_name, ref.gsub('heads/', '')).short_id
sha: client.commit(repo_name, Utils.url_safe_relative_branch(ref)).short_id
}
}
end

def download(path, branch)
file = client.get_file(repo_name, path, branch.gsub('heads/', ''))
file = client.get_file(repo_name, path, Utils.url_safe_relative_branch(branch))

# mock github response
{
Expand Down
4 changes: 4 additions & 0 deletions txgh/lib/txgh/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def relative_branch(branch)
branch.strip.sub(/\A(heads|tags)\//, '')
end

def url_safe_relative_branch(branch)
CGI.escape(relative_branch(branch))
end

def branches_equal?(first, second)
absolute_branch(first) == absolute_branch(second)
end
Expand Down
2 changes: 1 addition & 1 deletion txgh/lib/txgh/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Txgh
VERSION = '7.0.2'
VERSION = '7.0.3.beta1'
end
2 changes: 1 addition & 1 deletion txgh/spec/gitlab_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

let(:status) { described_class.new(transifex_project, gitlab_repo, branch) }
let(:resource) { tx_config.resource(resource_slug) }
let(:branch) { 'heads/master' }
let(:branch) { 'heads/feature/JIRA-task' }
let(:sha) { 'abc123shashasha' }

before(:each) do
Expand Down
14 changes: 14 additions & 0 deletions txgh/spec/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@
end
end

describe '.url_safe_relative_branch' do
it 'removes tags/ if present' do
expect(described_class.url_safe_relative_branch('tags/feature/foobar')).to eq('feature%2Ffoobar')
end

it 'removes heads/ if present' do
expect(described_class.url_safe_relative_branch('heads/foobar')).to eq('foobar')
end

it 'does nothing if no prefix can be removed' do
expect(described_class.url_safe_relative_branch('feature/JIRA-abcdef')).to eq('feature%2FJIRA-abcdef')
end
end

describe '.is_tag?' do
it 'returns true if given a tag' do
expect(described_class.is_tag?('tags/foo')).to eq(true)
Expand Down
2 changes: 1 addition & 1 deletion txgh/txgh.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY

s.add_dependency 'abroad', '~> 4.6'
s.add_dependency 'celluloid'
s.add_dependency 'celluloid', '~> 0.18.0'
s.add_dependency 'faraday', '0.17.3'
s.add_dependency 'faraday_middleware', '0.14.0'
s.add_dependency 'json', '~> 1.8'
Expand Down