1# frozen_string_literal: true 2 3module API 4 module Entities 5 class CommitWithLink < Commit 6 include MarkupHelper 7 include RequestAwareEntity 8 9 expose :author, using: Entities::UserPath 10 11 expose :author_gravatar_url do |commit| 12 GravatarService.new.execute(commit.author_email) 13 end 14 15 expose :commit_url do |commit, options| 16 project_commit_url(request.project, commit, params: options.fetch(:commit_url_params, {})) 17 end 18 19 expose :commit_path do |commit, options| 20 project_commit_path(request.project, commit, params: options.fetch(:commit_url_params, {})) 21 end 22 23 expose :description_html, if: { type: :full } do |commit| 24 markdown_field(commit, :description) 25 end 26 27 expose :title_html, if: { type: :full } do |commit| 28 markdown_field(commit, :title) 29 end 30 31 expose :signature_html, if: { type: :full } do |commit| 32 render('projects/commit/_signature', signature: commit.signature) if commit.has_signature? 33 end 34 35 expose :prev_commit_id, if: { type: :full } do |commit| 36 options[:prev_commit_id] 37 end 38 39 expose :next_commit_id, if: { type: :full } do |commit| 40 options[:next_commit_id] 41 end 42 43 expose :pipeline_status_path, if: { type: :full } do |commit, options| 44 pipeline_ref = options[:pipeline_ref] 45 pipeline_project = options[:pipeline_project] || commit.project 46 next unless pipeline_ref && pipeline_project 47 48 pipeline = commit.latest_pipeline_for_project(pipeline_ref, pipeline_project) 49 next unless pipeline&.status 50 51 pipelines_project_commit_path(pipeline_project, commit.id, ref: pipeline_ref) 52 end 53 54 def render(*args) 55 return unless request.respond_to?(:render) && request.render.respond_to?(:call) 56 57 request.render.call(*args) 58 end 59 end 60 end 61end 62