Single commit API returns wrong last_pipeline with wrong ref

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

Commits API ignores ref when fetching last_pipeline, which may result in wrong pipeline being reported as explained in cli#7465 (comment 2316644592)

Request https://git.xxx/api/v4/projects/153/repository/commits/master (docs https://docs.gitlab.com/ee/api/commits.html#get-a-single-commit) (note ref=master) returns wrong pipeline and wrong ref (ref=fcmanut-2167) .

{
  "id": "319dec0b84b69d73789f6ea40eb44e4f5acc6a3d",
  "short_id": "319dec0b",
  "created_at": "2025-01-22T15:52:26.000-03:00",
  "parent_ids": [
    "74c4d8a7ed14c72bec942208d721939c2b6b034d"
  ],
  "title": "Jira#CONFORM-29 - Consulta pública de Conformidade Tributária",
  "message": "Jira#CONFORM-29 - Consulta pública de Conformidade Tributária\n",
  "author_name": "xxx",
  "author_email": "xxx",
  "authored_date": "2025-01-22T15:52:26.000-03:00",
  "committer_name": "xxx",
  "committer_email": "xxx",
  "committed_date": "2025-01-22T15:52:26.000-03:00",
  "trailers": {

  },
  "extended_trailers": {

  },
  "web_url": "https://git.xxx/xxx/xxx-utilitarios/-/commit/319dec0b84b69d73789f6ea40eb44e4f5acc6a3d",
  "stats": {
    "additions": 100,
    "deletions": 14,
    "total": 114
  },
  "status": "skipped",
  "project_id": 153,
  "last_pipeline": {
    "id": 894634,
    "iid": 31789,
    "project_id": 153,
    "sha": "319dec0b84b69d73789f6ea40eb44e4f5acc6a3d",
    "ref": "fcmanut-2167",
    "status": "skipped",
    "source": "push",
    "created_at": "2025-01-27T14:22:52.342-03:00",
    "updated_at": "2025-01-27T14:22:52.342-03:00",
    "web_url": "https://git.xxx/xxx/xxx-utilitarios/-/pipelines/894634"
  }
}

Steps to reproduce

  1. Make commit appear on two branches. Like pull it to other branch from main to trigger pipeline.
  2. Make sure pipeline for the second branch is later than master.
  3. Run https://git.xxx/api/v4/projects/153/repository/commits/master but for your project
  4. See that master was replaced with another branch in last_pipeline.

Example Project

What is the current bug behavior?

What is the expected correct behavior?

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Most likely ref is not taken into account and last_pipeline is requested using commit hash only.

Edited by 🤖 GitLab Bot 🤖