2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-20 09:56:36 -05:00
|
|
|
class ProjectPresenter < Gitlab::View::Presenter::Delegated
|
|
|
|
include ActionView::Helpers::NumberHelper
|
|
|
|
include GitlabRoutingHelper
|
|
|
|
include StorageHelper
|
|
|
|
include TreeHelper
|
2018-12-07 09:11:42 -05:00
|
|
|
include IconsHelper
|
2020-08-26 11:10:29 -04:00
|
|
|
include BlobHelper
|
2018-04-18 06:44:12 -04:00
|
|
|
include ChecksCollaboration
|
2018-02-20 17:04:10 -05:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
2021-02-17 13:09:19 -05:00
|
|
|
include Gitlab::Experiment::Dsl
|
2018-02-20 09:56:36 -05:00
|
|
|
|
2021-09-21 05:12:21 -04:00
|
|
|
delegator_override_with GitlabRoutingHelper # TODO: Remove `GitlabRoutingHelper` inclusion as it's duplicate
|
2022-02-16 16:12:25 -05:00
|
|
|
delegator_override_with Gitlab::Utils::StrongMemoize # This module inclusion is expected. See https://gitlab.com/gitlab-org/gitlab/-/issues/352884.
|
2021-09-21 05:12:21 -04:00
|
|
|
|
|
|
|
presents ::Project, as: :project
|
2018-02-20 09:56:36 -05:00
|
|
|
|
2021-02-17 13:09:19 -05:00
|
|
|
AnchorData = Struct.new(:is_link, :label, :link, :class_modifier, :icon, :itemprop, :data)
|
2019-01-10 15:08:41 -05:00
|
|
|
MAX_TOPICS_TO_SHOW = 3
|
2018-09-06 03:27:39 -04:00
|
|
|
|
2018-12-07 09:11:42 -05:00
|
|
|
def statistic_icon(icon_name = 'plus-square-o')
|
2021-01-21 10:08:36 -05:00
|
|
|
sprite_icon(icon_name, css_class: 'icon gl-mr-2 gl-text-gray-500')
|
2018-12-07 09:11:42 -05:00
|
|
|
end
|
|
|
|
|
2018-02-20 13:51:52 -05:00
|
|
|
def statistics_anchors(show_auto_devops_callout:)
|
2018-02-20 09:56:36 -05:00
|
|
|
[
|
|
|
|
commits_anchor_data,
|
|
|
|
branches_anchor_data,
|
|
|
|
tags_anchor_data,
|
2020-03-25 11:07:47 -04:00
|
|
|
storage_anchor_data,
|
2020-01-17 04:08:24 -05:00
|
|
|
releases_anchor_data
|
2018-12-07 09:11:42 -05:00
|
|
|
].compact.select(&:is_link)
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
|
2018-02-20 13:51:52 -05:00
|
|
|
def statistics_buttons(show_auto_devops_callout:)
|
2018-02-20 09:56:36 -05:00
|
|
|
[
|
2018-07-03 07:58:03 -04:00
|
|
|
readme_anchor_data,
|
2019-11-18 13:06:53 -05:00
|
|
|
license_anchor_data,
|
2018-02-20 09:56:36 -05:00
|
|
|
changelog_anchor_data,
|
|
|
|
contribution_guide_anchor_data,
|
|
|
|
autodevops_anchor_data(show_auto_devops_callout: show_auto_devops_callout),
|
|
|
|
kubernetes_cluster_anchor_data,
|
2021-02-24 13:11:28 -05:00
|
|
|
gitlab_ci_anchor_data,
|
|
|
|
integrations_anchor_data
|
2019-04-19 09:02:35 -04:00
|
|
|
].compact.reject(&:is_link).sort_by.with_index { |item, idx| [item.class_modifier ? 0 : 1, idx] }
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
|
2018-02-20 13:51:52 -05:00
|
|
|
def empty_repo_statistics_anchors
|
2019-11-18 13:06:53 -05:00
|
|
|
[]
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
|
2018-02-20 13:51:52 -05:00
|
|
|
def empty_repo_statistics_buttons
|
2018-02-20 09:56:36 -05:00
|
|
|
[
|
2021-02-17 13:09:19 -05:00
|
|
|
upload_anchor_data,
|
2018-02-20 09:56:36 -05:00
|
|
|
new_file_anchor_data,
|
|
|
|
readme_anchor_data,
|
2019-11-18 13:06:53 -05:00
|
|
|
license_anchor_data,
|
2018-12-07 09:11:42 -05:00
|
|
|
changelog_anchor_data,
|
2019-09-20 05:06:17 -04:00
|
|
|
contribution_guide_anchor_data,
|
2021-02-24 13:11:28 -05:00
|
|
|
gitlab_ci_anchor_data,
|
|
|
|
integrations_anchor_data
|
2018-12-07 09:11:42 -05:00
|
|
|
].compact.reject { |item| item.is_link }
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
|
2018-02-20 11:30:49 -05:00
|
|
|
def default_view
|
2018-02-20 09:56:36 -05:00
|
|
|
return anonymous_project_view unless current_user
|
|
|
|
|
|
|
|
user_view = current_user.project_view
|
|
|
|
|
|
|
|
if can?(current_user, :download_code, project)
|
|
|
|
user_view
|
2020-10-14 20:08:42 -04:00
|
|
|
elsif user_view == 'activity'
|
|
|
|
'activity'
|
|
|
|
elsif project.wiki_repository_exists? && can?(current_user, :read_wiki, project)
|
|
|
|
'wiki'
|
|
|
|
elsif can?(current_user, :read_issue, project)
|
|
|
|
'projects/issues/issues'
|
2018-02-20 09:56:36 -05:00
|
|
|
else
|
2020-10-14 20:08:42 -04:00
|
|
|
'activity'
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def readme_path
|
2020-12-09 07:09:42 -05:00
|
|
|
filename_path(repository.readme_path)
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def changelog_path
|
2020-12-09 07:09:42 -05:00
|
|
|
filename_path(repository.changelog&.name)
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def license_path
|
2020-12-09 07:09:42 -05:00
|
|
|
filename_path(repository.license_blob&.name)
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def contribution_guide_path
|
|
|
|
if project && contribution_guide = repository.contribution_guide
|
|
|
|
project_blob_path(
|
|
|
|
project,
|
|
|
|
tree_join(project.default_branch,
|
|
|
|
contribution_guide.name)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_license_path
|
|
|
|
add_special_file_path(file_name: 'LICENSE')
|
|
|
|
end
|
|
|
|
|
2020-10-14 08:08:58 -04:00
|
|
|
def add_license_ide_path
|
2021-05-04 08:10:04 -04:00
|
|
|
ide_edit_path(project, default_branch_or_main, 'LICENSE')
|
2020-10-14 08:08:58 -04:00
|
|
|
end
|
|
|
|
|
2018-02-20 16:59:19 -05:00
|
|
|
def add_changelog_path
|
|
|
|
add_special_file_path(file_name: 'CHANGELOG')
|
|
|
|
end
|
|
|
|
|
2020-10-14 08:08:58 -04:00
|
|
|
def add_changelog_ide_path
|
2021-05-04 08:10:04 -04:00
|
|
|
ide_edit_path(project, default_branch_or_main, 'CHANGELOG')
|
2020-10-14 08:08:58 -04:00
|
|
|
end
|
|
|
|
|
2018-02-20 16:59:19 -05:00
|
|
|
def add_contribution_guide_path
|
2018-12-07 09:11:42 -05:00
|
|
|
add_special_file_path(file_name: 'CONTRIBUTING.md', commit_message: 'Add CONTRIBUTING')
|
2018-02-20 16:59:19 -05:00
|
|
|
end
|
|
|
|
|
2020-10-14 08:08:58 -04:00
|
|
|
def add_contribution_guide_ide_path
|
2021-05-04 08:10:04 -04:00
|
|
|
ide_edit_path(project, default_branch_or_main, 'CONTRIBUTING.md')
|
2020-10-14 08:08:58 -04:00
|
|
|
end
|
|
|
|
|
2018-02-20 09:56:36 -05:00
|
|
|
def add_readme_path
|
|
|
|
add_special_file_path(file_name: 'README.md')
|
|
|
|
end
|
|
|
|
|
2020-10-14 08:08:58 -04:00
|
|
|
def add_readme_ide_path
|
2021-05-04 08:10:04 -04:00
|
|
|
ide_edit_path(project, default_branch_or_main, 'README.md')
|
2020-10-14 08:08:58 -04:00
|
|
|
end
|
|
|
|
|
2018-02-20 09:56:36 -05:00
|
|
|
def license_short_name
|
|
|
|
license = repository.license
|
|
|
|
license&.nickname || license&.name || 'LICENSE'
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_current_user_push_code?
|
2018-02-20 17:04:10 -05:00
|
|
|
strong_memoize(:can_current_user_push_code) do
|
|
|
|
if empty_repo?
|
|
|
|
can?(current_user, :push_code, project)
|
|
|
|
else
|
2018-02-22 11:56:38 -05:00
|
|
|
can_current_user_push_to_branch?(default_branch)
|
2018-02-20 17:04:10 -05:00
|
|
|
end
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-22 11:56:38 -05:00
|
|
|
def can_current_user_push_to_branch?(branch)
|
2021-02-17 13:09:19 -05:00
|
|
|
return false unless current_user
|
|
|
|
|
2018-04-18 06:44:12 -04:00
|
|
|
user_access(project).can_push_to_branch?(branch)
|
|
|
|
end
|
2018-02-22 11:56:38 -05:00
|
|
|
|
2018-04-18 06:44:12 -04:00
|
|
|
def can_current_user_push_to_default_branch?
|
|
|
|
can_current_user_push_to_branch?(default_branch)
|
2018-02-22 11:56:38 -05:00
|
|
|
end
|
|
|
|
|
2020-03-25 11:07:47 -04:00
|
|
|
def storage_anchor_data
|
2022-05-19 05:09:08 -04:00
|
|
|
can_show_quota = can?(current_user, :admin_project, project) && !empty_repo?
|
2020-03-25 11:07:47 -04:00
|
|
|
AnchorData.new(true,
|
|
|
|
statistic_icon('disk') +
|
2022-05-19 05:09:08 -04:00
|
|
|
_('%{strong_start}%{human_size}%{strong_end} Project Storage').html_safe % {
|
2020-03-25 11:07:47 -04:00
|
|
|
human_size: storage_counter(statistics.storage_size),
|
|
|
|
strong_start: '<strong class="project-stat-value">'.html_safe,
|
|
|
|
strong_end: '</strong>'.html_safe
|
|
|
|
},
|
2022-05-19 05:09:08 -04:00
|
|
|
can_show_quota ? project_usage_quotas_path(project) : nil)
|
2020-03-25 11:07:47 -04:00
|
|
|
end
|
|
|
|
|
2020-01-17 04:08:24 -05:00
|
|
|
def releases_anchor_data
|
|
|
|
return unless can?(current_user, :read_release, project)
|
|
|
|
|
|
|
|
releases_count = project.releases.count
|
|
|
|
return if releases_count < 1
|
|
|
|
|
|
|
|
AnchorData.new(true,
|
|
|
|
statistic_icon('rocket') +
|
|
|
|
n_('%{strong_start}%{release_count}%{strong_end} Release', '%{strong_start}%{release_count}%{strong_end} Releases', releases_count).html_safe % {
|
|
|
|
release_count: number_with_delimiter(releases_count),
|
|
|
|
strong_start: '<strong class="project-stat-value">'.html_safe,
|
|
|
|
strong_end: '</strong>'.html_safe
|
|
|
|
},
|
|
|
|
project_releases_path(project))
|
|
|
|
end
|
|
|
|
|
2018-02-20 09:56:36 -05:00
|
|
|
def commits_anchor_data
|
2018-09-06 03:27:39 -04:00
|
|
|
AnchorData.new(true,
|
2018-12-07 09:11:42 -05:00
|
|
|
statistic_icon('commit') +
|
|
|
|
n_('%{strong_start}%{commit_count}%{strong_end} Commit', '%{strong_start}%{commit_count}%{strong_end} Commits', statistics.commit_count).html_safe % {
|
|
|
|
commit_count: number_with_delimiter(statistics.commit_count),
|
|
|
|
strong_start: '<strong class="project-stat-value">'.html_safe,
|
|
|
|
strong_end: '</strong>'.html_safe
|
|
|
|
},
|
2021-05-10 14:10:41 -04:00
|
|
|
empty_repo? ? nil : project_commits_path(project, default_branch_or_main))
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def branches_anchor_data
|
2018-09-06 03:27:39 -04:00
|
|
|
AnchorData.new(true,
|
2018-12-07 09:11:42 -05:00
|
|
|
statistic_icon('branch') +
|
|
|
|
n_('%{strong_start}%{branch_count}%{strong_end} Branch', '%{strong_start}%{branch_count}%{strong_end} Branches', repository.branch_count).html_safe % {
|
|
|
|
branch_count: number_with_delimiter(repository.branch_count),
|
|
|
|
strong_start: '<strong class="project-stat-value">'.html_safe,
|
|
|
|
strong_end: '</strong>'.html_safe
|
|
|
|
},
|
2018-09-06 03:27:39 -04:00
|
|
|
empty_repo? ? nil : project_branches_path(project))
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def tags_anchor_data
|
2018-09-06 03:27:39 -04:00
|
|
|
AnchorData.new(true,
|
2018-12-07 09:11:42 -05:00
|
|
|
statistic_icon('label') +
|
|
|
|
n_('%{strong_start}%{tag_count}%{strong_end} Tag', '%{strong_start}%{tag_count}%{strong_end} Tags', repository.tag_count).html_safe % {
|
|
|
|
tag_count: number_with_delimiter(repository.tag_count),
|
|
|
|
strong_start: '<strong class="project-stat-value">'.html_safe,
|
|
|
|
strong_end: '</strong>'.html_safe
|
|
|
|
},
|
2018-09-06 03:27:39 -04:00
|
|
|
empty_repo? ? nil : project_tags_path(project))
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
|
2021-02-17 13:09:19 -05:00
|
|
|
def upload_anchor_data
|
|
|
|
strong_memoize(:upload_anchor_data) do
|
|
|
|
next unless can_current_user_push_to_default_branch?
|
|
|
|
|
2021-10-28 23:12:09 -04:00
|
|
|
AnchorData.new(false,
|
|
|
|
statistic_icon('upload') + _('Upload file'),
|
|
|
|
'#modal-upload-blob',
|
|
|
|
'js-upload-file-trigger',
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
{
|
|
|
|
'target_branch' => default_branch_or_main,
|
|
|
|
'original_branch' => default_branch_or_main,
|
|
|
|
'can_push_code' => 'true',
|
|
|
|
'path' => project_create_blob_path(project, default_branch_or_main),
|
|
|
|
'project_path' => project.full_path
|
|
|
|
}
|
|
|
|
)
|
2021-02-17 13:09:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-20 09:56:36 -05:00
|
|
|
def new_file_anchor_data
|
2021-02-17 13:09:19 -05:00
|
|
|
if can_current_user_push_to_default_branch?
|
2021-05-04 08:10:04 -04:00
|
|
|
new_file_path = empty_repo? ? ide_edit_path(project, default_branch_or_main) : project_new_blob_path(project, default_branch_or_main)
|
2020-10-14 08:08:58 -04:00
|
|
|
|
2018-09-06 03:27:39 -04:00
|
|
|
AnchorData.new(false,
|
2018-12-07 09:11:42 -05:00
|
|
|
statistic_icon + _('New file'),
|
2020-10-14 08:08:58 -04:00
|
|
|
new_file_path,
|
2021-02-17 13:09:19 -05:00
|
|
|
'btn-dashed')
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def readme_anchor_data
|
2021-02-17 13:09:19 -05:00
|
|
|
if can_current_user_push_to_default_branch? && readme_path.nil?
|
2018-09-06 03:27:39 -04:00
|
|
|
AnchorData.new(false,
|
2018-12-07 09:11:42 -05:00
|
|
|
statistic_icon + _('Add README'),
|
2020-10-14 08:08:58 -04:00
|
|
|
empty_repo? ? add_readme_ide_path : add_readme_path)
|
2020-12-09 07:09:42 -05:00
|
|
|
elsif readme_path
|
2018-12-07 09:11:42 -05:00
|
|
|
AnchorData.new(false,
|
|
|
|
statistic_icon('doc-text') + _('README'),
|
|
|
|
default_view != 'readme' ? readme_path : '#readme',
|
2021-02-17 13:09:19 -05:00
|
|
|
'btn-default',
|
2018-12-07 09:11:42 -05:00
|
|
|
'doc-text')
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def changelog_anchor_data
|
2021-02-17 13:09:19 -05:00
|
|
|
if can_current_user_push_to_default_branch? && repository.changelog.blank?
|
2018-09-06 03:27:39 -04:00
|
|
|
AnchorData.new(false,
|
2018-12-07 09:11:42 -05:00
|
|
|
statistic_icon + _('Add CHANGELOG'),
|
2020-10-14 08:08:58 -04:00
|
|
|
empty_repo? ? add_changelog_ide_path : add_changelog_path)
|
2018-02-20 09:56:36 -05:00
|
|
|
elsif repository.changelog.present?
|
2018-12-07 09:11:42 -05:00
|
|
|
AnchorData.new(false,
|
|
|
|
statistic_icon('doc-text') + _('CHANGELOG'),
|
|
|
|
changelog_path,
|
2021-02-17 13:09:19 -05:00
|
|
|
'btn-default')
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def license_anchor_data
|
2018-12-07 09:11:42 -05:00
|
|
|
icon = statistic_icon('scale')
|
|
|
|
|
2018-09-06 03:27:39 -04:00
|
|
|
if repository.license_blob.present?
|
2019-11-18 13:06:53 -05:00
|
|
|
AnchorData.new(false,
|
|
|
|
icon + content_tag(:span, license_short_name, class: 'project-stat-value'),
|
|
|
|
license_path,
|
2021-02-17 13:09:19 -05:00
|
|
|
'btn-default',
|
2020-11-10 13:09:07 -05:00
|
|
|
nil,
|
|
|
|
'license')
|
2018-09-06 03:27:39 -04:00
|
|
|
else
|
2021-02-17 13:09:19 -05:00
|
|
|
if can_current_user_push_to_default_branch?
|
2019-11-18 13:06:53 -05:00
|
|
|
AnchorData.new(false,
|
|
|
|
content_tag(:span, statistic_icon + _('Add LICENSE'), class: 'add-license-link d-flex'),
|
2020-10-14 08:08:58 -04:00
|
|
|
empty_repo? ? add_license_ide_path : add_license_path)
|
2018-09-06 03:27:39 -04:00
|
|
|
else
|
2019-11-18 13:06:53 -05:00
|
|
|
AnchorData.new(false,
|
|
|
|
icon + content_tag(:span, _('No license. All rights reserved'), class: 'project-stat-value'),
|
2018-09-06 03:27:39 -04:00
|
|
|
nil)
|
|
|
|
end
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def contribution_guide_anchor_data
|
2021-02-17 13:09:19 -05:00
|
|
|
if can_current_user_push_to_default_branch? && repository.contribution_guide.blank?
|
2018-09-06 03:27:39 -04:00
|
|
|
AnchorData.new(false,
|
2018-12-07 09:11:42 -05:00
|
|
|
statistic_icon + _('Add CONTRIBUTING'),
|
2020-10-14 08:08:58 -04:00
|
|
|
empty_repo? ? add_contribution_guide_ide_path : add_contribution_guide_path)
|
2018-02-20 09:56:36 -05:00
|
|
|
elsif repository.contribution_guide.present?
|
2018-12-07 09:11:42 -05:00
|
|
|
AnchorData.new(false,
|
|
|
|
statistic_icon('doc-text') + _('CONTRIBUTING'),
|
2019-02-11 20:05:17 -05:00
|
|
|
contribution_guide_path,
|
2021-02-17 13:09:19 -05:00
|
|
|
'btn-default')
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def autodevops_anchor_data(show_auto_devops_callout: false)
|
2022-09-09 05:14:13 -04:00
|
|
|
return unless project.feature_available?(:builds, current_user)
|
|
|
|
|
2018-02-20 09:56:36 -05:00
|
|
|
if current_user && can?(current_user, :admin_pipeline, project) && repository.gitlab_ci_yml.blank? && !show_auto_devops_callout
|
2018-12-07 09:11:42 -05:00
|
|
|
if auto_devops_enabled?
|
|
|
|
AnchorData.new(false,
|
2019-04-19 09:02:35 -04:00
|
|
|
statistic_icon('settings') + _('Auto DevOps enabled'),
|
2018-12-07 09:11:42 -05:00
|
|
|
project_settings_ci_cd_path(project, anchor: 'autodevops-settings'),
|
2021-02-17 13:09:19 -05:00
|
|
|
'btn-default')
|
2018-12-07 09:11:42 -05:00
|
|
|
else
|
|
|
|
AnchorData.new(false,
|
|
|
|
statistic_icon + _('Enable Auto DevOps'),
|
|
|
|
project_settings_ci_cd_path(project, anchor: 'autodevops-settings'))
|
|
|
|
end
|
2018-02-20 09:56:36 -05:00
|
|
|
elsif auto_devops_enabled?
|
2018-12-07 09:11:42 -05:00
|
|
|
AnchorData.new(false,
|
2018-09-06 03:27:39 -04:00
|
|
|
_('Auto DevOps enabled'),
|
|
|
|
nil)
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def kubernetes_cluster_anchor_data
|
2020-01-09 07:08:03 -05:00
|
|
|
if can_instantiate_cluster?
|
2018-02-20 09:56:36 -05:00
|
|
|
if clusters.empty?
|
2018-12-07 09:11:42 -05:00
|
|
|
AnchorData.new(false,
|
|
|
|
statistic_icon + _('Add Kubernetes cluster'),
|
2022-01-10 01:13:42 -05:00
|
|
|
project_clusters_path(project))
|
2018-12-07 09:11:42 -05:00
|
|
|
else
|
|
|
|
cluster_link = clusters.count == 1 ? project_cluster_path(project, clusters.first) : project_clusters_path(project)
|
2018-02-20 09:56:36 -05:00
|
|
|
|
2018-12-07 09:11:42 -05:00
|
|
|
AnchorData.new(false,
|
2020-02-07 07:09:13 -05:00
|
|
|
_('Kubernetes'),
|
2018-12-07 09:11:42 -05:00
|
|
|
cluster_link,
|
2021-02-17 13:09:19 -05:00
|
|
|
'btn-default')
|
2018-12-07 09:11:42 -05:00
|
|
|
end
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_ci_anchor_data
|
2020-01-09 07:08:03 -05:00
|
|
|
if cicd_missing?
|
2018-09-06 03:27:39 -04:00
|
|
|
AnchorData.new(false,
|
2018-12-07 09:11:42 -05:00
|
|
|
statistic_icon + _('Set up CI/CD'),
|
2021-03-31 14:09:19 -04:00
|
|
|
project_ci_pipeline_editor_path(project))
|
2018-02-20 09:56:36 -05:00
|
|
|
elsif repository.gitlab_ci_yml.present?
|
2018-12-07 09:11:42 -05:00
|
|
|
AnchorData.new(false,
|
|
|
|
statistic_icon('doc-text') + _('CI/CD configuration'),
|
2021-03-31 14:09:19 -04:00
|
|
|
project_ci_pipeline_editor_path(project),
|
2021-02-17 13:09:19 -05:00
|
|
|
'btn-default')
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-10 15:08:41 -05:00
|
|
|
def topics_to_show
|
2021-08-09 05:22:41 -04:00
|
|
|
project_topic_list.take(MAX_TOPICS_TO_SHOW) # rubocop: disable CodeReuse/ActiveRecord
|
2018-09-06 03:27:39 -04:00
|
|
|
end
|
|
|
|
|
2019-02-28 05:37:39 -05:00
|
|
|
def topics_not_shown
|
2021-08-09 05:22:41 -04:00
|
|
|
project_topic_list - topics_to_show
|
2019-02-28 05:37:39 -05:00
|
|
|
end
|
|
|
|
|
2019-01-10 15:08:41 -05:00
|
|
|
def count_of_extra_topics_not_shown
|
2021-08-09 05:22:41 -04:00
|
|
|
if project_topic_list.count > MAX_TOPICS_TO_SHOW
|
|
|
|
project_topic_list.count - MAX_TOPICS_TO_SHOW
|
2018-09-06 03:27:39 -04:00
|
|
|
else
|
|
|
|
0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-10 15:08:41 -05:00
|
|
|
def has_extra_topics?
|
|
|
|
count_of_extra_topics_not_shown > 0
|
2018-09-06 03:27:39 -04:00
|
|
|
end
|
|
|
|
|
2020-01-09 07:08:03 -05:00
|
|
|
def can_setup_review_app?
|
|
|
|
strong_memoize(:can_setup_review_app) do
|
|
|
|
(can_instantiate_cluster? && all_clusters_empty?) || cicd_missing?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def all_clusters_empty?
|
|
|
|
strong_memoize(:all_clusters_empty) do
|
|
|
|
project.all_clusters.empty?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-20 16:59:19 -05:00
|
|
|
private
|
|
|
|
|
2021-02-24 13:11:28 -05:00
|
|
|
def integrations_anchor_data
|
2021-08-30 05:09:12 -04:00
|
|
|
return unless can?(current_user, :admin_project, project)
|
2021-02-24 13:11:28 -05:00
|
|
|
|
2021-08-30 05:09:12 -04:00
|
|
|
label = statistic_icon('settings') + _('Configure Integrations')
|
|
|
|
AnchorData.new(false, label, project_settings_integrations_path(project), nil, nil, nil)
|
2021-02-24 13:11:28 -05:00
|
|
|
end
|
|
|
|
|
2020-01-09 07:08:03 -05:00
|
|
|
def cicd_missing?
|
|
|
|
current_user && can_current_user_push_code? && repository.gitlab_ci_yml.blank? && !auto_devops_enabled?
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_instantiate_cluster?
|
|
|
|
current_user && can?(current_user, :create_cluster, project)
|
|
|
|
end
|
|
|
|
|
2020-12-09 07:09:42 -05:00
|
|
|
def filename_path(filepath)
|
|
|
|
return if filepath.blank?
|
|
|
|
|
|
|
|
project_blob_path(project, tree_join(default_branch, filepath))
|
2018-02-20 16:59:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def anonymous_project_view
|
|
|
|
if !project.empty_repo? && can?(current_user, :download_code, project)
|
|
|
|
'files'
|
2020-10-14 20:08:42 -04:00
|
|
|
elsif project.wiki_repository_exists? && can?(current_user, :read_wiki, project)
|
|
|
|
'wiki'
|
|
|
|
elsif can?(current_user, :read_issue, project)
|
|
|
|
'projects/issues/issues'
|
2018-02-20 16:59:19 -05:00
|
|
|
else
|
|
|
|
'activity'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-12 08:10:24 -04:00
|
|
|
def add_special_file_path(file_name:, commit_message: nil, branch_name: nil, additional_params: {})
|
2018-02-20 16:59:19 -05:00
|
|
|
commit_message ||= s_("CommitMessage|Add %{file_name}") % { file_name: file_name }
|
|
|
|
project_new_blob_path(
|
|
|
|
project,
|
2021-05-04 08:10:04 -04:00
|
|
|
default_branch_or_main,
|
2022-08-02 02:10:49 -04:00
|
|
|
file_name: file_name,
|
2018-02-20 16:59:19 -05:00
|
|
|
commit_message: commit_message,
|
2022-08-02 02:10:49 -04:00
|
|
|
branch_name: branch_name,
|
2021-05-12 08:10:24 -04:00
|
|
|
**additional_params
|
2018-02-20 16:59:19 -05:00
|
|
|
)
|
|
|
|
end
|
2021-08-09 05:22:41 -04:00
|
|
|
|
|
|
|
def project_topic_list
|
|
|
|
strong_memoize(:project_topic_list) do
|
2022-04-29 05:09:48 -04:00
|
|
|
project.topics.map { |topic| { name: topic.name, title: topic.title_or_name } }
|
2021-08-09 05:22:41 -04:00
|
|
|
end
|
|
|
|
end
|
2022-02-17 22:17:36 -05:00
|
|
|
|
|
|
|
# Avoid including ActionView::Helpers::UrlHelper
|
|
|
|
def content_tag(*args)
|
|
|
|
ActionController::Base.helpers.content_tag(*args)
|
|
|
|
end
|
2018-02-20 09:56:36 -05:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
ProjectPresenter.prepend_mod_with('ProjectPresenter')
|