Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
1d16f137
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,发现更多精彩内容 >>
提交
1d16f137
编写于
11月 21, 2016
作者:
K
Kamil Trzcinski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add deploy chat command [ci skip]
上级
c99522f2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
70 addition
and
14 deletion
+70
-14
app/models/environment.rb
app/models/environment.rb
+9
-1
lib/gitlab/chat_commands/deploy.rb
lib/gitlab/chat_commands/deploy.rb
+34
-0
lib/gitlab/chat_commands/result.rb
lib/gitlab/chat_commands/result.rb
+5
-0
lib/mattermost/presenter.rb
lib/mattermost/presenter.rb
+22
-13
未找到文件。
app/models/environment.rb
浏览文件 @
1d16f137
...
...
@@ -19,7 +19,7 @@ class Environment < ActiveRecord::Base
allow_nil:
true
,
addressable_url:
true
delegate
:stop_action
,
to: :last_deployment
,
allow_nil:
true
delegate
:stop_action
,
:manual_actions
,
to: :last_deployment
,
allow_nil:
true
scope
:available
,
->
{
with_state
(
:available
)
}
scope
:stopped
,
->
{
with_state
(
:stopped
)
}
...
...
@@ -99,4 +99,12 @@ class Environment < ActiveRecord::Base
stop
stop_action
.
play
(
current_user
)
end
def
actions_for
(
environment
)
return
[]
unless
manual_actions
manual_actions
.
select
|
action
|
action
.
expanded_environment_name
=
environment
end
end
end
lib/gitlab/chat_commands/deploy.rb
0 → 100644
浏览文件 @
1d16f137
module
Gitlab
module
ChatCommands
class
Deploy
<
BaseCommand
def
self
.
match
(
text
)
/\Adeploy\s+(?<from>.*)\s+to+\s+(?<to>.*)\z/
.
match
(
text
)
end
def
self
.
help_message
'deploy <environment> to <target-environment>'
end
def
self
.
allowed?
(
project
,
user
)
can?
(
user
,
:create_deployment
,
project
)
end
def
execute
(
match
)
from
=
match
[
:from
]
to
=
match
[
:to
]
environment
=
project
.
environments
.
find_by
(
name:
from
)
return
unless
environment
actions
=
environment
.
actions_for
(
to
)
return
unless
actions
.
any?
if
actions
.
one?
actions
.
first
.
play
(
current_user
)
else
Result
.
new
(
:error
,
'Too many actions defined'
)
end
end
end
end
end
lib/gitlab/chat_commands/result.rb
0 → 100644
浏览文件 @
1d16f137
module
Gitlab
module
ChatCommands
Result
=
Struct
.
new
(
:type
,
:message
)
end
end
lib/mattermost/presenter.rb
浏览文件 @
1d16f137
...
...
@@ -24,20 +24,22 @@ module Mattermost
end
end
def
present
(
resource
)
return
not_found
unless
resource
if
resource
.
respond_to?
(
:count
)
if
resource
.
count
>
1
return
multiple_resources
(
resource
)
elsif
resource
.
count
==
0
return
not_found
def
present
(
subject
)
return
not_found
unless
subject
if
subject
.
is_a?
(
Gitlab
::
ChatCommands
::
Result
)
show_result
(
subject
)
elsif
subject
.
respond_to?
(
:count
)
if
subject
.
try
(
:many?
)
multiple_resources
(
subject
)
elsif
subject
.
count
==
0
not_found
else
resource
=
resource
.
first
single_resource
(
subject
)
end
else
single_resource
(
subject
)
end
single_resource
(
resource
)
end
def
access_denied
...
...
@@ -46,6 +48,10 @@ module Mattermost
private
def
show_result
(
result
)
ephemeral_response
(
result
.
message
)
end
def
not_found
ephemeral_response
(
"404 not found! GitLab couldn't find what you were looking for! :boom:"
)
end
...
...
@@ -54,7 +60,7 @@ module Mattermost
return
error
(
resource
)
if
resource
.
errors
.
any?
||
!
resource
.
persisted?
message
=
"###
#{
title
(
resource
)
}
"
message
<<
"
\n\n
#{
resource
.
description
}
"
if
resource
.
description
message
<<
"
\n\n
#{
resource
.
description
}
"
if
resource
.
try
(
:description
)
in_channel_response
(
message
)
end
...
...
@@ -74,7 +80,10 @@ module Mattermost
end
def
title
(
resource
)
"[
#{
resource
.
to_reference
}
#{
resource
.
title
}
](
#{
url
(
resource
)
}
)"
reference
=
resource
.
try
(
:to_reference
)
||
resource
.
try
(
:id
)
title
=
resource
.
try
(
:title
)
||
resource
.
try
(
:name
)
"[
#{
reference
}
#{
title
}
](
#{
url
(
resource
)
}
)"
end
def
header_with_list
(
header
,
items
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录