Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r--lib/gitlab/git/declared_license.rb38
-rw-r--r--lib/gitlab/git/repository.rb29
-rw-r--r--lib/gitlab/git/wiki.rb131
-rw-r--r--lib/gitlab/git/wiki_page.rb21
4 files changed, 68 insertions, 151 deletions
diff --git a/lib/gitlab/git/declared_license.rb b/lib/gitlab/git/declared_license.rb
new file mode 100644
index 00000000000..bc12b1918ea
--- /dev/null
+++ b/lib/gitlab/git/declared_license.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Git
+ # DeclaredLicense is the software license declared in a LICENSE or COPYING
+ # file in the git repository.
+ class DeclaredLicense
+ # SPDX Identifier for the license
+ attr_reader :key
+
+ # Full name of the license
+ attr_reader :name
+
+ # Nickname of the license (optional, a shorter user-friendly name)
+ attr_reader :nickname
+
+ # Filename of the file containing license
+ attr_accessor :path
+
+ # URL that points to the LICENSE
+ attr_reader :url
+
+ def initialize(key: nil, name: nil, nickname: nil, url: nil, path: nil)
+ @key = key
+ @name = name
+ @nickname = nickname
+ @url = url
+ @path = path
+ end
+
+ def ==(other)
+ return unless other.is_a?(self.class)
+
+ key == other.key
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index f1cd75258be..9bbe17dcad1 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -783,10 +783,31 @@ module Gitlab
end
end
- def license_short_name
+ def license(from_gitaly)
wrapped_gitaly_errors do
- gitaly_repository_client.license_short_name
+ response = gitaly_repository_client.find_license
+
+ break nil if response.license_short_name.empty?
+
+ if from_gitaly
+ break ::Gitlab::Git::DeclaredLicense.new(key: response.license_short_name,
+ name: response.license_name,
+ nickname: response.license_nickname.presence,
+ url: response.license_url.presence,
+ path: response.license_path)
+ end
+
+ licensee_object = Licensee::License.new(response.license_short_name)
+
+ break nil if licensee_object.name.blank?
+
+ licensee_object.meta.nickname = "LICENSE" if licensee_object.key == "other"
+
+ licensee_object
end
+ rescue Licensee::InvalidLicense => e
+ Gitlab::ErrorTracking.track_exception(e)
+ nil
end
def fetch_source_branch!(source_repository, source_branch, local_ref)
@@ -1008,8 +1029,8 @@ module Gitlab
@praefect_info_client ||= Gitlab::GitalyClient::PraefectInfoService.new(self)
end
- def branch_names_contains_sha(sha)
- gitaly_ref_client.branch_names_contains_sha(sha)
+ def branch_names_contains_sha(sha, limit: 0)
+ gitaly_ref_client.branch_names_contains_sha(sha, limit: limit)
end
def tag_names_contains_sha(sha, limit: 0)
diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb
deleted file mode 100644
index 2228fcb886e..00000000000
--- a/lib/gitlab/git/wiki.rb
+++ /dev/null
@@ -1,131 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module Git
- class Wiki
- include Gitlab::Git::WrapsGitalyErrors
-
- DuplicatePageError = Class.new(StandardError)
-
- DEFAULT_PAGINATION = Kaminari.config.default_per_page
-
- CommitDetails = Struct.new(:user_id, :username, :name, :email, :message) do
- def to_h
- { user_id: user_id, username: username, name: name, email: email, message: message }
- end
- end
-
- # GollumSlug inlines just enough knowledge from Gollum::Page to generate a
- # slug, which is used when previewing pages that haven't been persisted
- class GollumSlug
- class << self
- def cname(name, char_white_sub = '-', char_other_sub = '-')
- if name.respond_to?(:gsub)
- name.gsub(/\s/, char_white_sub).gsub(/[<>+]/, char_other_sub)
- else
- ''
- end
- end
-
- def format_to_ext(format)
- format == :markdown ? "md" : format.to_s
- end
-
- def canonicalize_filename(filename)
- ::File.basename(filename, ::File.extname(filename)).tr('-', ' ')
- end
-
- def generate(title, format)
- ext = format_to_ext(format.to_sym)
- name = cname(title) + '.' + ext
- canonical_name = canonicalize_filename(name)
-
- path =
- if name.include?('/')
- name.sub(%r{/[^/]+$}, '/')
- else
- ''
- end
-
- path + cname(canonical_name, '-', '-')
- end
- end
- end
-
- attr_reader :repository
-
- # TODO remove argument when issue
- # https://gitlab.com/gitlab-org/gitlab/-/issues/329190
- # is closed.
- def self.default_ref(container = nil)
- Gitlab::DefaultBranch.value(object: container)
- end
-
- # Initialize with a Gitlab::Git::Repository instance
- def initialize(repository)
- @repository = repository
- end
-
- def repository_exists?
- @repository.exists?
- end
-
- def list_pages(limit: 0, sort: nil, direction_desc: false, load_content: false)
- wrapped_gitaly_errors do
- gitaly_list_pages(
- limit: limit,
- sort: sort,
- direction_desc: direction_desc,
- load_content: load_content
- )
- end
- end
-
- def page(title:, version: nil, dir: nil, load_content: true)
- wrapped_gitaly_errors do
- gitaly_find_page(title: title, version: version, dir: dir, load_content: load_content)
- end
- end
-
- def count_page_versions(page_path)
- @repository.count_commits(ref: 'HEAD', path: page_path)
- end
-
- def preview_slug(title, format)
- GollumSlug.generate(title, format)
- end
-
- private
-
- def gitaly_wiki_client
- @gitaly_wiki_client ||= Gitlab::GitalyClient::WikiService.new(@repository)
- end
-
- def gitaly_find_page(title:, version: nil, dir: nil, load_content: true)
- return unless title.present?
-
- wiki_page, version = gitaly_wiki_client.find_page(title: title, version: version, dir: dir, load_content: load_content)
- return unless wiki_page
-
- Gitlab::Git::WikiPage.from_gitaly_wiki_page(wiki_page, version)
- rescue GRPC::InvalidArgument
- nil
- end
-
- def gitaly_list_pages(limit: 0, sort: nil, direction_desc: false, load_content: false)
- params = { limit: limit, sort: sort, direction_desc: direction_desc }
-
- gitaly_pages =
- if load_content
- gitaly_wiki_client.load_all_pages(**params)
- else
- gitaly_wiki_client.list_all_pages(**params)
- end
-
- gitaly_pages.map do |wiki_page, version|
- Gitlab::Git::WikiPage.from_gitaly_wiki_page(wiki_page, version)
- end
- end
- end
- end
-end
diff --git a/lib/gitlab/git/wiki_page.rb b/lib/gitlab/git/wiki_page.rb
index 57b7e7d53dd..26d15daf093 100644
--- a/lib/gitlab/git/wiki_page.rb
+++ b/lib/gitlab/git/wiki_page.rb
@@ -5,22 +5,6 @@ module Gitlab
class WikiPage
attr_reader :url_path, :title, :format, :path, :version, :raw_data, :name, :historical, :formatted_data
- class << self
- # Abstracts away Gitlab::GitalyClient::WikiPage
- def from_gitaly_wiki_page(gitaly_page, version)
- new(
- url_path: gitaly_page.url_path,
- title: gitaly_page.title,
- format: gitaly_page.format,
- path: gitaly_page.path,
- raw_data: gitaly_page.raw_data,
- name: gitaly_page.name,
- historical: gitaly_page.historical?,
- version: version
- )
- end
- end
-
def initialize(hash)
@url_path = hash[:url_path]
@title = hash[:title]
@@ -41,6 +25,11 @@ module Gitlab
@text_data = @raw_data && Gitlab::EncodingHelper.encode!(@raw_data.dup)
end
+
+ def raw_data=(data)
+ @raw_data = data
+ @text_data = @raw_data && Gitlab::EncodingHelper.encode!(@raw_data.dup)
+ end
end
end
end