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
Boxiang Sun
gitlab-ce
Commits
f9fb7667
Commit
f9fb7667
authored
Jan 20, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8603 from jubianchi/hook-merge-request-action
Add action property to merge request hook
parents
0af2a161
4ffdb83e
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
141 additions
and
19 deletions
+141
-19
CHANGELOG
CHANGELOG
+1
-1
app/services/merge_requests/base_service.rb
app/services/merge_requests/base_service.rb
+4
-1
app/services/merge_requests/close_service.rb
app/services/merge_requests/close_service.rb
+1
-1
app/services/merge_requests/merge_service.rb
app/services/merge_requests/merge_service.rb
+1
-1
app/services/merge_requests/reopen_service.rb
app/services/merge_requests/reopen_service.rb
+1
-1
app/services/merge_requests/update_service.rb
app/services/merge_requests/update_service.rb
+1
-1
doc/web_hooks/web_hooks.md
doc/web_hooks/web_hooks.md
+3
-1
spec/services/merge_requests/close_service_spec.rb
spec/services/merge_requests/close_service_spec.rb
+12
-3
spec/services/merge_requests/create_service_spec.rb
spec/services/merge_requests/create_service_spec.rb
+14
-5
spec/services/merge_requests/merge_service_spec.rb
spec/services/merge_requests/merge_service_spec.rb
+44
-0
spec/services/merge_requests/reopen_service_spec.rb
spec/services/merge_requests/reopen_service_spec.rb
+45
-0
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+14
-4
No files found.
CHANGELOG
View file @
f9fb7667
...
@@ -42,7 +42,7 @@ v 7.8.0
...
@@ -42,7 +42,7 @@ v 7.8.0
-
-
-
-
-
-
-
-
Add action property to merge request hook (Julien Bianchi)
-
-
-
-
-
-
...
...
app/services/merge_requests/base_service.rb
View file @
f9fb7667
...
@@ -5,9 +5,12 @@ module MergeRequests
...
@@ -5,9 +5,12 @@ module MergeRequests
Note
.
create_status_change_note
(
merge_request
,
merge_request
.
target_project
,
current_user
,
merge_request
.
state
,
nil
)
Note
.
create_status_change_note
(
merge_request
,
merge_request
.
target_project
,
current_user
,
merge_request
.
state
,
nil
)
end
end
def
execute_hooks
(
merge_request
)
def
execute_hooks
(
merge_request
,
action
=
'open'
)
if
merge_request
.
project
if
merge_request
.
project
hook_data
=
merge_request
.
to_hook_data
(
current_user
)
hook_data
=
merge_request
.
to_hook_data
(
current_user
)
merge_request_url
=
Gitlab
::
UrlBuilder
.
new
(
:merge_request
).
build
(
merge_request
.
id
)
hook_data
[
:object_attributes
][
:url
]
=
merge_request_url
hook_data
[
:object_attributes
][
:action
]
=
action
merge_request
.
project
.
execute_hooks
(
hook_data
,
:merge_request_hooks
)
merge_request
.
project
.
execute_hooks
(
hook_data
,
:merge_request_hooks
)
end
end
end
end
...
...
app/services/merge_requests/close_service.rb
View file @
f9fb7667
...
@@ -9,7 +9,7 @@ module MergeRequests
...
@@ -9,7 +9,7 @@ module MergeRequests
event_service
.
close_mr
(
merge_request
,
current_user
)
event_service
.
close_mr
(
merge_request
,
current_user
)
notification_service
.
close_mr
(
merge_request
,
current_user
)
notification_service
.
close_mr
(
merge_request
,
current_user
)
create_note
(
merge_request
)
create_note
(
merge_request
)
execute_hooks
(
merge_request
)
execute_hooks
(
merge_request
,
'close'
)
end
end
merge_request
merge_request
...
...
app/services/merge_requests/merge_service.rb
View file @
f9fb7667
...
@@ -12,7 +12,7 @@ module MergeRequests
...
@@ -12,7 +12,7 @@ module MergeRequests
notification_service
.
merge_mr
(
merge_request
,
current_user
)
notification_service
.
merge_mr
(
merge_request
,
current_user
)
create_merge_event
(
merge_request
,
current_user
)
create_merge_event
(
merge_request
,
current_user
)
create_note
(
merge_request
)
create_note
(
merge_request
)
execute_hooks
(
merge_request
)
execute_hooks
(
merge_request
,
'merge'
)
true
true
rescue
rescue
...
...
app/services/merge_requests/reopen_service.rb
View file @
f9fb7667
...
@@ -5,7 +5,7 @@ module MergeRequests
...
@@ -5,7 +5,7 @@ module MergeRequests
event_service
.
reopen_mr
(
merge_request
,
current_user
)
event_service
.
reopen_mr
(
merge_request
,
current_user
)
notification_service
.
reopen_mr
(
merge_request
,
current_user
)
notification_service
.
reopen_mr
(
merge_request
,
current_user
)
create_note
(
merge_request
)
create_note
(
merge_request
)
execute_hooks
(
merge_request
)
execute_hooks
(
merge_request
,
'reopen'
)
merge_request
.
reload_code
merge_request
.
reload_code
merge_request
.
mark_as_unchecked
merge_request
.
mark_as_unchecked
end
end
...
...
app/services/merge_requests/update_service.rb
View file @
f9fb7667
...
@@ -38,7 +38,7 @@ module MergeRequests
...
@@ -38,7 +38,7 @@ module MergeRequests
end
end
merge_request
.
notice_added_references
(
merge_request
.
project
,
current_user
)
merge_request
.
notice_added_references
(
merge_request
.
project
,
current_user
)
execute_hooks
(
merge_request
)
execute_hooks
(
merge_request
,
'update'
)
end
end
merge_request
merge_request
...
...
doc/web_hooks/web_hooks.md
View file @
f9fb7667
...
@@ -166,7 +166,9 @@ Triggered when a new merge request is created or an existing merge request was u
...
@@ -166,7 +166,9 @@ Triggered when a new merge request is created or an existing merge request was u
"name"
:
"GitLab dev user"
,
"name"
:
"GitLab dev user"
,
"email"
:
"gitlabdev@dv6700.(none)"
"email"
:
"gitlabdev@dv6700.(none)"
}
}
}
},
"url"
:
"http://example.com/diaspora/merge_requests/1"
,
"action"
:
"open"
}
}
}
}
```
```
...
...
spec/services/merge_requests/close_service_spec.rb
View file @
f9fb7667
...
@@ -12,14 +12,23 @@ describe MergeRequests::CloseService do
...
@@ -12,14 +12,23 @@ describe MergeRequests::CloseService do
end
end
describe
:execute
do
describe
:execute
do
context
"valid params"
do
context
'valid params'
do
let
(
:service
)
{
MergeRequests
::
CloseService
.
new
(
project
,
user
,
{})
}
before
do
before
do
@merge_request
=
MergeRequests
::
CloseService
.
new
(
project
,
user
,
{}).
execute
(
merge_request
)
service
.
stub
(
:execute_hooks
)
@merge_request
=
service
.
execute
(
merge_request
)
end
end
it
{
@merge_request
.
should
be_valid
}
it
{
@merge_request
.
should
be_valid
}
it
{
@merge_request
.
should
be_closed
}
it
{
@merge_request
.
should
be_closed
}
it
'should execute hooks with close action'
do
expect
(
service
).
to
have_received
(
:execute_hooks
).
with
(
@merge_request
,
'close'
)
end
it
'should send email to user2 about assign of new merge_request'
do
it
'should send email to user2 about assign of new merge_request'
do
email
=
ActionMailer
::
Base
.
deliveries
.
last
email
=
ActionMailer
::
Base
.
deliveries
.
last
email
.
to
.
first
.
should
==
user2
.
email
email
.
to
.
first
.
should
==
user2
.
email
...
@@ -28,7 +37,7 @@ describe MergeRequests::CloseService do
...
@@ -28,7 +37,7 @@ describe MergeRequests::CloseService do
it
'should create system note about merge_request reassign'
do
it
'should create system note about merge_request reassign'
do
note
=
@merge_request
.
notes
.
last
note
=
@merge_request
.
notes
.
last
note
.
note
.
should
include
"Status changed to closed"
note
.
note
.
should
include
'Status changed to closed'
end
end
end
end
end
end
...
...
spec/services/merge_requests/create_service_spec.rb
View file @
f9fb7667
...
@@ -5,21 +5,30 @@ describe MergeRequests::CreateService do
...
@@ -5,21 +5,30 @@ describe MergeRequests::CreateService do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
describe
:execute
do
describe
:execute
do
context
"valid params"
do
context
'valid params'
do
before
do
let
(
:opts
)
do
project
.
team
<<
[
user
,
:master
]
{
opts
=
{
title:
'Awesome merge_request'
,
title:
'Awesome merge_request'
,
description:
'please fix'
,
description:
'please fix'
,
source_branch:
'stable'
,
source_branch:
'stable'
,
target_branch:
'master'
target_branch:
'master'
}
}
end
let
(
:service
)
{
MergeRequests
::
CreateService
.
new
(
project
,
user
,
opts
)
}
before
do
project
.
team
<<
[
user
,
:master
]
service
.
stub
(
:execute_hooks
)
@merge_request
=
MergeRequests
::
CreateService
.
new
(
project
,
user
,
opts
)
.
execute
@merge_request
=
service
.
execute
end
end
it
{
@merge_request
.
should
be_valid
}
it
{
@merge_request
.
should
be_valid
}
it
{
@merge_request
.
title
.
should
==
'Awesome merge_request'
}
it
{
@merge_request
.
title
.
should
==
'Awesome merge_request'
}
it
'should execute hooks with default action'
do
expect
(
service
).
to
have_received
(
:execute_hooks
).
with
(
@merge_request
)
end
end
end
end
end
end
end
spec/services/merge_requests/merge_service_spec.rb
0 → 100644
View file @
f9fb7667
require
'spec_helper'
describe
MergeRequests
::
MergeService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
assignee:
user2
)
}
let
(
:project
)
{
merge_request
.
project
}
before
do
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user2
,
:developer
]
end
describe
:execute
do
context
'valid params'
do
let
(
:service
)
{
MergeRequests
::
MergeService
.
new
(
project
,
user
,
{})
}
before
do
service
.
stub
(
:execute_hooks
)
service
.
execute
(
merge_request
,
'Awesome message'
)
end
it
{
merge_request
.
should
be_valid
}
it
{
merge_request
.
should
be_merged
}
it
'should execute hooks with merge action'
do
expect
(
service
).
to
have_received
(
:execute_hooks
).
with
(
merge_request
,
'merge'
)
end
it
'should send email to user2 about merge of new merge_request'
do
email
=
ActionMailer
::
Base
.
deliveries
.
last
email
.
to
.
first
.
should
==
user2
.
email
email
.
subject
.
should
include
(
merge_request
.
title
)
end
it
'should create system note about merge_request merge'
do
note
=
merge_request
.
notes
.
last
note
.
note
.
should
include
'Status changed to merged'
end
end
end
end
spec/services/merge_requests/reopen_service_spec.rb
0 → 100644
View file @
f9fb7667
require
'spec_helper'
describe
MergeRequests
::
ReopenService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
assignee:
user2
)
}
let
(
:project
)
{
merge_request
.
project
}
before
do
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user2
,
:developer
]
end
describe
:execute
do
context
'valid params'
do
let
(
:service
)
{
MergeRequests
::
ReopenService
.
new
(
project
,
user
,
{})
}
before
do
service
.
stub
(
:execute_hooks
)
merge_request
.
state
=
:closed
service
.
execute
(
merge_request
)
end
it
{
merge_request
.
should
be_valid
}
it
{
merge_request
.
should
be_reopened
}
it
'should execute hooks with reopen action'
do
expect
(
service
).
to
have_received
(
:execute_hooks
).
with
(
merge_request
,
'reopen'
)
end
it
'should send email to user2 about reopen of merge_request'
do
email
=
ActionMailer
::
Base
.
deliveries
.
last
email
.
to
.
first
.
should
==
user2
.
email
email
.
subject
.
should
include
(
merge_request
.
title
)
end
it
'should create system note about merge_request reopen'
do
note
=
merge_request
.
notes
.
last
note
.
note
.
should
include
'Status changed to reopened'
end
end
end
end
spec/services/merge_requests/update_service_spec.rb
View file @
f9fb7667
...
@@ -12,16 +12,21 @@ describe MergeRequests::UpdateService do
...
@@ -12,16 +12,21 @@ describe MergeRequests::UpdateService do
end
end
describe
:execute
do
describe
:execute
do
context
"valid params"
do
context
'valid params'
do
before
do
let
(
:opts
)
do
opts
=
{
{
title:
'New title'
,
title:
'New title'
,
description:
'Also please fix'
,
description:
'Also please fix'
,
assignee_id:
user2
.
id
,
assignee_id:
user2
.
id
,
state_event:
'close'
state_event:
'close'
}
}
end
let
(
:service
)
{
MergeRequests
::
UpdateService
.
new
(
project
,
user
,
opts
)
}
before
do
service
.
stub
(
:execute_hooks
)
@merge_request
=
MergeRequests
::
UpdateService
.
new
(
project
,
user
,
opts
)
.
execute
(
merge_request
)
@merge_request
=
service
.
execute
(
merge_request
)
end
end
it
{
@merge_request
.
should
be_valid
}
it
{
@merge_request
.
should
be_valid
}
...
@@ -29,6 +34,11 @@ describe MergeRequests::UpdateService do
...
@@ -29,6 +34,11 @@ describe MergeRequests::UpdateService do
it
{
@merge_request
.
assignee
.
should
==
user2
}
it
{
@merge_request
.
assignee
.
should
==
user2
}
it
{
@merge_request
.
should
be_closed
}
it
{
@merge_request
.
should
be_closed
}
it
'should execute hooks with update action'
do
expect
(
service
).
to
have_received
(
:execute_hooks
).
with
(
@merge_request
,
'update'
)
end
it
'should send email to user2 about assign of new merge_request'
do
it
'should send email to user2 about assign of new merge_request'
do
email
=
ActionMailer
::
Base
.
deliveries
.
last
email
=
ActionMailer
::
Base
.
deliveries
.
last
email
.
to
.
first
.
should
==
user2
.
email
email
.
to
.
first
.
should
==
user2
.
email
...
...
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