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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
4ffdb83e
Commit
4ffdb83e
authored
Jan 18, 2015
by
jubianchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add action property to merge request hook
parent
b1c79eaf
Changes
12
Hide 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 @
4ffdb83e
...
...
@@ -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 @
4ffdb83e
...
...
@@ -5,9 +5,12 @@ module MergeRequests
Note
.
create_status_change_note
(
merge_request
,
merge_request
.
target_project
,
current_user
,
merge_request
.
state
,
nil
)
end
def
execute_hooks
(
merge_request
)
def
execute_hooks
(
merge_request
,
action
=
'open'
)
if
merge_request
.
project
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
)
end
end
...
...
app/services/merge_requests/close_service.rb
View file @
4ffdb83e
...
...
@@ -9,7 +9,7 @@ module MergeRequests
event_service
.
close_mr
(
merge_request
,
current_user
)
notification_service
.
close_mr
(
merge_request
,
current_user
)
create_note
(
merge_request
)
execute_hooks
(
merge_request
)
execute_hooks
(
merge_request
,
'close'
)
end
merge_request
...
...
app/services/merge_requests/merge_service.rb
View file @
4ffdb83e
...
...
@@ -12,7 +12,7 @@ module MergeRequests
notification_service
.
merge_mr
(
merge_request
,
current_user
)
create_merge_event
(
merge_request
,
current_user
)
create_note
(
merge_request
)
execute_hooks
(
merge_request
)
execute_hooks
(
merge_request
,
'merge'
)
true
rescue
...
...
app/services/merge_requests/reopen_service.rb
View file @
4ffdb83e
...
...
@@ -5,7 +5,7 @@ module MergeRequests
event_service
.
reopen_mr
(
merge_request
,
current_user
)
notification_service
.
reopen_mr
(
merge_request
,
current_user
)
create_note
(
merge_request
)
execute_hooks
(
merge_request
)
execute_hooks
(
merge_request
,
'reopen'
)
merge_request
.
reload_code
merge_request
.
mark_as_unchecked
end
...
...
app/services/merge_requests/update_service.rb
View file @
4ffdb83e
...
...
@@ -38,7 +38,7 @@ module MergeRequests
end
merge_request
.
notice_added_references
(
merge_request
.
project
,
current_user
)
execute_hooks
(
merge_request
)
execute_hooks
(
merge_request
,
'update'
)
end
merge_request
...
...
doc/web_hooks/web_hooks.md
View file @
4ffdb83e
...
...
@@ -166,7 +166,9 @@ Triggered when a new merge request is created or an existing merge request was u
"name"
:
"GitLab dev user"
,
"email"
:
"gitlabdev@dv6700.(none)"
}
}
},
"url"
:
"http://example.com/diaspora/merge_requests/1"
,
"action"
:
"open"
}
}
```
...
...
spec/services/merge_requests/close_service_spec.rb
View file @
4ffdb83e
...
...
@@ -12,14 +12,23 @@ describe MergeRequests::CloseService do
end
describe
:execute
do
context
"valid params"
do
context
'valid params'
do
let
(
:service
)
{
MergeRequests
::
CloseService
.
new
(
project
,
user
,
{})
}
before
do
@merge_request
=
MergeRequests
::
CloseService
.
new
(
project
,
user
,
{}).
execute
(
merge_request
)
service
.
stub
(
:execute_hooks
)
@merge_request
=
service
.
execute
(
merge_request
)
end
it
{
@merge_request
.
should
be_valid
}
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
email
=
ActionMailer
::
Base
.
deliveries
.
last
email
.
to
.
first
.
should
==
user2
.
email
...
...
@@ -28,7 +37,7 @@ describe MergeRequests::CloseService do
it
'should create system note about merge_request reassign'
do
note
=
@merge_request
.
notes
.
last
note
.
note
.
should
include
"Status changed to closed"
note
.
note
.
should
include
'Status changed to closed'
end
end
end
...
...
spec/services/merge_requests/create_service_spec.rb
View file @
4ffdb83e
...
...
@@ -5,21 +5,30 @@ describe MergeRequests::CreateService do
let
(
:user
)
{
create
(
:user
)
}
describe
:execute
do
context
"valid params"
do
before
do
project
.
team
<<
[
user
,
:master
]
opts
=
{
context
'valid params'
do
let
(
:opts
)
do
{
title:
'Awesome merge_request'
,
description:
'please fix'
,
source_branch:
'stable'
,
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
it
{
@merge_request
.
should
be_valid
}
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
spec/services/merge_requests/merge_service_spec.rb
0 → 100644
View file @
4ffdb83e
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 @
4ffdb83e
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 @
4ffdb83e
...
...
@@ -12,16 +12,21 @@ describe MergeRequests::UpdateService do
end
describe
:execute
do
context
"valid params"
do
before
do
opts
=
{
context
'valid params'
do
let
(
:opts
)
do
{
title:
'New title'
,
description:
'Also please fix'
,
assignee_id:
user2
.
id
,
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
it
{
@merge_request
.
should
be_valid
}
...
...
@@ -29,6 +34,11 @@ describe MergeRequests::UpdateService do
it
{
@merge_request
.
assignee
.
should
==
user2
}
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
email
=
ActionMailer
::
Base
.
deliveries
.
last
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