Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): add project_languages methode #695

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/gitlab/client/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Gitlab::Client
# Defines methods related to projects.
# @see https://docs.gitlab.com/ce/api/projects.html
module Projects
module Projects # rubocop:disable Metrics/ModuleLength
# Gets a list of projects owned by the authenticated user.
#
# @example
Expand Down Expand Up @@ -704,5 +704,16 @@ def delete_project_custom_attribute(key, project_id = nil)
def project_deploy_tokens(project, options = {})
get("/projects/#{url_encode project}/deploy_tokens", query: options)
end

# Get languages used with percentage value
#
# @example
# Gitlab.project_languages(42)
#
# @param [Integer, String] id The ID or path of a project.
# @return [Gitlab::ObjectifiedHash]
def project_languages(project)
get("/projects/#{url_encode project}/languages")
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/project_languages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Ruby":99.99,"Shell":0.01}
12 changes: 12 additions & 0 deletions spec/gitlab/client/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -925,4 +925,16 @@
expect(@custom_attributes.first.username).to eq 'gitlab+deploy-token-93'
end
end

describe '.project_languages' do
before do
stub_get('/projects/2/languages', 'project_languages')
@project_languages = Gitlab.project_languages(2)
end

it 'returns a GitlabHash with language data' do
expect(@project_languages).to be_a Gitlab::ObjectifiedHash
expect(@project_languages.to_hash.keys).to contain_exactly('Ruby', 'Shell')
end
end
end