Bug Fix: Child pipelines are not found by API endpoints

What does this MR do?

Overview

Bug Behavior: When requesting child pipelines by pipeline id our pipeline api endpoints come back with a 404.

This MR changes that behavior so that requesting child pipelines by child pipeline id returns information about the child pipeline.

curl Request Before
▶ curl --globoff --header "PRIVATE-TOKEN: <t>" "http://host.docker.internal:3000/api/v4/projects/22/pipelines/48/jobs"
{"message":"404 Not found"}%
▶ curl --globoff --header "PRIVATE-TOKEN: <t>" "http://host.docker.internal:3000/api/v4/projects/22/pipelines/48"
{"message":"404 Not found"}%
curl Request After
~   ruby-2.6.3
▶ curl --globoff --header "PRIVATE-TOKEN: <t>" "http://host.docker.internal:3000/api/v4/projects/22/pipelines/48" | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1027  100  1027    0     0     29      0  0:00:35  0:00:35 --:--:--   250
{
   "detailed_status" : {
      "has_details" : false,
      "favicon" : "/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png",
      "label" : "passed",
      "tooltip" : "passed",
      "illustration" : null,
      "text" : "passed",
      "group" : "success",
      "icon" : "status_success",
      "details_path" : "/root/child-pipeline/-/pipelines/48"
   },
   "started_at" : "2020-07-10T18:26:00.865Z",
   "status" : "success",
   "ref" : "master",
   "user" : {
      "id" : 1,
      "state" : "active",
      "avatar_url" : "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
      "web_url" : "http://host.docker.internal:3000/root",
      "name" : "Administrator",
      "username" : "root"
   },
   "created_at" : "2020-07-10T18:25:55.816Z",
   "web_url" : "http://host.docker.internal:3000/root/child-pipeline/-/pipelines/48",
   "committed_at" : null,
   "id" : 48,
   "duration" : 14,
   "coverage" : null,
   "yaml_errors" : null,
   "updated_at" : "2020-07-10T18:26:16.011Z",
   "sha" : "9be10b71bbd034928c7ce4b26fdfb91f01e4532a",
   "before_sha" : "0000000000000000000000000000000000000000",
   "finished_at" : "2020-07-10T18:26:16.006Z",
   "tag" : false
}

▶ curl --globoff --header "PRIVATE-TOKEN: <t>" "http://host.docker.internal:3000/api/v4/projects/22/pipelines/48/jobs" | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1918  100  1918    0     0   7551      0 --:--:-- --:--:-- --:--:--  7551
[
   {
      "tag" : false,
      "duration" : 14.877372,
      "user" : {
         "twitter" : "",
         "username" : "root",
         "avatar_url" : "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
         "bio_html" : "",
         "public_email" : "",
         "location" : null,
         "id" : 1,
         "state" : "active",
         "skype" : "",
         "organization" : null,
         "work_information" : null,
         "website_url" : "",
         "job_title" : "",
         "web_url" : "http://host.docker.internal:3000/root",
         "linkedin" : "",
         "bio" : "",
         "created_at" : "2020-06-26T20:32:24.345Z",
         "name" : "Administrator"
      },
      "coverage" : null,
      "runner" : {
         "id" : 5,
         "name" : "gitlab-runner",
         "is_shared" : true,
         "active" : true,
         "online" : false,
         "description" : "new-3",
         "ip_address" : "127.0.0.1",
         "status" : "offline"
      },
      "id" : 750,
      "started_at" : "2020-07-10T18:26:00.349Z",
      "commit" : {
         "committer_name" : "Administrator",
         "short_id" : "9be10b71",
         "author_email" : "admin@example.com",
         "message" : "add child pipeline",
         "authored_date" : "2020-07-10T11:55:38.000-04:00",
         "committed_date" : "2020-07-10T11:55:38.000-04:00",
         "id" : "9be10b71bbd034928c7ce4b26fdfb91f01e4532a",
         "committer_email" : "admin@example.com",
         "title" : "add child pipeline",
         "created_at" : "2020-07-10T11:55:38.000-04:00",
         "parent_ids" : [
            "2b3f37bb9cf5502233b08bcfca53496e05ffd559"
         ],
         "web_url" : "http://host.docker.internal:3000/root/child-pipeline/-/commit/9be10b71bbd034928c7ce4b26fdfb91f01e4532a",
         "author_name" : "Administrator"
      },
      "finished_at" : "2020-07-10T18:26:15.226Z",
      "allow_failure" : false,
      "pipeline" : {
         "ref" : "master",
         "id" : 48,
         "updated_at" : "2020-07-10T18:26:16.011Z",
         "sha" : "9be10b71bbd034928c7ce4b26fdfb91f01e4532a",
         "web_url" : "http://host.docker.internal:3000/root/child-pipeline/-/pipelines/48",
         "status" : "success",
         "created_at" : "2020-07-10T18:25:55.816Z"
      },
      "status" : "success",
      "stage" : "child-stage1",
      "web_url" : "http://host.docker.internal:3000/root/child-pipeline/-/jobs/750",
      "artifacts" : [
         {
            "size" : 2297,
            "file_format" : null,
            "filename" : "job.log",
            "file_type" : "trace"
         }
      ],
      "ref" : "master",
      "name" : "child-job1",
      "created_at" : "2020-07-10T18:25:55.833Z",
      "artifacts_expire_at" : null
   }
]

Technical implementation

When finding the pipeline we are using project.ci_pipelines.find(params[:pipeline_id]) which shows "visible" (or "primary") pipelines.

To include child pipelines, we use: project.all_pipelines.find(params[:pipeline_id]). This will get all pipelines regardless of the config source.

Part of #207226 (closed)

Screenshots

Screen_Shot_2020-07-10_at_2.33.19_PM

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Allison Browne