Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
a039a2d9
提交
a039a2d9
编辑于
1 year ago
作者:
Dmitry Gruzd
提交者:
Bojan Marjanovic
1 year ago
浏览文件
操作
下载
补丁
差异文件
Allow Danger::OutdatedTodo to fail in Lefthook
上级
76c5f077
No related branches found
分支 包含提交
No related tags found
标签 包含提交
无相关合并请求
变更
4
隐藏空白变更内容
行内
左右并排
显示
4 个更改的文件
danger/plugins/todos.rb
+5
-1
5 个添加, 1 个删除
danger/plugins/todos.rb
lefthook.yml
+3
-1
3 个添加, 1 个删除
lefthook.yml
spec/tooling/danger/outdated_todo_spec.rb
+72
-63
72 个添加, 63 个删除
spec/tooling/danger/outdated_todo_spec.rb
tooling/danger/outdated_todo.rb
+10
-3
10 个添加, 3 个删除
tooling/danger/outdated_todo.rb
有
90 个添加
和
68 个删除
danger/plugins/todos.rb
+
5
−
1
浏览文件 @
a039a2d9
...
...
@@ -5,7 +5,11 @@
module
Danger
class
Todos
<
::
Danger
::
Plugin
def
check_outdated_todos
(
filenames
)
Tooling
::
Danger
::
OutdatedTodo
.
new
(
filenames
,
context:
self
).
check
Tooling
::
Danger
::
OutdatedTodo
.
new
(
filenames
,
context:
self
,
allow_fail:
from_lefthook?
).
check
end
def
from_lefthook?
%w[1 true]
.
include?
(
ENV
[
'FROM_LEFTHOOK'
])
end
end
end
此差异已折叠。
点击以展开。
lefthook.yml
+
3
−
1
浏览文件 @
a039a2d9
...
...
@@ -4,7 +4,9 @@ pre-push:
-
ref
:
master
commands
:
danger
:
run
:
bundle exec rake danger_local
files
:
git diff --name-only $(git merge-base origin/master HEAD)..HEAD
# We need to specify {files} as part of the command, otherwise it won't execute the hook
run
:
echo {files} >/dev/null && FROM_LEFTHOOK=1 bundle exec rake danger_local
eslint
:
tags
:
frontend style
files
:
git diff --name-only --diff-filter=d $(git merge-base origin/master HEAD)..HEAD
...
...
此差异已折叠。
点击以展开。
spec/tooling/danger/outdated_todo_spec.rb
+
72
−
63
浏览文件 @
a039a2d9
...
...
@@ -15,69 +15,78 @@
]
end
subject
(
:plugin
)
{
described_class
.
new
(
filenames
,
context:
fake_danger
,
todos:
todos
)
}
context
'when the filenames are mentioned in single todo'
do
let
(
:filenames
)
{
[
'app/controllers/acme_challenges_controller.rb'
]
}
it
'warns about mentions'
do
expect
(
fake_danger
)
.
to
receive
(
:warn
)
.
with
<<~
MESSAGE
`app/controllers/acme_challenges_controller.rb` was removed but is mentioned in:
- `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:5`
MESSAGE
plugin
.
check
end
end
context
'when the filenames are mentioned in multiple todos'
do
let
(
:filenames
)
do
[
'app/controllers/application_controller.rb'
,
'app/controllers/acme_challenges_controller.rb'
]
end
it
'warns about mentions'
do
expect
(
fake_danger
)
.
to
receive
(
:warn
)
.
with
(
<<~
FIRSTMESSAGE
)
`app/controllers/application_controller.rb` was removed but is mentioned in:
- `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:4`
- `spec/fixtures/tooling/danger/rubocop_todo/cop2.yml:4`
FIRSTMESSAGE
expect
(
fake_danger
)
.
to
receive
(
:warn
)
.
with
(
<<~
SECONDMESSAGE
)
`app/controllers/acme_challenges_controller.rb` was removed but is mentioned in:
- `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:5`
SECONDMESSAGE
plugin
.
check
end
end
context
'when the filenames are not mentioned in todos'
do
let
(
:filenames
)
{
[
'any/inexisting/file.rb'
]
}
it
'does not warn'
do
expect
(
fake_danger
).
not_to
receive
(
:warn
)
plugin
.
check
end
end
context
'when there is no todos'
do
let
(
:filenames
)
{
[
'app/controllers/acme_challenges_controller.rb'
]
}
let
(
:todos
)
{
[]
}
it
'does not warn'
do
expect
(
fake_danger
).
not_to
receive
(
:warn
)
plugin
.
check
subject
(
:plugin
)
{
described_class
.
new
(
filenames
,
context:
fake_danger
,
todos:
todos
,
allow_fail:
allow_fail
)
}
[
true
,
false
].
each
do
|
allow_failure
|
context
"with allow_fail set to
#{
allow_failure
}
"
do
let
(
:allow_fail
)
{
allow_failure
}
let
(
:expected_method
)
do
allow_failure
?
:fail
:
:warn
end
context
'when the filenames are mentioned in single todo'
do
let
(
:filenames
)
{
[
'app/controllers/acme_challenges_controller.rb'
]
}
it
'warns about mentions'
do
expect
(
fake_danger
)
.
to
receive
(
expected_method
)
.
with
<<~
MESSAGE
`app/controllers/acme_challenges_controller.rb` was removed but is mentioned in:
- `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:5`
MESSAGE
plugin
.
check
end
end
context
'when the filenames are mentioned in multiple todos'
do
let
(
:filenames
)
do
[
'app/controllers/application_controller.rb'
,
'app/controllers/acme_challenges_controller.rb'
]
end
it
'warns about mentions'
do
expect
(
fake_danger
)
.
to
receive
(
expected_method
)
.
with
(
<<~
FIRSTMESSAGE
)
`app/controllers/application_controller.rb` was removed but is mentioned in:
- `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:4`
- `spec/fixtures/tooling/danger/rubocop_todo/cop2.yml:4`
FIRSTMESSAGE
expect
(
fake_danger
)
.
to
receive
(
expected_method
)
.
with
(
<<~
SECONDMESSAGE
)
`app/controllers/acme_challenges_controller.rb` was removed but is mentioned in:
- `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:5`
SECONDMESSAGE
plugin
.
check
end
end
context
'when the filenames are not mentioned in todos'
do
let
(
:filenames
)
{
[
'any/inexisting/file.rb'
]
}
it
'does not warn'
do
expect
(
fake_danger
).
not_to
receive
(
expected_method
)
plugin
.
check
end
end
context
'when there is no todos'
do
let
(
:filenames
)
{
[
'app/controllers/acme_challenges_controller.rb'
]
}
let
(
:todos
)
{
[]
}
it
'does not warn'
do
expect
(
fake_danger
).
not_to
receive
(
expected_method
)
plugin
.
check
end
end
end
end
end
此差异已折叠。
点击以展开。
tooling/danger/outdated_todo.rb
+
10
−
3
浏览文件 @
a039a2d9
...
...
@@ -8,10 +8,11 @@ class OutdatedTodo
spec/support/rspec_order_todo.yml
]
.
freeze
def
initialize
(
filenames
,
context
:,
todos:
TODOS_GLOBS
)
def
initialize
(
filenames
,
context
:,
todos:
TODOS_GLOBS
,
allow_fail:
false
)
@filenames
=
filenames
@context
=
context
@todos_globs
=
todos
@allow_fail
=
allow_fail
end
def
check
...
...
@@ -22,17 +23,23 @@ def check
private
attr_reader
:filenames
,
:context
attr_reader
:filenames
,
:context
,
:allow_fail
def
check_filename
(
filename
)
mentions
=
all_mentions_for
(
filename
)
return
if
mentions
.
empty?
context
.
warn
<<~
MESSAGE
message
=
<<~
MESSAGE
`
#{
filename
}
` was removed but is mentioned in:
#{
mentions
.
join
(
"
\n
"
)
}
MESSAGE
if
allow_fail
context
.
fail
message
else
context
.
warn
message
end
end
def
all_mentions_for
(
filename
)
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录