diff options
Diffstat (limited to 'lib/api/entities/snippet.rb')
-rw-r--r-- | lib/api/entities/snippet.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/api/entities/snippet.rb b/lib/api/entities/snippet.rb index 19c89603cbc..40488eb882d 100644 --- a/lib/api/entities/snippet.rb +++ b/lib/api/entities/snippet.rb @@ -17,6 +17,18 @@ module API expose :file_name do |snippet| snippet.file_name_on_repo || snippet.file_name end + expose :files, if: ->(snippet, options) { snippet_multiple_files?(snippet, options[:current_user]) } do |snippet, options| + snippet.list_files.map do |file| + { + path: file, + raw_url: Gitlab::UrlBuilder.build(snippet, file: file, ref: snippet.repository.root_ref) + } + end + end + + def snippet_multiple_files?(snippet, current_user) + ::Feature.enabled?(:snippet_multiple_files, current_user) && snippet.repository_exists? + end end end end |