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
a2842241
Commit
a2842241
authored
Jan 03, 2019
by
Tiago Botelho
Committed by
Douwe Maan
Jan 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add committers and authors methods on MergeRequest
These are used by the EE-only approvers feature
parent
cfa71082
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
10 deletions
+77
-10
app/models/commit_collection.rb
app/models/commit_collection.rb
+6
-0
app/models/merge_request.rb
app/models/merge_request.rb
+17
-7
spec/controllers/projects/merge_requests/creations_controller_spec.rb
...lers/projects/merge_requests/creations_controller_spec.rb
+1
-1
spec/models/commit_collection_spec.rb
spec/models/commit_collection_spec.rb
+24
-1
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+28
-0
spec/services/merge_requests/refresh_service_spec.rb
spec/services/merge_requests/refresh_service_spec.rb
+1
-1
No files found.
app/models/commit_collection.rb
View file @
a2842241
...
@@ -19,6 +19,12 @@ class CommitCollection
...
@@ -19,6 +19,12 @@ class CommitCollection
commits
.
each
(
&
block
)
commits
.
each
(
&
block
)
end
end
def
committers
emails
=
commits
.
reject
(
&
:merge_commit?
).
map
(
&
:committer_email
).
uniq
User
.
by_any_email
(
emails
)
end
# Sets the pipeline status for every commit.
# Sets the pipeline status for every commit.
#
#
# Setting this status ahead of time removes the need for running a query for
# Setting this status ahead of time removes the need for running a query for
...
...
app/models/merge_request.rb
View file @
a2842241
...
@@ -284,6 +284,14 @@ class MergeRequest < ActiveRecord::Base
...
@@ -284,6 +284,14 @@ class MergeRequest < ActiveRecord::Base
work_in_progress?
(
title
)
?
title
:
"WIP:
#{
title
}
"
work_in_progress?
(
title
)
?
title
:
"WIP:
#{
title
}
"
end
end
def
committers
@committers
||=
commits
.
committers
end
def
authors
User
.
from_union
([
committers
,
User
.
where
(
id:
self
.
author_id
)])
end
# Verifies if title has changed not taking into account WIP prefix
# Verifies if title has changed not taking into account WIP prefix
# for merge requests.
# for merge requests.
def
wipless_title_changed
(
old_title
)
def
wipless_title_changed
(
old_title
)
...
@@ -327,13 +335,15 @@ class MergeRequest < ActiveRecord::Base
...
@@ -327,13 +335,15 @@ class MergeRequest < ActiveRecord::Base
end
end
def
commits
def
commits
if
persisted?
return
merge_request_diff
.
commits
if
persisted?
merge_request_diff
.
commits
els
if
compare_commits
commits_arr
=
if
compare_commits
compare_commits
.
reverse
compare_commits
.
reverse
else
else
[]
[]
end
end
CommitCollection
.
new
(
source_project
,
commits_arr
,
source_branch
)
end
end
def
commits_count
def
commits_count
...
...
spec/controllers/projects/merge_requests/creations_controller_spec.rb
View file @
a2842241
...
@@ -71,7 +71,7 @@ describe Projects::MergeRequests::CreationsController do
...
@@ -71,7 +71,7 @@ describe Projects::MergeRequests::CreationsController do
expect
(
response
).
to
be_success
expect
(
response
).
to
be_success
total
=
assigns
(
:total_commit_count
)
total
=
assigns
(
:total_commit_count
)
expect
(
assigns
(
:commits
)).
to
be_an
Array
expect
(
assigns
(
:commits
)).
to
be_an
CommitCollection
expect
(
total
).
to
be
>
0
expect
(
total
).
to
be
>
0
expect
(
assigns
(
:hidden_commit_count
)).
to
eq
(
0
)
expect
(
assigns
(
:hidden_commit_count
)).
to
eq
(
0
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
...
...
spec/models/commit_collection_spec.rb
View file @
a2842241
...
@@ -2,7 +2,7 @@ require 'spec_helper'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
CommitCollection
do
describe
CommitCollection
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:commit
)
{
project
.
commit
}
let
(
:commit
)
{
project
.
commit
(
"c1c67abbaf91f624347bb3ae96eabe3a1b742478"
)
}
describe
'#each'
do
describe
'#each'
do
it
'yields every commit'
do
it
'yields every commit'
do
...
@@ -12,6 +12,29 @@ describe CommitCollection do
...
@@ -12,6 +12,29 @@ describe CommitCollection do
end
end
end
end
describe
'.committers'
do
it
'returns a relation of users when users are found'
do
user
=
create
(
:user
,
email:
commit
.
committer_email
.
upcase
)
collection
=
described_class
.
new
(
project
,
[
commit
])
expect
(
collection
.
committers
).
to
contain_exactly
(
user
)
end
it
'returns empty array when committers cannot be found'
do
collection
=
described_class
.
new
(
project
,
[
commit
])
expect
(
collection
.
committers
).
to
be_empty
end
it
'excludes authors of merge commits'
do
commit
=
project
.
commit
(
"60ecb67744cb56576c30214ff52294f8ce2def98"
)
create
(
:user
,
email:
commit
.
committer_email
.
upcase
)
collection
=
described_class
.
new
(
project
,
[
commit
])
expect
(
collection
.
committers
).
to
be_empty
end
end
describe
'#with_pipeline_status'
do
describe
'#with_pipeline_status'
do
it
'sets the pipeline status for every commit so no additional queries are necessary'
do
it
'sets the pipeline status for every commit so no additional queries are necessary'
do
create
(
create
(
...
...
spec/models/merge_request_spec.rb
View file @
a2842241
...
@@ -991,6 +991,34 @@ describe MergeRequest do
...
@@ -991,6 +991,34 @@ describe MergeRequest do
end
end
end
end
describe
'#committers'
do
it
'returns all the committers of every commit in the merge request'
do
users
=
subject
.
commits
.
map
(
&
:committer_email
).
uniq
.
map
do
|
email
|
create
(
:user
,
email:
email
)
end
expect
(
subject
.
committers
).
to
match_array
(
users
)
end
it
'returns an empty array if no committer is associated with a user'
do
expect
(
subject
.
committers
).
to
be_empty
end
end
describe
'#authors'
do
it
'returns a list with all the committers in the merge request and author'
do
users
=
subject
.
commits
.
map
(
&
:committer_email
).
uniq
.
map
do
|
email
|
create
(
:user
,
email:
email
)
end
expect
(
subject
.
authors
).
to
match_array
([
subject
.
author
,
*
users
])
end
it
'returns only the author if no committer is associated with a user'
do
expect
(
subject
.
authors
).
to
contain_exactly
(
subject
.
author
)
end
end
describe
'#hook_attrs'
do
describe
'#hook_attrs'
do
it
'delegates to Gitlab::HookData::MergeRequestBuilder#build'
do
it
'delegates to Gitlab::HookData::MergeRequestBuilder#build'
do
builder
=
double
builder
=
double
...
...
spec/services/merge_requests/refresh_service_spec.rb
View file @
a2842241
...
@@ -509,7 +509,7 @@ describe MergeRequests::RefreshService do
...
@@ -509,7 +509,7 @@ describe MergeRequests::RefreshService do
committed_date:
Time
.
now
committed_date:
Time
.
now
)
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:commits
).
and_return
(
[
commit
]
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:commits
).
and_return
(
CommitCollection
.
new
(
@project
,
[
commit
],
'feature'
)
)
end
end
context
'when the merge request is sourced from the same project'
do
context
'when the merge request is sourced from the same project'
do
...
...
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