Commit a7954564 authored by Phil Hughes's avatar Phil Hughes

Created a constant for archive formats

Closes https://gitlab.com/gitlab-org/gitlab/issues/35231
parent 14227cac
...@@ -197,9 +197,7 @@ module TreeHelper ...@@ -197,9 +197,7 @@ module TreeHelper
end end
def directory_download_links(project, ref, archive_prefix) def directory_download_links(project, ref, archive_prefix)
formats = ['zip', 'tar.gz', 'tar.bz2', 'tar'] Gitlab::Workhorse::ARCHIVE_FORMATS.map do |fmt|
formats.map do |fmt|
{ {
text: fmt, text: fmt,
path: project_archive_path(project, id: tree_join(ref, archive_prefix), format: fmt) path: project_archive_path(project, id: tree_join(ref, archive_prefix), format: fmt)
......
...@@ -6,11 +6,9 @@ module Releases ...@@ -6,11 +6,9 @@ module Releases
attr_accessor :project, :tag_name, :format attr_accessor :project, :tag_name, :format
FORMATS = %w(zip tar.gz tar.bz2 tar).freeze
class << self class << self
def all(project, tag_name) def all(project, tag_name)
Releases::Source::FORMATS.map do |format| Gitlab::Workhorse::ARCHIVE_FORMATS.map do |format|
Releases::Source.new(project: project, Releases::Source.new(project: project,
tag_name: tag_name, tag_name: tag_name,
format: format) format: format)
......
- formats = [['zip', 'btn-primary'], ['tar.gz'], ['tar.bz2'], ['tar']]
.btn-group.ml-0.w-100 .btn-group.ml-0.w-100
- formats.each do |(fmt, extra_class)| - Gitlab::Workhorse::ARCHIVE_FORMATS.each_with_index do |fmt, index|
- archive_path = project_archive_path(project, id: tree_join(ref, archive_prefix), path: path, format: fmt) - archive_path = project_archive_path(project, id: tree_join(ref, archive_prefix), path: path, format: fmt)
= link_to fmt, external_storage_url_or_path(archive_path), rel: 'nofollow', download: '', class: "btn btn-xs #{extra_class}" = link_to fmt, external_storage_url_or_path(archive_path), rel: 'nofollow', download: '', class: "btn btn-xs #{"btn-primary" if index == 0}"
...@@ -14,6 +14,7 @@ module Gitlab ...@@ -14,6 +14,7 @@ module Gitlab
NOTIFICATION_CHANNEL = 'workhorse:notifications' NOTIFICATION_CHANNEL = 'workhorse:notifications'
ALLOWED_GIT_HTTP_ACTIONS = %w[git_receive_pack git_upload_pack info_refs].freeze ALLOWED_GIT_HTTP_ACTIONS = %w[git_receive_pack git_upload_pack info_refs].freeze
DETECT_HEADER = 'Gitlab-Workhorse-Detect-Content-Type' DETECT_HEADER = 'Gitlab-Workhorse-Detect-Content-Type'
ARCHIVE_FORMATS = %w(zip tar.gz tar.bz2 tar).freeze
include JwtAuthenticatable include JwtAuthenticatable
......
...@@ -57,14 +57,14 @@ RSpec.describe Release do ...@@ -57,14 +57,14 @@ RSpec.describe Release do
subject { release.assets_count } subject { release.assets_count }
it 'returns the number of sources' do it 'returns the number of sources' do
is_expected.to eq(Releases::Source::FORMATS.count) is_expected.to eq(Gitlab::Workhorse::ARCHIVE_FORMATS.count)
end end
context 'when a links exists' do context 'when a links exists' do
let!(:link) { create(:release_link, release: release) } let!(:link) { create(:release_link, release: release) }
it 'counts the link as an asset' do it 'counts the link as an asset' do
is_expected.to eq(1 + Releases::Source::FORMATS.count) is_expected.to eq(1 + Gitlab::Workhorse::ARCHIVE_FORMATS.count)
end end
it "excludes sources count when asked" do it "excludes sources count when asked" do
......
...@@ -11,7 +11,7 @@ describe Releases::Source do ...@@ -11,7 +11,7 @@ describe Releases::Source do
it 'returns all formats of sources' do it 'returns all formats of sources' do
expect(subject.map(&:format)) expect(subject.map(&:format))
.to match_array(described_class::FORMATS) .to match_array(Gitlab::Workhorse::ARCHIVE_FORMATS)
end end
end end
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'archive download buttons' do shared_examples 'archive download buttons' do
let(:formats) { %w(zip tar.gz tar.bz2 tar) }
let(:path_to_visit) { project_path(project) } let(:path_to_visit) { project_path(project) }
let(:ref) { project.default_branch } let(:ref) { project.default_branch }
...@@ -13,7 +12,7 @@ shared_examples 'archive download buttons' do ...@@ -13,7 +12,7 @@ shared_examples 'archive download buttons' do
context 'private project' do context 'private project' do
it 'shows archive download buttons with external storage URL prepended and user token appended to their href' do it 'shows archive download buttons with external storage URL prepended and user token appended to their href' do
formats.each do |format| Gitlab::Workhorse::ARCHIVE_FORMATS.each do |format|
path = archive_path(project, ref, format) path = archive_path(project, ref, format)
uri = URI('https://cdn.gitlab.com') uri = URI('https://cdn.gitlab.com')
uri.path = path uri.path = path
...@@ -28,7 +27,7 @@ shared_examples 'archive download buttons' do ...@@ -28,7 +27,7 @@ shared_examples 'archive download buttons' do
let(:project) { create(:project, :repository, :public) } let(:project) { create(:project, :repository, :public) }
it 'shows archive download buttons with external storage URL prepended to their href' do it 'shows archive download buttons with external storage URL prepended to their href' do
formats.each do |format| Gitlab::Workhorse::ARCHIVE_FORMATS.each do |format|
path = archive_path(project, ref, format) path = archive_path(project, ref, format)
uri = URI('https://cdn.gitlab.com') uri = URI('https://cdn.gitlab.com')
uri.path = path uri.path = path
...@@ -45,7 +44,7 @@ shared_examples 'archive download buttons' do ...@@ -45,7 +44,7 @@ shared_examples 'archive download buttons' do
end end
it 'shows default archive download buttons' do it 'shows default archive download buttons' do
formats.each do |format| Gitlab::Workhorse::ARCHIVE_FORMATS.each do |format|
path = archive_path(project, ref, format) path = archive_path(project, ref, format)
expect(page).to have_link format, href: path expect(page).to have_link format, href: path
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment