Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
e467a11e
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e467a11e
编写于
4月 13, 2018
作者:
R
Roger Rüttimann
提交者:
Douwe Maan
4月 13, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Feature/add language in repository to api
上级
70083ebf
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
81 addition
and
0 deletion
+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
未找到文件。
changelogs/unreleased/feature-add-language-in-repository-to-api.yml
0 → 100644
浏览文件 @
e467a11e
---
title
:
'
API:
add
languages
of
project
GET
/projects/:id/languages'
merge_request
:
17770
author
:
Roger Rüttimann
type
:
added
doc/api/projects.md
浏览文件 @
e467a11e
...
...
@@ -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
浏览文件 @
e467a11e
...
...
@@ -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
浏览文件 @
e467a11e
# -*- 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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录