Skip to content

Expose `project.project_forked_from` in app/serializers

Currently the front-end relies on some janky logic to determine if a project is forked

This code does seem very bug prone as we are trying to figure out if the project full path equals the target project path on the client. This is business logic and I don't think it's very stable. I would much prefer we have a key/value pair sent from the BE that simply lets the client know if we should display the label. I.E fork: true

To simplify this, we should send the data over to the front-end instead of having it find out for itself.

We can do this by:

diff --git a/app/serializers/project_entity.rb b/app/serializers/project_entity.rb
index cbdc19a83ce2..8a1ad2ea70b8 100644
--- a/app/serializers/project_entity.rb
+++ b/app/serializers/project_entity.rb
@@ -17,4 +17,9 @@ class ProjectEntity < Grape::Entity
   expose :refs_url do |project|
     refs_project_path(project)
   end
+
+  expose :forked_from_project_id, if: ->(project, _) { project.forked? },
+    documentation: { type: 'integer', example: 1 } do |project|
+    project.forked_from_project.id
+  end
 end