debian-mirror-gitlab/lib/api/entities/snippet.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
796 B
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module API
module Entities
2021-03-08 18:12:59 +05:30
class Snippet < BasicSnippet
2023-01-13 00:05:48 +05:30
expose :author, using: Entities::UserBasic, documentation: { type: 'Entities::UserBasic' }
expose :file_name, documentation: { type: 'string', example: 'add.rb' } do |snippet|
2021-09-04 01:27:46 +05:30
snippet_files.first || snippet.file_name
2020-05-24 23:13:21 +05:30
end
2023-01-13 00:05:48 +05:30
expose :files, documentation: {
is_array: true, example: 'e0d123e5f316bef78bfdf5a008837577'
} do |snippet, options|
2021-09-04 01:27:46 +05:30
snippet_files.map do |file|
2020-07-28 23:09:34 +05:30
{
path: file,
raw_url: Gitlab::UrlBuilder.build(snippet, file: file, ref: snippet.repository.root_ref)
}
end
end
2021-09-04 01:27:46 +05:30
private
def snippet_files
@snippet_files ||= object.list_files
end
2020-03-13 15:44:24 +05:30
end
end
end