2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
require 'mime/types'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe API::Repositories do
|
2014-09-02 18:07:02 +05:30
|
|
|
include RepoHelpers
|
2016-06-02 11:05:42 +05:30
|
|
|
include WorkhorseHelpers
|
2021-04-29 21:17:54 +05:30
|
|
|
include ProjectForksHelper
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:guest) { create(:user).tap { |u| create(:project_member, :guest, user: u, project: project) } }
|
|
|
|
let!(:project) { create(:project, :repository, creator: user) }
|
2018-11-18 11:00:15 +05:30
|
|
|
let!(:maintainer) { create(:project_member, :maintainer, user: user, project: project) }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
describe "GET /projects/:id/repository/tree" do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:route) { "/projects/#{project.id}/repository/tree" }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
shared_examples_for 'repository tree' do
|
|
|
|
it 'returns the repository tree' do
|
|
|
|
get api(route, current_user)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(response).to include_pagination_headers
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(json_response).to be_an(Array)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
first_commit = json_response.first
|
|
|
|
expect(first_commit['name']).to eq('bar')
|
|
|
|
expect(first_commit['type']).to eq('tree')
|
|
|
|
expect(first_commit['mode']).to eq('040000')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when ref does not exist' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api("#{route}?ref=foo", current_user) }
|
|
|
|
let(:message) { '404 Tree Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repository is disabled' do
|
|
|
|
include_context 'disabled repository'
|
|
|
|
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, current_user) }
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'with recursive=1' do
|
|
|
|
it 'returns recursive project paths tree' do
|
|
|
|
get api("#{route}?recursive=1", current_user)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response[4]['name']).to eq('html')
|
|
|
|
expect(json_response[4]['path']).to eq('files/html')
|
|
|
|
expect(json_response[4]['type']).to eq('tree')
|
|
|
|
expect(json_response[4]['mode']).to eq('040000')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repository is disabled' do
|
|
|
|
include_context 'disabled repository'
|
|
|
|
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, current_user) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when ref does not exist' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api("#{route}?recursive=1&ref=foo", current_user) }
|
|
|
|
let(:message) { '404 Tree Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
context 'keyset pagination mode' do
|
|
|
|
let(:first_response) do
|
|
|
|
get api(route, current_user), params: { pagination: "keyset" }
|
|
|
|
|
|
|
|
Gitlab::Json.parse(response.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'paginates using keysets' do
|
|
|
|
page_token = first_response.last["id"]
|
|
|
|
|
|
|
|
get api(route, current_user), params: { pagination: "keyset", page_token: page_token }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response).to be_an(Array)
|
|
|
|
expect(json_response).not_to eq(first_response)
|
|
|
|
expect(json_response.map { |t| t["id"] }).not_to include(page_token)
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated', 'and project is public' do
|
|
|
|
it_behaves_like 'repository tree' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:current_user) { nil }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api(route) }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a developer' do
|
|
|
|
it_behaves_like 'repository tree' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, guest) }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/repository/blobs/:sha" do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:route) { "/projects/#{project.id}/repository/blobs/#{sample_blob.oid}" }
|
|
|
|
|
|
|
|
shared_examples_for 'repository blob' do
|
|
|
|
it 'returns blob attributes as json' do
|
2021-10-27 15:23:28 +05:30
|
|
|
stub_const("Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE", 5)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
get api(route, current_user)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response['size']).to eq(111)
|
|
|
|
expect(json_response['encoding']).to eq("base64")
|
|
|
|
expect(json_response['sha']).to eq(sample_blob.oid)
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
content = Base64.decode64(json_response['content'])
|
|
|
|
expect(content.lines.first).to eq("class Commit\n")
|
|
|
|
expect(content).to eq(project.repository.gitaly_blob_client.get_blob(oid: sample_blob.oid, limit: -1).data)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when sha does not exist' do
|
|
|
|
it_behaves_like '404 response' do
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:request) { get api(route.sub(sample_blob.oid, 'abcd9876'), current_user) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:message) { '404 Blob Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repository is disabled' do
|
|
|
|
include_context 'disabled repository'
|
|
|
|
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, current_user) }
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when unauthenticated', 'and project is public' do
|
|
|
|
it_behaves_like 'repository blob' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api(route) }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when authenticated', 'as a developer' do
|
|
|
|
it_behaves_like 'repository blob' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, guest) }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe "GET /projects/:id/repository/blobs/:sha/raw" do
|
|
|
|
let(:route) { "/projects/#{project.id}/repository/blobs/#{sample_blob.oid}/raw" }
|
|
|
|
|
|
|
|
shared_examples_for 'repository raw blob' do
|
|
|
|
it 'returns the repository raw blob' do
|
2021-10-27 15:23:28 +05:30
|
|
|
expect(Gitlab::Workhorse).to receive(:send_git_blob) do |_, blob|
|
|
|
|
expect(blob.id).to eq(sample_blob.oid)
|
|
|
|
expect(blob.loaded_size).to eq(0)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
get api(route, current_user)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true"
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(response.parsed_body).to be_empty
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
it 'sets inline content disposition by default' do
|
2019-02-15 15:39:39 +05:30
|
|
|
get api(route, current_user)
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(headers['Content-Disposition']).to eq 'inline'
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it 'defines an uncached header response' do
|
|
|
|
get api(route, current_user)
|
|
|
|
|
|
|
|
expect(response.headers["Cache-Control"]).to eq("max-age=0, private, must-revalidate, no-store, no-cache")
|
|
|
|
expect(response.headers["Pragma"]).to eq("no-cache")
|
|
|
|
expect(response.headers["Expires"]).to eq("Fri, 01 Jan 1990 00:00:00 GMT")
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when sha does not exist' do
|
|
|
|
it_behaves_like '404 response' do
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:request) { get api(route.sub(sample_blob.oid, 'abcd9876'), current_user) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:message) { '404 Blob Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repository is disabled' do
|
|
|
|
include_context 'disabled repository'
|
|
|
|
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, current_user) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated', 'and project is public' do
|
|
|
|
it_behaves_like 'repository raw blob' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api(route) }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when authenticated', 'as a developer' do
|
|
|
|
it_behaves_like 'repository raw blob' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, guest) }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/repository/archive(.:format)?:sha" do
|
2020-07-28 23:09:34 +05:30
|
|
|
let(:project_id) { CGI.escape(project.full_path) }
|
|
|
|
let(:route) { "/projects/#{project_id}/repository/archive" }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
before do
|
|
|
|
allow(::Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(false)
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
shared_examples_for 'repository archive' do
|
|
|
|
it 'returns the repository archive' do
|
|
|
|
get api(route, current_user)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
type, params = workhorse_send_data
|
|
|
|
|
|
|
|
expect(type).to eq('git-archive')
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.tar.gz/)
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(response.parsed_body).to be_empty
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the repository archive archive.zip' do
|
2020-07-28 23:09:34 +05:30
|
|
|
get api("/projects/#{project_id}/repository/archive.zip", user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
type, params = workhorse_send_data
|
|
|
|
|
|
|
|
expect(type).to eq('git-archive')
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.zip/)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the repository archive archive.tar.bz2' do
|
2020-07-28 23:09:34 +05:30
|
|
|
get api("/projects/#{project_id}/repository/archive.tar.bz2", user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
type, params = workhorse_send_data
|
|
|
|
|
|
|
|
expect(type).to eq('git-archive')
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.tar.bz2/)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when sha does not exist' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api("#{route}?sha=xxx", current_user) }
|
|
|
|
let(:message) { '404 File Not Found' }
|
|
|
|
end
|
|
|
|
end
|
2020-03-28 13:19:24 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
it 'returns only a part of the repository with path set' do
|
|
|
|
path = 'bar'
|
|
|
|
get api("#{route}?path=#{path}", current_user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
|
|
|
|
type, params = workhorse_send_data
|
|
|
|
|
|
|
|
expect(type).to eq('git-archive')
|
|
|
|
expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\-#{path}\.tar.gz/)
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it 'rate limits user when thresholds hit' do
|
|
|
|
allow(::Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(true)
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
get api("/projects/#{project_id}/repository/archive.tar.bz2", user)
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:too_many_requests)
|
|
|
|
end
|
|
|
|
|
2020-03-28 13:19:24 +05:30
|
|
|
context "when hotlinking detection is enabled" do
|
|
|
|
before do
|
2020-06-23 00:09:42 +05:30
|
|
|
stub_feature_flags(repository_archive_hotlinking_interception: true)
|
2020-03-28 13:19:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like "hotlink interceptor" do
|
|
|
|
let(:http_request) do
|
|
|
|
get api(route, current_user), headers: headers
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated', 'and project is public' do
|
|
|
|
it_behaves_like 'repository archive' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
context 'when unauthenticated and project path has dots' do
|
|
|
|
it_behaves_like 'repository archive' do
|
|
|
|
let(:project) { create(:project, :public, :repository, path: 'path.with.dot') }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api(route) }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when authenticated', 'as a developer' do
|
|
|
|
it_behaves_like 'repository archive' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, guest) }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects/:id/repository/compare' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:route) { "/projects/#{project.id}/repository/compare" }
|
|
|
|
|
|
|
|
shared_examples_for 'repository compare' do
|
|
|
|
it "compares branches" do
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(::Gitlab::Git::Compare).to receive(:new).with(anything, anything, anything, {
|
|
|
|
straight: false
|
|
|
|
}).and_call_original
|
2019-02-15 15:39:39 +05:30
|
|
|
get api(route, current_user), params: { from: 'master', to: 'feature' }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(json_response['web_url']).to be_present
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it "compares branches with explicit merge-base mode" do
|
|
|
|
expect(::Gitlab::Git::Compare).to receive(:new).with(anything, anything, anything, {
|
|
|
|
straight: false
|
|
|
|
}).and_call_original
|
2019-02-15 15:39:39 +05:30
|
|
|
get api(route, current_user), params: { from: 'master', to: 'feature', straight: false }
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(json_response['web_url']).to be_present
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "compares branches with explicit straight mode" do
|
|
|
|
expect(::Gitlab::Git::Compare).to receive(:new).with(anything, anything, anything, {
|
|
|
|
straight: true
|
|
|
|
}).and_call_original
|
2019-02-15 15:39:39 +05:30
|
|
|
get api(route, current_user), params: { from: 'master', to: 'feature', straight: true }
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(json_response['web_url']).to be_present
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it "compares tags" do
|
2019-02-15 15:39:39 +05:30
|
|
|
get api(route, current_user), params: { from: 'v1.0.0', to: 'v1.1.0' }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(json_response['web_url']).to be_present
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "compares commits" do
|
2019-02-15 15:39:39 +05:30
|
|
|
get api(route, current_user), params: { from: sample_commit.id, to: sample_commit.parent_id }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response['commits']).to be_empty
|
|
|
|
expect(json_response['diffs']).to be_empty
|
|
|
|
expect(json_response['compare_same_ref']).to be_falsey
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(json_response['web_url']).to be_present
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "compares commits in reverse order" do
|
2019-02-15 15:39:39 +05:30
|
|
|
get api(route, current_user), params: { from: sample_commit.parent_id, to: sample_commit.id }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(json_response['web_url']).to be_present
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it "compare commits between different projects with non-forked relation" do
|
|
|
|
public_project = create(:project, :repository, :public)
|
|
|
|
|
|
|
|
get api(route, current_user), params: { from: sample_commit.parent_id, to: sample_commit.id, from_project_id: public_project.id }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "compare commits between different projects" do
|
|
|
|
group = create(:group)
|
|
|
|
group.add_owner(current_user)
|
|
|
|
|
|
|
|
forked_project = fork_project(project, current_user, repository: true, namespace: group)
|
|
|
|
forked_project.repository.create_ref('refs/heads/improve/awesome', 'refs/heads/improve/more-awesome')
|
|
|
|
|
|
|
|
get api(route, current_user), params: { from: 'improve/awesome', to: 'feature', from_project_id: forked_project.id }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it "compares same refs" do
|
2019-02-15 15:39:39 +05:30
|
|
|
get api(route, current_user), params: { from: 'master', to: 'master' }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response['commits']).to be_empty
|
|
|
|
expect(json_response['diffs']).to be_empty
|
|
|
|
expect(json_response['compare_same_ref']).to be_truthy
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
it "returns an empty string when the diff overflows" do
|
2021-01-03 14:25:43 +05:30
|
|
|
allow(Gitlab::Git::DiffCollection)
|
|
|
|
.to receive(:default_limits)
|
|
|
|
.and_return({ max_files: 2, max_lines: 2 })
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
get api(route, current_user), params: { from: 'master', to: 'feature' }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
|
|
|
expect(json_response['diffs'].first['diff']).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a 404 when from ref is unknown" do
|
|
|
|
get api(route, current_user), params: { from: 'unknown_ref', to: 'master' }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a 404 when to ref is unknown" do
|
|
|
|
get api(route, current_user), params: { from: 'master', to: 'unknown_ref' }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
it "returns a newly created commit", :use_clean_rails_redis_caching do
|
|
|
|
# Parse the commits ourselves because json_response is cached
|
|
|
|
def commit_messages(response)
|
|
|
|
Gitlab::Json.parse(response.body)["commits"].map do |commit|
|
|
|
|
commit["message"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# First trigger the rate limit cache
|
|
|
|
get api(route, current_user), params: { from: 'master', to: 'feature' }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(commit_messages(response)).not_to include("Cool new commit")
|
|
|
|
|
|
|
|
# Then create a new commit via the API
|
|
|
|
post api("/projects/#{project.id}/repository/commits", user), params: {
|
|
|
|
branch: "feature",
|
|
|
|
commit_message: "Cool new commit",
|
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
action: "create",
|
|
|
|
file_path: "foo/bar/baz.txt",
|
|
|
|
content: "puts 8"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
|
|
|
|
|
|
|
# Now perform the same query as before, but the cache should have expired
|
|
|
|
# and our new commit should exist
|
|
|
|
get api(route, current_user), params: { from: 'master', to: 'feature' }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(commit_messages(response)).to include("Cool new commit")
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when unauthenticated', 'and project is public' do
|
|
|
|
it_behaves_like 'repository compare' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api(route) }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when authenticated', 'as a developer' do
|
|
|
|
it_behaves_like 'repository compare' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, guest) }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects/:id/repository/contributors' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:route) { "/projects/#{project.id}/repository/contributors" }
|
|
|
|
|
|
|
|
shared_examples_for 'repository contributors' do
|
|
|
|
it 'returns valid data' do
|
|
|
|
get api(route, current_user)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
|
|
|
|
first_contributor = json_response.first
|
|
|
|
expect(first_contributor['email']).to eq('tiagonbotelho@hotmail.com')
|
|
|
|
expect(first_contributor['name']).to eq('tiagonbotelho')
|
|
|
|
expect(first_contributor['commits']).to eq(1)
|
|
|
|
expect(first_contributor['additions']).to eq(0)
|
|
|
|
expect(first_contributor['deletions']).to eq(0)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
context 'using sorting' do
|
|
|
|
context 'by commits desc' do
|
|
|
|
it 'returns the repository contribuors sorted by commits desc' do
|
2019-02-15 15:39:39 +05:30
|
|
|
get api(route, current_user), params: { order_by: 'commits', sort: 'desc' }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to match_response_schema('contributors')
|
|
|
|
expect(json_response.first['commits']).to be > json_response.last['commits']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'by name desc' do
|
|
|
|
it 'returns the repository contribuors sorted by name asc case insensitive' do
|
2019-02-15 15:39:39 +05:30
|
|
|
get api(route, current_user), params: { order_by: 'name', sort: 'asc' }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to match_response_schema('contributors')
|
|
|
|
expect(json_response.first['name'].downcase).to be < json_response.last['name'].downcase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated', 'and project is public' do
|
|
|
|
it_behaves_like 'repository contributors' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api(route) }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a developer' do
|
|
|
|
it_behaves_like 'repository contributors' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, guest) }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
# Regression: https://gitlab.com/gitlab-org/gitlab-foss/issues/45363
|
2018-05-09 12:01:36 +05:30
|
|
|
describe 'Links header contains working URLs when no `order_by` nor `sort` is given' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
|
|
|
it 'returns `Link` header that includes URLs with default value for `order_by` & `sort`' do
|
|
|
|
get api(route, current_user)
|
|
|
|
|
|
|
|
first_link_url = response.headers['Link'].split(';').first
|
|
|
|
|
|
|
|
expect(first_link_url).to include('order_by=commits')
|
|
|
|
expect(first_link_url).to include('sort=asc')
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
describe 'GET :id/repository/merge_base' do
|
|
|
|
let(:refs) do
|
2018-12-13 13:39:08 +05:30
|
|
|
%w(304d257dcb821665ab5110318fc58a007bd104ed 0031876facac3f2b2702a0e53a26e89939a42209 570e7b2abdd848b95f2f578043fc23bd6f6fd24d)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
subject(:request) do
|
2019-02-15 15:39:39 +05:30
|
|
|
get(api("/projects/#{project.id}/repository/merge_base", current_user), params: { refs: refs })
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'merge base' do
|
|
|
|
it 'returns the common ancestor' do
|
|
|
|
request
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
expect(json_response['id']).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated', 'and project is public' do
|
|
|
|
it_behaves_like 'merge base' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:current_user) { nil }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a developer' do
|
|
|
|
it_behaves_like 'merge base' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passing refs that do not exist' do
|
|
|
|
it_behaves_like '400 response' do
|
|
|
|
let(:refs) { %w(304d257dcb821665ab5110318fc58a007bd104ed missing) }
|
|
|
|
let(:current_user) { user }
|
|
|
|
let(:message) { 'Could not find ref: missing' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passing refs that do not have a merge base' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:refs) { ['304d257dcb821665ab5110318fc58a007bd104ed', TestEnv::BRANCH_SHA['orphaned-branch']] }
|
|
|
|
let(:current_user) { user }
|
|
|
|
let(:message) { '404 Merge Base Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not enough refs are passed' do
|
|
|
|
let(:refs) { %w(only-one) }
|
|
|
|
let(:current_user) { user }
|
|
|
|
|
|
|
|
it 'renders a bad request error' do
|
|
|
|
request
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(json_response['message']).to eq('Provide at least 2 refs')
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
describe 'GET /projects/:id/repository/changelog' do
|
|
|
|
it 'generates the changelog for a version' do
|
|
|
|
spy = instance_spy(Repositories::ChangelogService)
|
|
|
|
release_notes = 'Release notes'
|
|
|
|
|
|
|
|
allow(Repositories::ChangelogService)
|
|
|
|
.to receive(:new)
|
|
|
|
.with(
|
|
|
|
project,
|
|
|
|
user,
|
|
|
|
version: '1.0.0',
|
|
|
|
from: 'foo',
|
|
|
|
to: 'bar',
|
|
|
|
date: DateTime.new(2020, 1, 1),
|
|
|
|
trailer: 'Foo'
|
|
|
|
)
|
|
|
|
.and_return(spy)
|
|
|
|
|
|
|
|
expect(spy).to receive(:execute).with(commit_to_changelog: false).and_return(release_notes)
|
|
|
|
|
|
|
|
get(
|
|
|
|
api("/projects/#{project.id}/repository/changelog", user),
|
|
|
|
params: {
|
|
|
|
version: '1.0.0',
|
|
|
|
from: 'foo',
|
|
|
|
to: 'bar',
|
|
|
|
date: '2020-01-01',
|
|
|
|
trailer: 'Foo'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response['notes']).to eq(release_notes)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'supports leaving out the from and to attribute' do
|
|
|
|
spy = instance_spy(Repositories::ChangelogService)
|
|
|
|
|
|
|
|
allow(Repositories::ChangelogService)
|
|
|
|
.to receive(:new)
|
|
|
|
.with(
|
|
|
|
project,
|
|
|
|
user,
|
|
|
|
version: '1.0.0',
|
|
|
|
date: DateTime.new(2020, 1, 1),
|
|
|
|
trailer: 'Foo'
|
|
|
|
)
|
|
|
|
.and_return(spy)
|
|
|
|
|
|
|
|
expect(spy).to receive(:execute).with(commit_to_changelog: false)
|
|
|
|
|
|
|
|
get(
|
|
|
|
api("/projects/#{project.id}/repository/changelog", user),
|
|
|
|
params: {
|
|
|
|
version: '1.0.0',
|
|
|
|
date: '2020-01-01',
|
|
|
|
trailer: 'Foo'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response['notes']).to be_present
|
|
|
|
end
|
2022-05-07 20:08:51 +05:30
|
|
|
|
|
|
|
context 'when previous tag version does not exist' do
|
|
|
|
it_behaves_like '422 response' do
|
|
|
|
let(:request) { get api("/projects/#{project.id}/repository/changelog", user), params: { version: 'v0.0.0' } }
|
|
|
|
let(:message) { 'Failed to generate the changelog: The commit start range is unspecified, and no previous tag could be found to use instead' }
|
|
|
|
end
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
describe 'POST /projects/:id/repository/changelog' do
|
|
|
|
it 'generates the changelog for a version' do
|
|
|
|
spy = instance_spy(Repositories::ChangelogService)
|
|
|
|
|
|
|
|
allow(Repositories::ChangelogService)
|
|
|
|
.to receive(:new)
|
|
|
|
.with(
|
|
|
|
project,
|
|
|
|
user,
|
|
|
|
version: '1.0.0',
|
|
|
|
from: 'foo',
|
|
|
|
to: 'bar',
|
|
|
|
date: DateTime.new(2020, 1, 1),
|
|
|
|
branch: 'kittens',
|
|
|
|
trailer: 'Foo',
|
|
|
|
file: 'FOO.md',
|
|
|
|
message: 'Commit message'
|
|
|
|
)
|
|
|
|
.and_return(spy)
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
allow(spy).to receive(:execute).with(commit_to_changelog: true)
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
post(
|
|
|
|
api("/projects/#{project.id}/repository/changelog", user),
|
|
|
|
params: {
|
|
|
|
version: '1.0.0',
|
|
|
|
from: 'foo',
|
|
|
|
to: 'bar',
|
|
|
|
date: '2020-01-01',
|
|
|
|
branch: 'kittens',
|
|
|
|
trailer: 'Foo',
|
|
|
|
file: 'FOO.md',
|
|
|
|
message: 'Commit message'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'supports leaving out the from and to attribute' do
|
|
|
|
spy = instance_spy(Repositories::ChangelogService)
|
|
|
|
|
|
|
|
allow(Repositories::ChangelogService)
|
|
|
|
.to receive(:new)
|
|
|
|
.with(
|
|
|
|
project,
|
|
|
|
user,
|
|
|
|
version: '1.0.0',
|
|
|
|
date: DateTime.new(2020, 1, 1),
|
|
|
|
branch: 'kittens',
|
|
|
|
trailer: 'Foo',
|
|
|
|
file: 'FOO.md',
|
|
|
|
message: 'Commit message'
|
|
|
|
)
|
|
|
|
.and_return(spy)
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
expect(spy).to receive(:execute).with(commit_to_changelog: true)
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
post(
|
|
|
|
api("/projects/#{project.id}/repository/changelog", user),
|
|
|
|
params: {
|
|
|
|
version: '1.0.0',
|
|
|
|
date: '2020-01-01',
|
|
|
|
branch: 'kittens',
|
|
|
|
trailer: 'Foo',
|
|
|
|
file: 'FOO.md',
|
|
|
|
message: 'Commit message'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it 'produces an error when generating the changelog fails' do
|
|
|
|
spy = instance_spy(Repositories::ChangelogService)
|
|
|
|
|
|
|
|
allow(Repositories::ChangelogService)
|
|
|
|
.to receive(:new)
|
|
|
|
.with(
|
|
|
|
project,
|
|
|
|
user,
|
|
|
|
version: '1.0.0',
|
|
|
|
from: 'foo',
|
|
|
|
to: 'bar',
|
|
|
|
date: DateTime.new(2020, 1, 1),
|
|
|
|
branch: 'kittens',
|
|
|
|
trailer: 'Foo',
|
|
|
|
file: 'FOO.md',
|
|
|
|
message: 'Commit message'
|
|
|
|
)
|
|
|
|
.and_return(spy)
|
|
|
|
|
|
|
|
allow(spy)
|
|
|
|
.to receive(:execute)
|
|
|
|
.and_raise(Gitlab::Changelog::Error.new('oops'))
|
|
|
|
|
|
|
|
post(
|
|
|
|
api("/projects/#{project.id}/repository/changelog", user),
|
|
|
|
params: {
|
|
|
|
version: '1.0.0',
|
|
|
|
from: 'foo',
|
|
|
|
to: 'bar',
|
|
|
|
date: '2020-01-01',
|
|
|
|
branch: 'kittens',
|
|
|
|
trailer: 'Foo',
|
|
|
|
file: 'FOO.md',
|
|
|
|
message: 'Commit message'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:unprocessable_entity)
|
|
|
|
expect(json_response['message']).to eq('Failed to generate the changelog: oops')
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|