Use file_path parameter instead of url encoding in repository files api
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Description
Seems like there has been some confusion, problems with url encoding when using the repository files api. Getting files require url encoding which is harder/confusing with files within subfolders.
For example from the api docs:
file_path (required) - Url encoded full path to new file. Ex. lib%2Fclass%2Erb
Proposal
Update existing, or add additional endpoint that doesn't use the file as part of request endpoint.
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/api/files.rb#L63
For example, I tested adding this:
desc 'Get raw file contents from the repository'
params do
requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
requires :ref, type: String, desc: 'The name of branch, tag commit'
end
get ":id/repository/files/raw", requirements: FILE_ENDPOINT_REQUIREMENTS do
assign_file_vars!
send_git_blob @repo, @blob
end
Couple example requests with this vs current url encoding.
curl --request GET --header $TOKEN "http://$URI/api/v4/projects/13/repository/files/raw?ref=master&file_path=directory/test.rb"
curl --request GET --header $TOKEN "http://$URI/api/v4/projects/13/repository/files/directory%2Ftest%2Erb/raw?ref=master"
import requests
url = "http://gitlab/api/v4/projects/13/repository/files/raw"
payload = {'file_path': 'directory/test.rb', 'ref': 'master'}
r = requests.get(url,headers=headers, params=payload)
print r.text
url = "http://gitlab/api/v4/projects/13/repository/files/directory%2Ftest%2Erb/raw"
payload = {'ref': 'master'}
r = requests.get(url,headers=headers, params=payload)
print r.text
Links / references
Internal Zendesk: https://gitlab.zendesk.com/agent/tickets/90060
Edited by 🤖 GitLab Bot 🤖