Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
e467a11e
Commit
e467a11e
authored
Apr 13, 2018
by
Roger Rüttimann
Committed by
Douwe Maan
Apr 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Feature/add language in repository to api
parent
70083ebf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
0 deletions
+81
-0
changelogs/unreleased/feature-add-language-in-repository-to-api.yml
.../unreleased/feature-add-language-in-repository-to-api.yml
+5
-0
doc/api/projects.md
doc/api/projects.md
+23
-0
lib/api/projects.rb
lib/api/projects.rb
+5
-0
spec/requests/api/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 @
e467a11e
---
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 @
e467a11e
...
@@ -915,6 +915,29 @@ Example response:
...
@@ -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
## Archive a project
Archives the project if the user is either admin or the project owner of this project. This action is
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 @
e467a11e
...
@@ -338,6 +338,11 @@ module API
...
@@ -338,6 +338,11 @@ module API
end
end
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'
desc
'Remove a project'
delete
":id"
do
delete
":id"
do
authorize!
:remove_project
,
user_project
authorize!
:remove_project
,
user_project
...
...
spec/requests/api/projects_spec.rb
View file @
e467a11e
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
require
'spec_helper'
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
describe
API
::
Projects
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
...
@@ -1694,6 +1706,42 @@ describe API::Projects do
...
@@ -1694,6 +1706,42 @@ describe API::Projects do
end
end
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
describe
'DELETE /projects/:id'
do
context
'when authenticated as user'
do
context
'when authenticated as user'
do
it
'removes project'
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