Gitlab API repository file endpoint doesn't work with commit
Hi
I've been trying to use gitlab repository_files
api which suggests that we can use :
Parameters:
-
file_path
(required) - Url encoded full path to new file. Ex. lib%2Fclass%2Erb -
ref
(required) - The name of branch, tag orcommit
Summary
When I'm requesting this endpoint
with ref
as commit id
it always send back the requested file from master
branch.
Steps to reproduce
- I have only one branch
master
in repository at self hosted gitlab-omnibus - Add a file to repository, copy the commit id (let's call it
commit1
). - Update the same file, commit and push it to repository (let's call it
commit2
). - Use
repository_files
API endpoint to retrieve blob of this file withref=commit1
- The blob you'll get will be of
commit2
(where my currentHEAD
is).
Example API call :
https://wwww.example.com/gitlab/api/v4/projects/111/repository/files/.gitlab-ci.yml?ref=fe6c65e95928b8e9cfa1c16800c9a2f8de95c23a
Also API documentation suggests that ref
is a mandatory parameter however even if you don't pass, it will send the file from master
.
Example Project
NA
What is the current bug behavior?
API is giving incorrect result.
What is the expected correct behavior?
API should have responded with the file from mentioned commit
.
Relevant logs and/or screenshots
NA
Output of checks
NA
Results of GitLab environment info
Expand for output related to GitLab environment info
Gitlab Version : GitLab Community Edition 12.1.8 Installation Type : Omnibus Operating System : Ubuntu18.04 LTSResults 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
(If you can, link to the line of code that might be responsible for the problem)