Skip to content

Commit

Permalink
Complete the Remote Mirrors endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Balasankar 'Balu' C <[email protected]>
  • Loading branch information
Balasankar 'Balu' C committed Oct 30, 2024
1 parent bcfeb45 commit 5ff0448
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/gitlab/client/remote_mirrors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ def remote_mirrors(project)
get("/projects/#{url_encode project}/remote_mirrors")
end

# Get a specific remote mirror.
#
# @example
# Gitlab.remote_mirror(42, 1234)
#
# @param [Integer, String] project The ID or path of a project.
# @param [Integer] id The ID of the remote mirror.
#
# @return [Gitlab::ObjectifiedHash] Information about the specified remote mirror.
def remote_mirror(project, id)
get("/projects/#{url_encode project}/remote_mirrors/#{id}")
end

# Create a remote mirror
#
# @example
Expand Down Expand Up @@ -47,5 +60,31 @@ def create_remote_mirror(project, url, options = {})
def edit_remote_mirror(project, id, options = {})
put("/projects/#{url_encode project}/remote_mirrors/#{id}", body: options)
end

# Delete a remote mirror.
#
# @example
# Gitlab.delete_remote_mirror(42, 1234)
#
# @param [Integer, String] project The ID or path of a project.
# @param [Integer] id The ID of the remote mirror.
#
# @return [Gitlab::ObjectifiedHash]
def delete_remote_mirror(project, id)
delete("/projects/#{url_encode project}/remote_mirrors/#{id}")
end

# Force push mirror update.
#
# @example
# Gitlab.sync_remote_mirror(42, 1234)
#
# @param [Integer, String] project The ID or path of a project.
# @param [Integer] id The ID of the remote mirror.
#
# @return [Gitlab::ObjectifiedHash]
def sync_remote_mirror(project, id)
post("/projects/#{url_encode project}/remote_mirrors/#{id}/sync")
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/remote_mirror.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"enabled":true,"id":123456,"keep_divergent_refs":true,"last_error":"Some refs have diverged and have not been updated on the remote:\n\nrefs/heads/master","last_successful_update_at":"2020-08-11T15:36:04.668Z","last_update_at":"2020-08-11T15:37:20.701Z","last_update_started_at":"2020-08-11T15:37:17.659Z","only_protected_branches":true,"update_status":"failed","url":"https://*****:*****@gitlab.com/mirror/target.git"}
47 changes: 47 additions & 0 deletions spec/gitlab/client/remote_mirrors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
end
end

describe '.remote_mirror' do
before do
stub_get('/projects/5/remote_mirrors/123456', 'remote_mirror')
@mirror = Gitlab.remote_mirror(5, 123_456)
end

it 'gets the correct resource' do
expect(a_get('/projects/5/remote_mirrors/123456')).to have_been_made
end

it "returns a paginated response of project's push mirrors" do
expect(@mirror).to be_a Gitlab::ObjectifiedHash
expect(@mirror.enabled).to be(true)
expect(@mirror.url).to include('gitlab.com/mirror/target.git')
end
end

describe '.create_remote_mirror' do
let(:api_path) { '/projects/5/remote_mirrors' }
let(:mirror_path) { 'https://username:[email protected]/gitlab/example.git' }
Expand Down Expand Up @@ -67,4 +84,34 @@
expect(@mirror.keep_divergent_refs).to be(true)
end
end

describe '.delete_remote_mirror' do
before do
stub_request(:delete, "#{Gitlab.endpoint}/projects/5/remote_mirrors/123456")
.with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
.to_return(status: 204)
@mirror = Gitlab.delete_remote_mirror(5, 123_456)
end

it 'deletes the correct resource' do
expect(a_delete('/projects/5/remote_mirrors/123456')).to have_been_made
end

it 'removes the mirror' do
expect(@mirror.to_h).to be_empty
end
end

describe '.sync_remote_mirror' do
before do
stub_request(:post, "#{Gitlab.endpoint}/projects/5/remote_mirrors/123456/sync")
.with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
.to_return(status: 204)
@mirror = Gitlab.sync_remote_mirror(5, 123_456)
end

it 'executes a POST to the correct resource' do
expect(a_post('/projects/5/remote_mirrors/123456/sync')).to have_been_made
end
end
end

0 comments on commit 5ff0448

Please sign in to comment.