Commit b8d52a31 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'fix-compliance-pipeline-validation' into 'master'

Make ref parameter optional in get raw file api

See merge request gitlab-org/gitlab!58787
parents 6c18f7a8 1461199d
---
title: Make ref parameter optional in get raw file api
merge_request: 58787
author:
type: changed
...@@ -168,8 +168,8 @@ curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/a ...@@ -168,8 +168,8 @@ curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/a
Parameters: Parameters:
- `file_path` (required) - URL encoded full path to new file. Ex. lib%2Fclass%2Erb - `file_path` (required) - URL encoded full path to new file, such as lib%2Fclass%2Erb.
- `ref` (required) - The name of branch, tag or commit - `ref` (optional) - The name of branch, tag or commit. Default is the `HEAD` of the project.
NOTE: NOTE:
Like [Get file from repository](repository_files.md#get-file-from-repository) you can use `HEAD` to get just file metadata. Like [Get file from repository](repository_files.md#get-file-from-repository) you can use `HEAD` to get just file metadata.
......
...@@ -45,7 +45,7 @@ export const fetchPipelineConfigurationFileExists = async (path) => { ...@@ -45,7 +45,7 @@ export const fetchPipelineConfigurationFileExists = async (path) => {
} }
try { try {
const { status } = await Api.getRawFile(`${group}/${project}`, file); const { status } = await Api.getRawFile(`${group}/${project}`, file, { ref: undefined });
return status === httpStatus.OK; return status === httpStatus.OK;
} catch (e) { } catch (e) {
......
...@@ -113,7 +113,7 @@ module API ...@@ -113,7 +113,7 @@ module API
desc 'Get raw file metadata from repository' desc 'Get raw file metadata from repository'
params do params do
requires :file_path, type: String, file_path: true, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' requires :file_path, type: String, file_path: true, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false optional :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false
end end
head ":id/repository/files/:file_path/raw", requirements: FILE_ENDPOINT_REQUIREMENTS do head ":id/repository/files/:file_path/raw", requirements: FILE_ENDPOINT_REQUIREMENTS do
assign_file_vars! assign_file_vars!
...@@ -124,7 +124,7 @@ module API ...@@ -124,7 +124,7 @@ module API
desc 'Get raw file contents from the repository' desc 'Get raw file contents from the repository'
params do params do
requires :file_path, type: String, file_path: true, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' requires :file_path, type: String, file_path: true, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
requires :ref, type: String, desc: 'The name of branch, tag commit', allow_blank: false optional :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false
end end
get ":id/repository/files/:file_path/raw", requirements: FILE_ENDPOINT_REQUIREMENTS do get ":id/repository/files/:file_path/raw", requirements: FILE_ENDPOINT_REQUIREMENTS do
assign_file_vars! assign_file_vars!
......
...@@ -517,6 +517,21 @@ RSpec.describe API::Files do ...@@ -517,6 +517,21 @@ RSpec.describe API::Files do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end end
context 'when ref is not provided' do
before do
stub_application_setting(default_branch_name: 'main')
end
it 'returns response :ok', :aggregate_failures do
url = route(file_path) + "/raw"
expect(Gitlab::Workhorse).to receive(:send_git_blob)
get api(url, current_user), params: {}
expect(response).to have_gitlab_http_status(:ok)
end
end
it 'returns raw file info for files with dots' do it 'returns raw file info for files with dots' do
url = route('.gitignore') + "/raw" url = route('.gitignore') + "/raw"
expect(Gitlab::Workhorse).to receive(:send_git_blob) expect(Gitlab::Workhorse).to receive(:send_git_blob)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment