Skip to content

[BUG] unidiff params does not work as described in doc

Summary

unidiff params does not work as described in doc.

Doc: https://docs.gitlab.com/ee/api/merge_requests.html#get-a-single-merge-request-diff-version

Steps to reproduce

  1. Fetch code diffs through MR versions/:id API with unidiff=false
curl --location 'https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/merge_requests/166562/versions/1124715671?unidiff=false' \
--header 'PRIVATE-TOKEN: PAT'
  1. Fetch code diffs through MR versions/:id API with unidiff=true
curl --location 'https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/merge_requests/166562/versions/1124715671?unidiff=true' \
--header 'PRIVATE-TOKEN: PAT'

They were supposed to return different results.

By the way, diffs API is correct.

curl --location 'https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/merge_requests/166562/diffs?unidiff=false' \
--header 'PRIVATE-TOKEN: PAT'

Related Source Code: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/api/merge_request_diffs.rb#L46-49

      get ":id/merge_requests/:merge_request_iid/versions/:version_id", urgency: :low do
        merge_request = find_merge_request_with_access(params[:merge_request_iid])

        present_cached merge_request.merge_request_diffs.find(params[:version_id]), with: Entities::MergeRequestDiffFull, cache_context: nil, enable_unidiff: declared_params[:unidiff]
      end

Example Project

!166561 (diffs)

What is the current bug behavior?

Using opposite parameters yielded the same result.

What is the expected correct behavior?

Using opposite parameters yielded different results.

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

Edited by 🤖 GitLab Bot 🤖