Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
c793252e
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,发现更多精彩内容 >>
提交
c793252e
编写于
7月 13, 2018
作者:
S
Stan Hu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for deleting branches via the Bitbucket Server API
上级
ec4109d4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
55 addition
and
1 deletion
+55
-1
lib/bitbucket_server/client.rb
lib/bitbucket_server/client.rb
+9
-0
lib/bitbucket_server/connection.rb
lib/bitbucket_server/connection.rb
+26
-1
spec/lib/bitbucket_server/connection_spec.rb
spec/lib/bitbucket_server/connection_spec.rb
+20
-0
未找到文件。
lib/bitbucket_server/client.rb
浏览文件 @
c793252e
...
...
@@ -36,6 +36,15 @@ module BitbucketServer
connection
.
post
(
"/projects/
#{
project_key
}
/repos/
#{
repo
}
/branches"
,
payload
.
to_json
)
end
def
delete_branch
(
project_key
,
repo
,
branch_name
,
sha
)
payload
=
{
name:
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
branch_name
,
dryRun:
false
}
connection
.
delete
(
:branches
,
"/projects/
#{
project_key
}
/repos/
#{
repo
}
/branches"
,
payload
.
to_json
)
end
private
def
get_collection
(
path
,
type
)
...
...
lib/bitbucket_server/connection.rb
浏览文件 @
c793252e
...
...
@@ -36,10 +36,27 @@ module BitbucketServer
response
.
parsed_response
end
# We need to support two different APIs for deletion:
#
# /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/branches/default
# /rest/branch-utils/1.0/projects/{projectKey}/repos/{repositorySlug}/branches
def
delete
(
resource
,
path
,
body
)
url
=
delete_url
(
resource
,
path
)
response
=
Gitlab
::
HTTP
.
delete
(
url
,
basic_auth:
auth
,
headers:
post_headers
,
body:
body
)
check_errors!
(
response
)
response
.
parsed_response
end
private
def
check_errors!
(
response
)
return
if
response
.
code
==
2
00
return
if
response
.
code
>=
200
&&
response
.
code
<
3
00
details
=
if
response
.
parsed_response
&&
response
.
parsed_response
.
is_a?
(
Hash
)
...
...
@@ -68,5 +85,13 @@ module BitbucketServer
def
root_url
"
#{
base_uri
}
/rest/api/
#{
api_version
}
"
end
def
delete_url
(
resource
,
path
)
if
resource
==
:branches
"
#{
base_uri
}
/branch-utils/
#{
api_version
}#{
path
}
"
else
build_url
(
path
)
end
end
end
end
spec/lib/bitbucket_server/connection_spec.rb
浏览文件 @
c793252e
...
...
@@ -35,4 +35,24 @@ describe BitbucketServer::Connection do
expect
{
subject
.
post
(
url
,
payload
)
}.
to
raise_error
(
described_class
::
ConnectionError
)
end
end
describe
'#delete'
do
context
'branch API'
do
let
(
:branch_path
)
{
'/projects/foo/repos/bar/branches'
}
let
(
:branch_url
)
{
'https://test:7990/branch-utils/1.0/projects/foo/repos/bar/branches'
}
let
(
:path
)
{
}
it
'returns JSON body'
do
WebMock
.
stub_request
(
:delete
,
branch_url
).
to_return
(
body:
payload
.
to_json
,
status:
200
,
headers:
headers
)
expect
(
subject
.
delete
(
:branches
,
branch_path
,
payload
)).
to
eq
(
payload
)
end
it
'throws an exception if the response is not 200'
do
WebMock
.
stub_request
(
:delete
,
branch_url
).
to_return
(
body:
payload
.
to_json
,
status:
500
,
headers:
headers
)
expect
{
subject
.
delete
(
:branches
,
branch_path
,
payload
)
}.
to
raise_error
(
described_class
::
ConnectionError
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录