Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
5b700328
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,发现更多精彩内容 >>
提交
5b700328
编写于
4月 09, 2019
作者:
J
Jason Goodman
提交者:
Rémy Coutable
4月 09, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Set release name when adding release notes to an existing tag
Also set the release sha and author
上级
74ac04a6
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
106 addition
and
21 deletion
+106
-21
app/controllers/projects/tags/releases_controller.rb
app/controllers/projects/tags/releases_controller.rb
+3
-7
app/models/release.rb
app/models/release.rb
+1
-0
app/services/releases/concerns.rb
app/services/releases/concerns.rb
+1
-1
app/services/releases/create_service.rb
app/services/releases/create_service.rb
+15
-5
changelogs/unreleased/issue-58418-release-notes.yml
changelogs/unreleased/issue-58418-release-notes.yml
+5
-0
lib/gitlab/legacy_github_import/release_formatter.rb
lib/gitlab/legacy_github_import/release_formatter.rb
+1
-0
spec/controllers/projects/tags/releases_controller_spec.rb
spec/controllers/projects/tags/releases_controller_spec.rb
+53
-8
spec/lib/gitlab/legacy_github_import/release_formatter_spec.rb
...lib/gitlab/legacy_github_import/release_formatter_spec.rb
+1
-0
spec/models/release_spec.rb
spec/models/release_spec.rb
+16
-0
spec/services/releases/create_service_spec.rb
spec/services/releases/create_service_spec.rb
+10
-0
未找到文件。
app/controllers/projects/tags/releases_controller.rb
浏览文件 @
5b700328
...
@@ -12,16 +12,13 @@ class Projects::Tags::ReleasesController < Projects::ApplicationController
...
@@ -12,16 +12,13 @@ class Projects::Tags::ReleasesController < Projects::ApplicationController
end
end
def
update
def
update
# Release belongs to Tag which is not active record object,
# it exists only to save a description to each Tag.
# If description is empty we should destroy the existing record.
if
release_params
[
:description
].
present?
if
release_params
[
:description
].
present?
release
.
update
(
release_params
)
release
.
update
(
release_params
)
else
else
release
.
destroy
release
.
destroy
end
end
redirect_to
project_tag_path
(
@project
,
@
tag
.
name
)
redirect_to
project_tag_path
(
@project
,
tag
.
name
)
end
end
private
private
...
@@ -30,11 +27,10 @@ class Projects::Tags::ReleasesController < Projects::ApplicationController
...
@@ -30,11 +27,10 @@ class Projects::Tags::ReleasesController < Projects::ApplicationController
@tag
||=
@repository
.
find_tag
(
params
[
:tag_id
])
@tag
||=
@repository
.
find_tag
(
params
[
:tag_id
])
end
end
# rubocop: disable CodeReuse/ActiveRecord
def
release
def
release
@release
||=
@project
.
releases
.
find_or_initialize_by
(
tag:
@tag
.
name
)
@release
||=
Releases
::
CreateService
.
new
(
project
,
current_user
,
tag:
@tag
.
name
)
.
find_or_build_release
end
end
# rubocop: enable CodeReuse/ActiveRecord
def
release_params
def
release_params
params
.
require
(
:release
).
permit
(
:description
)
params
.
require
(
:release
).
permit
(
:description
)
...
...
app/models/release.rb
浏览文件 @
5b700328
...
@@ -15,6 +15,7 @@ class Release < ApplicationRecord
...
@@ -15,6 +15,7 @@ class Release < ApplicationRecord
accepts_nested_attributes_for
:links
,
allow_destroy:
true
accepts_nested_attributes_for
:links
,
allow_destroy:
true
validates
:description
,
:project
,
:tag
,
presence:
true
validates
:description
,
:project
,
:tag
,
presence:
true
validates
:name
,
presence:
true
,
on: :create
scope
:sorted
,
->
{
order
(
created_at: :desc
)
}
scope
:sorted
,
->
{
order
(
created_at: :desc
)
}
...
...
app/services/releases/concerns.rb
浏览文件 @
5b700328
...
@@ -15,7 +15,7 @@ module Releases
...
@@ -15,7 +15,7 @@ module Releases
end
end
def
name
def
name
params
[
:name
]
params
[
:name
]
||
tag_name
end
end
def
description
def
description
...
...
app/services/releases/create_service.rb
浏览文件 @
5b700328
...
@@ -15,6 +15,10 @@ module Releases
...
@@ -15,6 +15,10 @@ module Releases
create_release
(
tag
)
create_release
(
tag
)
end
end
def
find_or_build_release
release
||
build_release
(
existing_tag
)
end
private
private
def
ensure_tag
def
ensure_tag
...
@@ -38,7 +42,17 @@ module Releases
...
@@ -38,7 +42,17 @@ module Releases
end
end
def
create_release
(
tag
)
def
create_release
(
tag
)
release
=
project
.
releases
.
create!
(
release
=
build_release
(
tag
)
release
.
save!
success
(
tag:
tag
,
release:
release
)
rescue
=>
e
error
(
e
.
message
,
400
)
end
def
build_release
(
tag
)
project
.
releases
.
build
(
name:
name
,
name:
name
,
description:
description
,
description:
description
,
author:
current_user
,
author:
current_user
,
...
@@ -46,10 +60,6 @@ module Releases
...
@@ -46,10 +60,6 @@ module Releases
sha:
tag
.
dereferenced_target
.
sha
,
sha:
tag
.
dereferenced_target
.
sha
,
links_attributes:
params
.
dig
(
:assets
,
'links'
)
||
[]
links_attributes:
params
.
dig
(
:assets
,
'links'
)
||
[]
)
)
success
(
tag:
tag
,
release:
release
)
rescue
=>
e
error
(
e
.
message
,
400
)
end
end
end
end
end
end
changelogs/unreleased/issue-58418-release-notes.yml
0 → 100644
浏览文件 @
5b700328
---
title
:
Set release name when adding release notes to an existing tag
merge_request
:
26807
author
:
type
:
fixed
lib/gitlab/legacy_github_import/release_formatter.rb
浏览文件 @
5b700328
...
@@ -7,6 +7,7 @@ module Gitlab
...
@@ -7,6 +7,7 @@ module Gitlab
{
{
project:
project
,
project:
project
,
tag:
raw_data
.
tag_name
,
tag:
raw_data
.
tag_name
,
name:
raw_data
.
name
,
description:
raw_data
.
body
,
description:
raw_data
.
body
,
created_at:
raw_data
.
created_at
,
created_at:
raw_data
.
created_at
,
updated_at:
raw_data
.
created_at
updated_at:
raw_data
.
created_at
...
...
spec/controllers/projects/tags/releases_controller_spec.rb
浏览文件 @
5b700328
...
@@ -18,40 +18,85 @@ describe Projects::Tags::ReleasesController do
...
@@ -18,40 +18,85 @@ describe Projects::Tags::ReleasesController do
tag_id
=
release
.
tag
tag_id
=
release
.
tag
project
.
releases
.
destroy_all
# rubocop: disable DestroyAll
project
.
releases
.
destroy_all
# rubocop: disable DestroyAll
get
:edit
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
project
,
tag_id:
tag_id
}
response
=
get
:edit
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
project
,
tag_id:
tag_id
}
release
=
assigns
(
:release
)
release
=
assigns
(
:release
)
expect
(
release
).
not_to
be_nil
expect
(
release
).
not_to
be_nil
expect
(
release
).
not_to
be_persisted
expect
(
release
).
not_to
be_persisted
expect
(
response
).
to
have_http_status
(
:ok
)
end
end
it
'retrieves an existing release'
do
it
'retrieves an existing release'
do
get
:edit
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
project
,
tag_id:
release
.
tag
}
response
=
get
:edit
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
project
,
tag_id:
release
.
tag
}
release
=
assigns
(
:release
)
release
=
assigns
(
:release
)
expect
(
release
).
not_to
be_nil
expect
(
release
).
not_to
be_nil
expect
(
release
).
to
be_persisted
expect
(
release
).
to
be_persisted
expect
(
response
).
to
have_http_status
(
:ok
)
end
end
end
end
describe
'PUT #update'
do
describe
'PUT #update'
do
it
'updates release note description'
do
it
'updates release note description'
do
update_release
(
'description updated'
)
response
=
update_release
(
release
.
tag
,
"description updated"
)
release
=
project
.
releases
.
find_by
_tag
(
tag
)
release
=
project
.
releases
.
find_by
(
tag:
tag
)
expect
(
release
.
description
).
to
eq
(
"description updated"
)
expect
(
release
.
description
).
to
eq
(
"description updated"
)
expect
(
response
).
to
have_http_status
(
:found
)
end
end
it
'deletes release note when description is null'
do
it
'creates a release if one does not exist'
do
expect
{
update_release
(
''
)
}.
to
change
(
project
.
releases
,
:count
).
by
(
-
1
)
tag_without_release
=
create_new_tag
expect
do
update_release
(
tag_without_release
.
name
,
"a new release"
)
end
.
to
change
{
project
.
releases
.
count
}.
by
(
1
)
expect
(
response
).
to
have_http_status
(
:found
)
end
it
'sets the release name, sha, and author for a new release'
do
tag_without_release
=
create_new_tag
response
=
update_release
(
tag_without_release
.
name
,
"a new release"
)
release
=
project
.
releases
.
find_by
(
tag:
tag_without_release
.
name
)
expect
(
release
.
name
).
to
eq
(
tag_without_release
.
name
)
expect
(
release
.
sha
).
to
eq
(
tag_without_release
.
target_commit
.
sha
)
expect
(
release
.
author
.
id
).
to
eq
(
user
.
id
)
expect
(
response
).
to
have_http_status
(
:found
)
end
it
'deletes release when description is empty'
do
initial_releases_count
=
project
.
releases
.
count
response
=
update_release
(
release
.
tag
,
""
)
expect
(
initial_releases_count
).
to
eq
(
1
)
expect
(
project
.
releases
.
count
).
to
eq
(
0
)
expect
(
response
).
to
have_http_status
(
:found
)
end
it
'does nothing when description is empty and the tag does not have a release'
do
tag_without_release
=
create_new_tag
expect
do
update_release
(
tag_without_release
.
name
,
""
)
end
.
not_to
change
{
project
.
releases
.
count
}
expect
(
response
).
to
have_http_status
(
:found
)
end
end
end
end
def
update_release
(
description
)
def
create_new_tag
project
.
repository
.
add_tag
(
user
,
'mytag'
,
'master'
)
end
def
update_release
(
tag_id
,
description
)
put
:update
,
params:
{
put
:update
,
params:
{
namespace_id:
project
.
namespace
.
to_param
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
project_id:
project
,
tag_id:
release
.
tag
,
tag_id:
tag_id
,
release:
{
description:
description
}
release:
{
description:
description
}
}
}
end
end
...
...
spec/lib/gitlab/legacy_github_import/release_formatter_spec.rb
浏览文件 @
5b700328
...
@@ -25,6 +25,7 @@ describe Gitlab::LegacyGithubImport::ReleaseFormatter do
...
@@ -25,6 +25,7 @@ describe Gitlab::LegacyGithubImport::ReleaseFormatter do
expected
=
{
expected
=
{
project:
project
,
project:
project
,
tag:
'v1.0.0'
,
tag:
'v1.0.0'
,
name:
'First release'
,
description:
'Release v1.0.0'
,
description:
'Release v1.0.0'
,
created_at:
created_at
,
created_at:
created_at
,
updated_at:
created_at
updated_at:
created_at
...
...
spec/models/release_spec.rb
浏览文件 @
5b700328
...
@@ -18,6 +18,22 @@ RSpec.describe Release do
...
@@ -18,6 +18,22 @@ RSpec.describe Release do
describe
'validation'
do
describe
'validation'
do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:description
)
}
it
{
is_expected
.
to
validate_presence_of
(
:description
)
}
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
context
'when a release exists in the database without a name'
do
it
'does not require name'
do
existing_release_without_name
=
build
(
:release
,
project:
project
,
author:
user
,
name:
nil
)
existing_release_without_name
.
save
(
validate:
false
)
existing_release_without_name
.
description
=
"change"
existing_release_without_name
.
save
existing_release_without_name
.
reload
expect
(
existing_release_without_name
).
to
be_valid
expect
(
existing_release_without_name
.
description
).
to
eq
(
"change"
)
expect
(
existing_release_without_name
.
name
).
to
be_nil
end
end
end
end
describe
'#assets_count'
do
describe
'#assets_count'
do
...
...
spec/services/releases/create_service_spec.rb
浏览文件 @
5b700328
...
@@ -19,6 +19,8 @@ describe Releases::CreateService do
...
@@ -19,6 +19,8 @@ describe Releases::CreateService do
shared_examples
'a successful release creation'
do
shared_examples
'a successful release creation'
do
it
'creates a new release'
do
it
'creates a new release'
do
result
=
service
.
execute
result
=
service
.
execute
expect
(
project
.
releases
.
count
).
to
eq
(
1
)
expect
(
result
[
:status
]).
to
eq
(
:success
)
expect
(
result
[
:status
]).
to
eq
(
:success
)
expect
(
result
[
:tag
]).
not_to
be_nil
expect
(
result
[
:tag
]).
not_to
be_nil
expect
(
result
[
:release
]).
not_to
be_nil
expect
(
result
[
:release
]).
not_to
be_nil
...
@@ -69,4 +71,12 @@ describe Releases::CreateService do
...
@@ -69,4 +71,12 @@ describe Releases::CreateService do
end
end
end
end
end
end
describe
'#find_or_build_release'
do
it
'does not save the built release'
do
service
.
find_or_build_release
expect
(
project
.
releases
.
count
).
to
eq
(
0
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录