diff options
author | Hordur Freyr Yngvason <hfyngvason@gitlab.com> | 2019-08-15 11:53:36 +0000 |
---|---|---|
committer | Hordur Freyr Yngvason <hfyngvason@gitlab.com> | 2019-08-15 11:53:36 +0000 |
commit | ace7cdeda0846794b9e40477320f446a28d94f53 (patch) | |
tree | eacab9dc0ea2196eaf8dba34a8e6edaf401bc049 | |
parent | c4a72bd280c5886bf890a801abb1890fc4af1e6c (diff) | |
download | gitlab-ce-squash-project-templates-on-update.tar.gz |
Split out two methods and add commentssquash-project-templates-on-update
-rw-r--r-- | lib/gitlab/project_template.rb | 8 | ||||
-rw-r--r-- | lib/tasks/gitlab/update_templates.rake | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/project_template_spec.rb | 12 | ||||
-rw-r--r-- | spec/tasks/gitlab/update_templates_rake_spec.rb | 3 |
4 files changed, 26 insertions, 2 deletions
diff --git a/lib/gitlab/project_template.rb b/lib/gitlab/project_template.rb index dbf469a44c1..fa1d1203842 100644 --- a/lib/gitlab/project_template.rb +++ b/lib/gitlab/project_template.rb @@ -24,6 +24,14 @@ module Gitlab "#{preview}.git" end + def project_path + URI.parse(preview).path.sub(%r{\A/}, '') + end + + def uri_encoded_project_path + ERB::Util.url_encode(project_path) + end + def ==(other) name == other.name && title == other.title end diff --git a/lib/tasks/gitlab/update_templates.rake b/lib/tasks/gitlab/update_templates.rake index 63c4fd0833a..fdcd34320b1 100644 --- a/lib/tasks/gitlab/update_templates.rake +++ b/lib/tasks/gitlab/update_templates.rake @@ -52,8 +52,7 @@ namespace :gitlab do raise "Failed to create project: #{project.errors.messages}" end - project_path = URI.parse(template.preview).path[1..-1] # strip leading slash - uri_encoded_project_path = project_path.gsub('/', '%2F') + uri_encoded_project_path = template.uri_encoded_project_path # extract a concrete commit for signing off what we actually downloaded # this way we do the right thing even if the repository gets updated in the meantime @@ -81,6 +80,8 @@ namespace :gitlab do Gitlab::TaskHelpers.run_command!(%w(git init)) Gitlab::TaskHelpers.run_command!(%w(git add .)) Gitlab::TaskHelpers.run_command!(['git', 'commit', '--author', 'GitLab <root@localhost>', '--message', commit_message]) + + # Hacky workaround to push to the project in a way that works with both GDK and the test environment Gitlab::GitalyClient::StorageSettings.allow_disk_access do Gitlab::TaskHelpers.run_command!(['git', 'remote', 'add', 'origin', "file://#{project.repository.raw.path}"]) end diff --git a/spec/lib/gitlab/project_template_spec.rb b/spec/lib/gitlab/project_template_spec.rb index 8b82ea7faa5..c7c82d07508 100644 --- a/spec/lib/gitlab/project_template_spec.rb +++ b/spec/lib/gitlab/project_template_spec.rb @@ -28,6 +28,18 @@ describe Gitlab::ProjectTemplate do end end + describe '#project_path' do + subject { described_class.new('name', 'title', 'description', 'https://gitlab.com/some/project/path').project_path } + + it { is_expected.to eq 'some/project/path' } + end + + describe '#uri_encoded_project_path' do + subject { described_class.new('name', 'title', 'description', 'https://gitlab.com/some/project/path').uri_encoded_project_path } + + it { is_expected.to eq 'some%2Fproject%2Fpath' } + end + describe '.find' do subject { described_class.find(query) } diff --git a/spec/tasks/gitlab/update_templates_rake_spec.rb b/spec/tasks/gitlab/update_templates_rake_spec.rb index f0b5db57142..14b4ad5e3d8 100644 --- a/spec/tasks/gitlab/update_templates_rake_spec.rb +++ b/spec/tasks/gitlab/update_templates_rake_spec.rb @@ -8,9 +8,12 @@ describe 'gitlab:update_project_templates rake task' do before do Rake.application.rake_require 'tasks/gitlab/update_templates' create(:admin) + allow(Gitlab::ProjectTemplate) .to receive(:archive_directory) .and_return(Pathname.new(tmpdir)) + + # Gitlab::HTTP resolves the domain to an IP prior to WebMock taking effect, hence the wildcard stub_request(:get, %r{^https://.*/api/v4/projects/gitlab-org%2Fproject-templates%2Frails/repository/commits\?page=1&per_page=1}) .to_return( status: 200, |