Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
771b777a
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 搜索 >>
提交
771b777a
编写于
9月 23, 2017
作者:
G
Guilherme Vieira
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adds requirements that supports anything in sha params
上级
b1464157
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
33 addition
and
28 deletion
+33
-28
changelogs/unreleased/sha-handling.yml
changelogs/unreleased/sha-handling.yml
+5
-0
doc/api/repositories.md
doc/api/repositories.md
+1
-1
lib/api/api.rb
lib/api/api.rb
+4
-3
lib/api/commits.rb
lib/api/commits.rb
+5
-7
lib/api/repositories.rb
lib/api/repositories.rb
+2
-2
lib/api/v3/builds.rb
lib/api/v3/builds.rb
+1
-1
lib/api/v3/commits.rb
lib/api/v3/commits.rb
+6
-6
lib/api/v3/repositories.rb
lib/api/v3/repositories.rb
+3
-3
spec/requests/api/v3/repositories_spec.rb
spec/requests/api/v3/repositories_spec.rb
+6
-5
未找到文件。
changelogs/unreleased/sha-handling.yml
0 → 100644
浏览文件 @
771b777a
---
title
:
Fix 404 errors in API caused when the branch name had a dot
merge_request
:
14462
author
:
gvieira37
type
:
fixed
doc/api/repositories.md
浏览文件 @
771b777a
...
...
@@ -85,7 +85,7 @@ GET /projects/:id/repository/blobs/:sha
Parameters:
-
`id`
(required) - The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user
-
`sha`
(required) - The
commit or branch name
-
`sha`
(required) - The
blob SHA
## Raw blob content
...
...
lib/api/api.rb
浏览文件 @
771b777a
...
...
@@ -4,6 +4,10 @@ module API
LOG_FILENAME
=
Rails
.
root
.
join
(
"log"
,
"api_json.log"
)
NO_SLASH_URL_PART_REGEX
=
%r{[^/]+}
PROJECT_ENDPOINT_REQUIREMENTS
=
{
id:
NO_SLASH_URL_PART_REGEX
}.
freeze
COMMIT_ENDPOINT_REQUIREMENTS
=
PROJECT_ENDPOINT_REQUIREMENTS
.
merge
(
sha:
NO_SLASH_URL_PART_REGEX
).
freeze
use
GrapeLogging
::
Middleware
::
RequestLogger
,
logger:
Logger
.
new
(
LOG_FILENAME
),
formatter:
Gitlab
::
GrapeLogging
::
Formatters
::
LogrageWithTimestamp
.
new
,
...
...
@@ -96,9 +100,6 @@ module API
helpers
::
API
::
Helpers
helpers
::
API
::
Helpers
::
CommonHelpers
NO_SLASH_URL_PART_REGEX
=
%r{[^/]+}
PROJECT_ENDPOINT_REQUIREMENTS
=
{
id:
NO_SLASH_URL_PART_REGEX
}.
freeze
# Keep in alphabetical order
mount
::
API
::
AccessRequests
mount
::
API
::
AwardEmoji
...
...
lib/api/commits.rb
浏览文件 @
771b777a
...
...
@@ -4,8 +4,6 @@ module API
class
Commits
<
Grape
::
API
include
PaginationParams
COMMIT_ENDPOINT_REQUIREMENTS
=
API
::
PROJECT_ENDPOINT_REQUIREMENTS
.
merge
(
sha:
API
::
NO_SLASH_URL_PART_REGEX
)
before
{
authorize!
:download_code
,
user_project
}
params
do
...
...
@@ -85,7 +83,7 @@ module API
params
do
requires
:sha
,
type:
String
,
desc:
'A commit sha, or the name of a branch or tag'
end
get
':id/repository/commits/:sha'
,
requirements:
COMMIT_ENDPOINT_REQUIREMENTS
do
get
':id/repository/commits/:sha'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
'Commit'
unless
commit
...
...
@@ -99,7 +97,7 @@ module API
params
do
requires
:sha
,
type:
String
,
desc:
'A commit sha, or the name of a branch or tag'
end
get
':id/repository/commits/:sha/diff'
,
requirements:
COMMIT_ENDPOINT_REQUIREMENTS
do
get
':id/repository/commits/:sha/diff'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
'Commit'
unless
commit
...
...
@@ -115,7 +113,7 @@ module API
use
:pagination
requires
:sha
,
type:
String
,
desc:
'A commit sha, or the name of a branch or tag'
end
get
':id/repository/commits/:sha/comments'
,
requirements:
COMMIT_ENDPOINT_REQUIREMENTS
do
get
':id/repository/commits/:sha/comments'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
'Commit'
unless
commit
...
...
@@ -132,7 +130,7 @@ module API
requires
:sha
,
type:
String
,
desc:
'A commit sha, or the name of a branch or tag to be cherry picked'
requires
:branch
,
type:
String
,
desc:
'The name of the branch'
end
post
':id/repository/commits/:sha/cherry_pick'
,
requirements:
COMMIT_ENDPOINT_REQUIREMENTS
do
post
':id/repository/commits/:sha/cherry_pick'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
authorize!
:push_code
,
user_project
commit
=
user_project
.
commit
(
params
[
:sha
])
...
...
@@ -169,7 +167,7 @@ module API
requires
:line_type
,
type:
String
,
values:
%w(new old)
,
default:
'new'
,
desc:
'The type of the line'
end
end
post
':id/repository/commits/:sha/comments'
,
requirements:
COMMIT_ENDPOINT_REQUIREMENTS
do
post
':id/repository/commits/:sha/comments'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
'Commit'
unless
commit
...
...
lib/api/repositories.rb
浏览文件 @
771b777a
...
...
@@ -57,7 +57,7 @@ module API
desc
'Get raw blob contents from the repository'
params
do
requires
:sha
,
type:
String
,
desc:
'The commit
, branch name, or tag name
'
requires
:sha
,
type:
String
,
desc:
'The commit
hash
'
end
get
':id/repository/blobs/:sha/raw'
do
assign_blob_vars!
...
...
@@ -67,7 +67,7 @@ module API
desc
'Get a blob from the repository'
params
do
requires
:sha
,
type:
String
,
desc:
'The commit
, branch name, or tag name
'
requires
:sha
,
type:
String
,
desc:
'The commit
hash
'
end
get
':id/repository/blobs/:sha'
do
assign_blob_vars!
...
...
lib/api/v3/builds.rb
浏览文件 @
771b777a
...
...
@@ -8,7 +8,7 @@ module API
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
:projects
do
resource
:projects
,
requirements:
API
::
PROJECT_ENDPOINT_REQUIREMENTS
do
helpers
do
params
:optional_scope
do
optional
:scope
,
types:
[
String
,
Array
[
String
]],
desc:
'The scope of builds to show'
,
...
...
lib/api/v3/commits.rb
浏览文件 @
771b777a
...
...
@@ -11,7 +11,7 @@ module API
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
:projects
,
requirements:
{
id:
%r{[^/]+}
}
do
resource
:projects
,
requirements:
API
::
PROJECT_ENDPOINT_REQUIREMENTS
do
desc
'Get a project repository commits'
do
success
::
API
::
Entities
::
RepoCommit
end
...
...
@@ -72,7 +72,7 @@ module API
params
do
requires
:sha
,
type:
String
,
desc:
'A commit sha, or the name of a branch or tag'
end
get
":id/repository/commits/:sha"
do
get
":id/repository/commits/:sha"
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
"Commit"
unless
commit
...
...
@@ -86,7 +86,7 @@ module API
params
do
requires
:sha
,
type:
String
,
desc:
'A commit sha, or the name of a branch or tag'
end
get
":id/repository/commits/:sha/diff"
do
get
":id/repository/commits/:sha/diff"
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
"Commit"
unless
commit
...
...
@@ -102,7 +102,7 @@ module API
use
:pagination
requires
:sha
,
type:
String
,
desc:
'A commit sha, or the name of a branch or tag'
end
get
':id/repository/commits/:sha/comments'
do
get
':id/repository/commits/:sha/comments'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
'Commit'
unless
commit
...
...
@@ -119,7 +119,7 @@ module API
requires
:sha
,
type:
String
,
desc:
'A commit sha to be cherry picked'
requires
:branch
,
type:
String
,
desc:
'The name of the branch'
end
post
':id/repository/commits/:sha/cherry_pick'
do
post
':id/repository/commits/:sha/cherry_pick'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
authorize!
:push_code
,
user_project
commit
=
user_project
.
commit
(
params
[
:sha
])
...
...
@@ -156,7 +156,7 @@ module API
requires
:line_type
,
type:
String
,
values:
%w(new old)
,
default:
'new'
,
desc:
'The type of the line'
end
end
post
':id/repository/commits/:sha/comments'
do
post
':id/repository/commits/:sha/comments'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
'Commit'
unless
commit
...
...
lib/api/v3/repositories.rb
浏览文件 @
771b777a
...
...
@@ -8,7 +8,7 @@ module API
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
:projects
,
requirements:
{
id:
%r{[^/]+}
}
do
resource
:projects
,
requirements:
API
::
PROJECT_ENDPOINT_REQUIREMENTS
do
helpers
do
def
handle_project_member_errors
(
errors
)
if
errors
[
:project_access
].
any?
...
...
@@ -43,7 +43,7 @@ module API
requires
:sha
,
type:
String
,
desc:
'The commit, branch name, or tag name'
requires
:filepath
,
type:
String
,
desc:
'The path to the file to display'
end
get
[
":id/repository/blobs/:sha"
,
":id/repository/commits/:sha/blob"
]
do
get
[
":id/repository/blobs/:sha"
,
":id/repository/commits/:sha/blob"
]
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
repo
=
user_project
.
repository
commit
=
repo
.
commit
(
params
[
:sha
])
not_found!
"Commit"
unless
commit
...
...
@@ -56,7 +56,7 @@ module API
params
do
requires
:sha
,
type:
String
,
desc:
'The commit, branch name, or tag name'
end
get
':id/repository/raw_blobs/:sha'
do
get
':id/repository/raw_blobs/:sha'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
repo
=
user_project
.
repository
begin
blob
=
Gitlab
::
Git
::
Blob
.
raw
(
repo
,
params
[
:sha
])
...
...
spec/requests/api/v3/repositories_spec.rb
浏览文件 @
771b777a
...
...
@@ -97,10 +97,11 @@ describe API::V3::Repositories do
end
end
{
'blobs/:sha'
=>
'blobs/master'
,
'commits/:sha/blob'
=>
'commits/master/blob'
}.
each
do
|
desc_path
,
example_path
|
[
[
'blobs/:sha'
,
'blobs/master'
],
[
'blobs/:sha'
,
'blobs/v1.1.0'
],
[
'commits/:sha/blob'
,
'commits/master/blob'
]
].
each
do
|
desc_path
,
example_path
|
describe
"GET /projects/:id/repository/
#{
desc_path
}
"
do
let
(
:route
)
{
"/projects/
#{
project
.
id
}
/repository/
#{
example_path
}
?filepath=README.md"
}
shared_examples_for
'repository blob'
do
...
...
@@ -110,7 +111,7 @@ describe API::V3::Repositories do
end
context
'when sha does not exist'
do
it_behaves_like
'404 response'
do
let
(
:request
)
{
get
v3_api
(
route
.
sub
(
'master'
,
'invalid_branch_name'
)
,
current_user
)
}
let
(
:request
)
{
get
v3_api
(
"/projects/
#{
project
.
id
}
/repository/
#{
desc_path
.
sub
(
':sha'
,
'invalid_branch_name'
)
}
?filepath=README.md"
,
current_user
)
}
let
(
:message
)
{
'404 Commit Not Found'
}
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录