BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
b5f9d4c4
Commit
b5f9d4c4
authored
Oct 14, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce Pipeline#merge_requests_with_active_first,
Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6019#note_16956802
parent
5b9971fa
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
7 deletions
+51
-7
pipelines.rb
app/mailers/emails/pipelines.rb
+1
-4
pipeline.rb
app/models/ci/pipeline.rb
+7
-3
merge_request.rb
app/models/merge_request.rb
+4
-0
pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+31
-0
merge_request_spec.rb
spec/models/merge_request_spec.rb
+8
-0
No files found.
app/mailers/emails/pipelines.rb
View file @
b5f9d4c4
...
...
@@ -13,10 +13,7 @@ module Emails
def
pipeline_mail
(
pipeline
,
to
,
status
)
@project
=
pipeline
.
project
@pipeline
=
pipeline
@merge_request
=
@project
.
merge_requests
.
opened
.
find_by
(
source_project:
@project
,
source_branch:
@pipeline
.
ref
,
target_branch:
@project
.
default_branch
)
@merge_request
=
pipeline
.
merge_requests_with_active_first
.
first
add_headers
mail
(
to:
to
,
subject:
pipeline_subject
(
status
),
skip_premailer:
true
)
do
|
format
|
...
...
app/models/ci/pipeline.rb
View file @
b5f9d4c4
...
...
@@ -293,9 +293,13 @@ module Ci
# the merge request's latest commit.
def
merge_requests
@merge_requests
||=
begin
project
.
merge_requests
.
where
(
source_branch:
self
.
ref
).
select
{
|
merge_request
|
merge_request
.
pipeline
.
try
(
:id
)
==
self
.
id
}
project
.
merge_requests
.
where
(
source_branch:
ref
).
select
{
|
merge_request
|
merge_request
.
pipeline
.
try
(
:id
)
==
id
}
end
def
merge_requests_with_active_first
merge_requests
.
sort_by
do
|
merge_request
|
[
merge_request
.
state_priority
,
-
merge_request
.
updated_at
.
to_i
]
end
end
...
...
app/models/merge_request.rb
View file @
b5f9d4c4
...
...
@@ -169,6 +169,10 @@ class MergeRequest < ActiveRecord::Base
work_in_progress?
(
title
)
?
title
:
"WIP:
#{
title
}
"
end
def
state_priority
%w[opened reopened closed merged locked]
.
index
(
state
)
end
def
to_reference
(
from_project
=
nil
)
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
iid
}
"
...
...
spec/models/ci/pipeline_spec.rb
View file @
b5f9d4c4
...
...
@@ -523,4 +523,35 @@ describe Ci::Pipeline, models: true do
expect
(
pipeline
.
merge_requests
).
to
be_empty
end
end
describe
'#merge_requests_with_active_first'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:pipeline
)
do
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
'master'
,
sha:
project
.
repository
.
commit
(
'master'
).
sha
)
end
let!
(
:merge_requests
)
do
[
create_merge_request
(
:merged
,
Time
.
at
(
0
)),
create_merge_request
(
:merged
,
Time
.
at
(
9
)),
create_merge_request
(
:opened
,
Time
.
at
(
0
))]
end
it
'returns opened/recent merge requests first, then closed ones'
do
expect
(
pipeline
.
merge_requests_with_active_first
).
to
eq
(
merge_requests
.
reverse
)
end
def
create_merge_request
(
state
,
updated_at
)
create
(
:merge_request
,
source_project:
project
,
source_branch:
pipeline
.
ref
,
state:
state
,
updated_at:
updated_at
)
end
end
end
spec/models/merge_request_spec.rb
View file @
b5f9d4c4
...
...
@@ -58,6 +58,14 @@ describe MergeRequest, models: true do
it
{
is_expected
.
to
respond_to
(
:merge_when_build_succeeds
)
}
end
describe
'#state_priority'
do
it
'returns the priority of state'
do
%w[opened reopened closed merged locked]
.
each
.
with_index
do
|
state
,
idx
|
expect
(
MergeRequest
.
new
(
state:
state
).
state_priority
).
to
eq
(
idx
)
end
end
end
describe
'.in_projects'
do
it
'returns the merge requests for a set of projects'
do
expect
(
described_class
.
in_projects
(
Project
.
all
)).
to
eq
([
subject
])
...
...
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