Commit ef047d07 authored by Sean McGivern's avatar Sean McGivern Committed by Douglas Barbosa Alexandre

Merge branch '4269-public-repositories-api' into 'master'

Allow Repositories API GET endpoints to be requested anonymously

Closes #4269

See merge request !8148
parent 3847f889
---
title: Allow Repositories API GET endpoints to be requested anonymously
merge_request: 8148
author:
......@@ -2,7 +2,8 @@
## List repository tree
Get a list of repository files and directories in a project.
Get a list of repository files and directories in a project. This endpoint can
be accessed without authentication if the repository is publicly accessible.
```
GET /projects/:id/repository/tree
......@@ -71,7 +72,8 @@ Parameters:
## Raw file content
Get the raw file contents for a file by commit SHA and path.
Get the raw file contents for a file by commit SHA and path. This endpoint can
be accessed without authentication if the repository is publicly accessible.
```
GET /projects/:id/repository/blobs/:sha
......@@ -85,7 +87,8 @@ Parameters:
## Raw blob content
Get the raw file contents for a blob by blob SHA.
Get the raw file contents for a blob by blob SHA. This endpoint can be accessed
without authentication if the repository is publicly accessible.
```
GET /projects/:id/repository/raw_blobs/:sha
......@@ -98,7 +101,8 @@ Parameters:
## Get file archive
Get an archive of the repository
Get an archive of the repository. This endpoint can be accessed without
authentication if the repository is publicly accessible.
```
GET /projects/:id/repository/archive
......@@ -111,6 +115,9 @@ Parameters:
## Compare branches, tags or commits
This endpoint can be accessed without authentication if the repository is
publicly accessible.
```
GET /projects/:id/repository/compare
```
......@@ -163,7 +170,8 @@ Response:
## Contributors
Get repository contributors list
Get repository contributors list. This endpoint can be accessed without
authentication if the repository is publicly accessible.
```
GET /projects/:id/repository/contributors
......
......@@ -2,7 +2,6 @@ require 'mime/types'
module API
class Repositories < Grape::API
before { authenticate! }
before { authorize! :download_code, user_project }
params do
......@@ -79,8 +78,6 @@ module API
optional :format, type: String, desc: 'The archive format'
end
get ':id/repository/archive', requirements: { format: Gitlab::Regex.archive_formats_regex } do
authorize! :download_code, user_project
begin
send_git_archive user_project.repository, ref: params[:sha], format: params[:format]
rescue
......@@ -96,7 +93,6 @@ module API
requires :to, type: String, desc: 'The commit, branch name, or tag name to stop comparison'
end
get ':id/repository/compare' do
authorize! :download_code, user_project
compare = Gitlab::Git::Compare.new(user_project.repository.raw_repository, params[:from], params[:to])
present compare, with: Entities::Compare
end
......@@ -105,8 +101,6 @@ module API
success Entities::Contributor
end
get ':id/repository/contributors' do
authorize! :download_code, user_project
begin
present user_project.repository.contributors,
with: Entities::Contributor
......
This diff is collapsed.
# Specs for status checking.
#
# Requires an API request:
# let(:request) { get api("/projects/#{project.id}/repository/branches", user) }
shared_examples_for '400 response' do
before do
# Fires the request
request
end
it 'returns 400' do
expect(response).to have_http_status(400)
end
end
shared_examples_for '403 response' do
before do
# Fires the request
request
end
it 'returns 403' do
expect(response).to have_http_status(403)
end
end
shared_examples_for '404 response' do
let(:message) { nil }
before do
# Fires the request
request
end
it 'returns 404' do
expect(response).to have_http_status(404)
expect(json_response).to be_an Object
if message.present?
expect(json_response['message']).to eq(message)
end
end
end
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