diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 18:08:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 18:08:52 +0300 |
commit | 0ab47b994caa80c5587f33dc818626b66cfdafe2 (patch) | |
tree | 5ef3976d2f84e3368903a67ba2dbd87a74b9a43c /lib/gitlab/git_access_snippet.rb | |
parent | 1308dc5eb484ab0f8064989fc551ebdb4b1a7976 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/git_access_snippet.rb')
-rw-r--r-- | lib/gitlab/git_access_snippet.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/gitlab/git_access_snippet.rb b/lib/gitlab/git_access_snippet.rb new file mode 100644 index 00000000000..d99b9c3fe89 --- /dev/null +++ b/lib/gitlab/git_access_snippet.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +module Gitlab + class GitAccessSnippet < GitAccess + ERROR_MESSAGES = { + snippet_not_found: 'The snippet you were looking for could not be found.', + repository_not_found: 'The snippet repository you were looking for could not be found.' + }.freeze + + attr_reader :snippet + + def initialize(actor, snippet, protocol, **kwargs) + @snippet = snippet + + super(actor, project, protocol, **kwargs) + end + + def check(cmd, _changes) + unless Feature.enabled?(:version_snippets, user) + raise NotFoundError, ERROR_MESSAGES[:snippet_not_found] + end + + check_snippet_accessibility! + + success_result(cmd) + end + + def project + snippet&.project + end + + private + + def repository + snippet&.repository + end + + def check_snippet_accessibility! + if snippet.blank? + raise NotFoundError, ERROR_MESSAGES[:snippet_not_found] + end + + unless repository&.exists? + raise NotFoundError, ERROR_MESSAGES[:repository_not_found] + end + end + end +end |