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
Tatuya Kamada
gitlab-ce
Commits
e59623e7
Commit
e59623e7
authored
Dec 15, 2016
by
jurre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mark MR as WIP when pushing WIP commits
parent
d3f26be6
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
152 additions
and
1 deletion
+152
-1
app/models/commit.rb
app/models/commit.rb
+6
-0
app/services/merge_requests/refresh_service.rb
app/services/merge_requests/refresh_service.rb
+19
-0
app/services/system_note_service.rb
app/services/system_note_service.rb
+6
-0
changelogs/unreleased/wip-mr-from-commits.yml
changelogs/unreleased/wip-mr-from-commits.yml
+4
-0
spec/models/commit_spec.rb
spec/models/commit_spec.rb
+28
-0
spec/services/merge_requests/refresh_service_spec.rb
spec/services/merge_requests/refresh_service_spec.rb
+64
-0
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+23
-0
spec/support/test_env.rb
spec/support/test_env.rb
+2
-1
No files found.
app/models/commit.rb
View file @
e59623e7
...
@@ -326,6 +326,12 @@ class Commit
...
@@ -326,6 +326,12 @@ class Commit
# no-op but needs to be defined since #persisted? is defined
# no-op but needs to be defined since #persisted? is defined
end
end
WIP_REGEX
=
/\A\s*(((?i)(\[WIP\]|WIP:|WIP)\s|WIP$))|(fixup!|squash!)\s/
.
freeze
def
work_in_progress?
!!
(
title
=~
WIP_REGEX
)
end
private
private
def
commit_reference
(
from_project
,
referable_commit_id
,
full:
false
)
def
commit_reference
(
from_project
,
referable_commit_id
,
full:
false
)
...
...
app/services/merge_requests/refresh_service.rb
View file @
e59623e7
...
@@ -21,6 +21,7 @@ module MergeRequests
...
@@ -21,6 +21,7 @@ module MergeRequests
end
end
comment_mr_with_commits
comment_mr_with_commits
mark_mr_as_wip_from_commits
execute_mr_web_hooks
execute_mr_web_hooks
true
true
...
@@ -136,6 +137,24 @@ module MergeRequests
...
@@ -136,6 +137,24 @@ module MergeRequests
end
end
end
end
def
mark_mr_as_wip_from_commits
return
unless
@commits
.
present?
merge_requests_for_source_branch
.
each
do
|
merge_request
|
wip_commit
=
@commits
.
detect
(
&
:work_in_progress?
)
if
wip_commit
&&
!
merge_request
.
work_in_progress?
merge_request
.
update
(
title:
merge_request
.
wip_title
)
SystemNoteService
.
add_merge_request_wip_from_commit
(
merge_request
,
merge_request
.
project
,
@current_user
,
wip_commit
)
end
end
end
# Call merge request webhook with update branches
# Call merge request webhook with update branches
def
execute_mr_web_hooks
def
execute_mr_web_hooks
merge_requests_for_source_branch
.
each
do
|
merge_request
|
merge_requests_for_source_branch
.
each
do
|
merge_request
|
...
...
app/services/system_note_service.rb
View file @
e59623e7
...
@@ -208,6 +208,12 @@ module SystemNoteService
...
@@ -208,6 +208,12 @@ module SystemNoteService
create_note
(
noteable:
noteable
,
project:
project
,
author:
author
,
note:
body
)
create_note
(
noteable:
noteable
,
project:
project
,
author:
author
,
note:
body
)
end
end
def
add_merge_request_wip_from_commit
(
noteable
,
project
,
author
,
commit
)
body
=
"marked as a **Work In Progress** from
#{
commit
.
to_reference
(
project
)
}
"
create_note
(
noteable:
noteable
,
project:
project
,
author:
author
,
note:
body
)
end
def
self
.
resolve_all_discussions
(
merge_request
,
project
,
author
)
def
self
.
resolve_all_discussions
(
merge_request
,
project
,
author
)
body
=
"resolved all discussions"
body
=
"resolved all discussions"
...
...
changelogs/unreleased/wip-mr-from-commits.yml
0 → 100644
View file @
e59623e7
---
title
:
Mark MR as WIP when pushing WIP commits
merge_request
:
8124
author
:
Jurre Stender @jurre
spec/models/commit_spec.rb
View file @
e59623e7
...
@@ -323,4 +323,32 @@ eos
...
@@ -323,4 +323,32 @@ eos
expect
(
new_commit
.
message
).
to
eq
(
commit
.
message
)
expect
(
new_commit
.
message
).
to
eq
(
commit
.
message
)
end
end
end
end
describe
'#work_in_progress?'
do
[
'squash! '
,
'fixup! '
,
'wip: '
,
'WIP: '
,
'[WIP] '
].
each
do
|
wip_prefix
|
it
"detects the '
#{
wip_prefix
}
' prefix"
do
commit
.
message
=
"
#{
wip_prefix
}#{
commit
.
message
}
"
expect
(
commit
).
to
be_work_in_progress
end
end
it
"detects WIP for a commit just saying 'wip'"
do
commit
.
message
=
"wip"
expect
(
commit
).
to
be_work_in_progress
end
it
"doesn't detect WIP for a commit that begins with 'FIXUP! '"
do
commit
.
message
=
"FIXUP!
#{
commit
.
message
}
"
expect
(
commit
).
not_to
be_work_in_progress
end
it
"doesn't detect WIP for words starting with WIP"
do
commit
.
message
=
"Wipout
#{
commit
.
message
}
"
expect
(
commit
).
not_to
be_work_in_progress
end
end
end
end
spec/services/merge_requests/refresh_service_spec.rb
View file @
e59623e7
...
@@ -237,6 +237,70 @@ describe MergeRequests::RefreshService, services: true do
...
@@ -237,6 +237,70 @@ describe MergeRequests::RefreshService, services: true do
end
end
end
end
context
'marking the merge request as work in progress'
do
let
(
:refresh_service
)
{
service
.
new
(
@project
,
@user
)
}
before
do
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
end
it
'marks the merge request as work in progress from fixup commits'
do
fixup_merge_request
=
create
(
:merge_request
,
source_project:
@project
,
source_branch:
'wip'
,
target_branch:
'master'
,
target_project:
@project
)
commits
=
fixup_merge_request
.
commits
oldrev
=
commits
.
last
.
id
newrev
=
commits
.
first
.
id
refresh_service
.
execute
(
oldrev
,
newrev
,
'refs/heads/wip'
)
fixup_merge_request
.
reload
expect
(
fixup_merge_request
.
work_in_progress?
).
to
eq
(
true
)
expect
(
fixup_merge_request
.
notes
.
last
.
note
).
to
match
(
/marked as a \*\*Work In Progress\*\* from
#{
Commit
.
reference_pattern
}
/
)
end
it
'references the commit that caused the Work in Progress status'
do
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
allow
(
refresh_service
).
to
receive
(
:find_new_commits
)
refresh_service
.
instance_variable_set
(
"@commits"
,
[
instance_double
(
Commit
,
id:
'aaaaaaa'
,
short_id:
'aaaaaaa'
,
title:
'Fix issue'
,
work_in_progress?:
false
),
instance_double
(
Commit
,
id:
'bbbbbbb'
,
short_id:
'bbbbbbb'
,
title:
'fixup! Fix issue'
,
work_in_progress?:
true
,
to_reference:
'bbbbbbb'
),
instance_double
(
Commit
,
id:
'ccccccc'
,
short_id:
'ccccccc'
,
title:
'fixup! Fix issue'
,
work_in_progress?:
true
,
to_reference:
'ccccccc'
),
])
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/wip'
)
reload_mrs
expect
(
@merge_request
.
notes
.
last
.
note
).
to
eq
(
"marked as a **Work In Progress** from bbbbbbb"
)
end
end
def
reload_mrs
def
reload_mrs
@merge_request
.
reload
@merge_request
.
reload
@fork_merge_request
.
reload
@fork_merge_request
.
reload
...
...
spec/services/system_note_service_spec.rb
View file @
e59623e7
...
@@ -805,4 +805,27 @@ describe SystemNoteService, services: true do
...
@@ -805,4 +805,27 @@ describe SystemNoteService, services: true do
noteable
.
save!
noteable
.
save!
end
end
end
end
describe
'.add_merge_request_wip_from_commit'
do
let
(
:noteable
)
do
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
end
subject
do
described_class
.
add_merge_request_wip_from_commit
(
noteable
,
project
,
author
,
noteable
.
diff_head_commit
)
end
it_behaves_like
'a system note'
it
"posts the 'marked as a Work In Progress from commit' system note"
do
expect
(
subject
.
note
).
to
match
(
/marked as a \*\*Work In Progress\*\* from
#{
Commit
.
reference_pattern
}
/
)
end
end
end
end
spec/support/test_env.rb
View file @
e59623e7
...
@@ -35,7 +35,8 @@ module TestEnv
...
@@ -35,7 +35,8 @@ module TestEnv
'conflict-missing-side'
=>
'eb227b3'
,
'conflict-missing-side'
=>
'eb227b3'
,
'conflict-non-utf8'
=>
'd0a293c'
,
'conflict-non-utf8'
=>
'd0a293c'
,
'conflict-too-large'
=>
'39fa04f'
,
'conflict-too-large'
=>
'39fa04f'
,
'deleted-image-test'
=>
'6c17798'
'deleted-image-test'
=>
'6c17798'
,
'wip'
=>
'b9238ee'
}
}
# gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily
# gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily
...
...
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