BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
a45729c8
Commit
a45729c8
authored
Apr 13, 2018
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/add-language-in-repository-to-api' into 'master'
Feature/add language in repository to api See merge request gitlab-org/gitlab-ce!17770
parents
70083ebf
e467a11e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
0 deletions
+81
-0
feature-add-language-in-repository-to-api.yml
.../unreleased/feature-add-language-in-repository-to-api.yml
+5
-0
projects.md
doc/api/projects.md
+23
-0
projects.rb
lib/api/projects.rb
+5
-0
projects_spec.rb
spec/requests/api/projects_spec.rb
+48
-0
No files found.
changelogs/unreleased/feature-add-language-in-repository-to-api.yml
0 → 100644
View file @
a45729c8
---
title
:
'
API:
add
languages
of
project
GET
/projects/:id/languages'
merge_request
:
17770
author
:
Roger Rüttimann
type
:
added
doc/api/projects.md
View file @
a45729c8
...
...
@@ -915,6 +915,29 @@ Example response:
}
```
## Languages
Get languages used in a project with percentage value.
```
GET /projects/:id/languages
```
```
bash
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
"https://gitlab.example.com/api/v4/projects/5/languages"
```
Example response:
```
json
{
"Ruby"
:
66.69
,
"JavaScript"
:
22.98
,
"HTML"
:
7.91
,
"CoffeeScript"
:
2.42
}
```
## Archive a project
Archives the project if the user is either admin or the project owner of this project. This action is
...
...
lib/api/projects.rb
View file @
a45729c8
...
...
@@ -338,6 +338,11 @@ module API
end
end
desc
'Get languages in project repository'
get
':id/languages'
do
user_project
.
repository
.
languages
.
map
{
|
language
|
language
.
values_at
(
:label
,
:value
)
}.
to_h
end
desc
'Remove a project'
delete
":id"
do
authorize!
:remove_project
,
user_project
...
...
spec/requests/api/projects_spec.rb
View file @
a45729c8
# -*- coding: utf-8 -*-
require
'spec_helper'
shared_examples
'languages and percentages JSON response'
do
let
(
:expected_languages
)
{
project
.
repository
.
languages
.
map
{
|
language
|
language
.
values_at
(
:label
,
:value
)}.
to_h
}
it
'returns expected language values'
do
get
api
(
"/projects/
#{
project
.
id
}
/languages"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
).
to
eq
(
expected_languages
)
expect
(
json_response
.
count
).
to
be
>
1
end
end
describe
API
::
Projects
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
...
...
@@ -1694,6 +1706,42 @@ describe API::Projects do
end
end
describe
'GET /projects/:id/languages'
do
context
'with an authorized user'
do
it_behaves_like
'languages and percentages JSON response'
do
let
(
:project
)
{
project3
}
end
it
'returns not_found(404) for not existing project'
do
get
api
(
"/projects/9999999999/languages"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'with not authorized user'
do
it
'returns not_found for existing but unauthorized project'
do
get
api
(
"/projects/
#{
project3
.
id
}
/languages"
,
user3
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'without user'
do
let
(
:project_public
)
{
create
(
:project
,
:public
,
:repository
)
}
it_behaves_like
'languages and percentages JSON response'
do
let
(
:project
)
{
project_public
}
end
it
'returns not_found for existing but unauthorized project'
do
get
api
(
"/projects/
#{
project3
.
id
}
/languages"
,
nil
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
end
describe
'DELETE /projects/:id'
do
context
'when authenticated as user'
do
it
'removes project'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment