Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
1d16f137
Commit
1d16f137
authored
Nov 21, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add deploy chat command [ci skip]
parent
c99522f2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
14 deletions
+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
No files found.
app/models/environment.rb
View file @
1d16f137
...
@@ -19,7 +19,7 @@ class Environment < ActiveRecord::Base
...
@@ -19,7 +19,7 @@ class Environment < ActiveRecord::Base
allow_nil:
true
,
allow_nil:
true
,
addressable_url:
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
:available
,
->
{
with_state
(
:available
)
}
scope
:stopped
,
->
{
with_state
(
:stopped
)
}
scope
:stopped
,
->
{
with_state
(
:stopped
)
}
...
@@ -99,4 +99,12 @@ class Environment < ActiveRecord::Base
...
@@ -99,4 +99,12 @@ class Environment < ActiveRecord::Base
stop
stop
stop_action
.
play
(
current_user
)
stop_action
.
play
(
current_user
)
end
end
def
actions_for
(
environment
)
return
[]
unless
manual_actions
manual_actions
.
select
|
action
|
action
.
expanded_environment_name
=
environment
end
end
end
end
lib/gitlab/chat_commands/deploy.rb
0 → 100644
View file @
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
View file @
1d16f137
module
Gitlab
module
ChatCommands
Result
=
Struct
.
new
(
:type
,
:message
)
end
end
lib/mattermost/presenter.rb
View file @
1d16f137
...
@@ -24,20 +24,22 @@ module Mattermost
...
@@ -24,20 +24,22 @@ module Mattermost
end
end
end
end
def
present
(
resource
)
def
present
(
subject
)
return
not_found
unless
resource
return
not_found
unless
subject
if
resource
.
respond_to?
(
:count
)
if
subject
.
is_a?
(
Gitlab
::
ChatCommands
::
Result
)
if
resource
.
count
>
1
show_result
(
subject
)
return
multiple_resources
(
resource
)
elsif
subject
.
respond_to?
(
:count
)
elsif
resource
.
count
==
0
if
subject
.
try
(
:many?
)
return
not_found
multiple_resources
(
subject
)
elsif
subject
.
count
==
0
not_found
else
else
resource
=
resource
.
first
single_resource
(
subject
)
end
end
else
single_resource
(
subject
)
end
end
single_resource
(
resource
)
end
end
def
access_denied
def
access_denied
...
@@ -46,6 +48,10 @@ module Mattermost
...
@@ -46,6 +48,10 @@ module Mattermost
private
private
def
show_result
(
result
)
ephemeral_response
(
result
.
message
)
end
def
not_found
def
not_found
ephemeral_response
(
"404 not found! GitLab couldn't find what you were looking for! :boom:"
)
ephemeral_response
(
"404 not found! GitLab couldn't find what you were looking for! :boom:"
)
end
end
...
@@ -54,7 +60,7 @@ module Mattermost
...
@@ -54,7 +60,7 @@ module Mattermost
return
error
(
resource
)
if
resource
.
errors
.
any?
||
!
resource
.
persisted?
return
error
(
resource
)
if
resource
.
errors
.
any?
||
!
resource
.
persisted?
message
=
"###
#{
title
(
resource
)
}
"
message
=
"###
#{
title
(
resource
)
}
"
message
<<
"
\n\n
#{
resource
.
description
}
"
if
resource
.
description
message
<<
"
\n\n
#{
resource
.
description
}
"
if
resource
.
try
(
:description
)
in_channel_response
(
message
)
in_channel_response
(
message
)
end
end
...
@@ -74,7 +80,10 @@ module Mattermost
...
@@ -74,7 +80,10 @@ module Mattermost
end
end
def
title
(
resource
)
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
end
def
header_with_list
(
header
,
items
)
def
header_with_list
(
header
,
items
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment