From ed51ca5a93a481323f9aa09b589e200965cefe04 Mon Sep 17 00:00:00 2001 From: Matthias Baur Date: Thu, 1 Jul 2021 08:59:15 +0200 Subject: [PATCH] Implement get deploy tokens of project --- lib/gitlab/client/projects.rb | 11 +++++++++++ spec/fixtures/project_deploy_tokens.json | 1 + spec/gitlab/client/projects_spec.rb | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 spec/fixtures/project_deploy_tokens.json diff --git a/lib/gitlab/client/projects.rb b/lib/gitlab/client/projects.rb index 1964203b5..36cc245a9 100644 --- a/lib/gitlab/client/projects.rb +++ b/lib/gitlab/client/projects.rb @@ -693,5 +693,16 @@ def add_project_custom_attribute(key, value, project_id) def delete_project_custom_attribute(key, project_id = nil) delete("/projects/#{project_id}/custom_attributes/#{key}") end + + # List project deploy tokens + # + # @example + # Gitlab.project_deploy_tokens(42) + # + # @param [Integer, String] id The ID or path of a project. + # @option options [Boolean] :active Limit by active status. Optional. + def project_deploy_tokens(project, options = {}) + get("/projects/#{url_encode project}/deploy_tokens", query: options) + end end end diff --git a/spec/fixtures/project_deploy_tokens.json b/spec/fixtures/project_deploy_tokens.json new file mode 100644 index 000000000..c1626697d --- /dev/null +++ b/spec/fixtures/project_deploy_tokens.json @@ -0,0 +1 @@ +[{"id":93,"name":"foo","username":"gitlab+deploy-token-93","expires_at":null,"scopes":["read_repository"],"revoked":false,"expired":false}] diff --git a/spec/gitlab/client/projects_spec.rb b/spec/gitlab/client/projects_spec.rb index 481809946..fefab1e4c 100644 --- a/spec/gitlab/client/projects_spec.rb +++ b/spec/gitlab/client/projects_spec.rb @@ -909,4 +909,20 @@ end end end + + describe '.project_deploy_tokens' do + before do + stub_get('/projects/2/deploy_tokens', 'project_deploy_tokens') + @custom_attributes = Gitlab.project_deploy_tokens(2) + end + + it 'gets the correct resource' do + expect(a_get('/projects/2/deploy_tokens')).to have_been_made + end + + it 'returns a information about deploy tokens of project' do + expect(@custom_attributes.first.name).to eq 'foo' + expect(@custom_attributes.first.username).to eq 'gitlab+deploy-token-93' + end + end end