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
Jérome Perrin
gitlab-ce
Commits
4ae411ff
Commit
4ae411ff
authored
Mar 17, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preloads head pipeline for each merge request
parent
11ff9fc6
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
36 additions
and
8 deletions
+36
-8
app/controllers/concerns/issuable_collections.rb
app/controllers/concerns/issuable_collections.rb
+1
-1
app/models/merge_request.rb
app/models/merge_request.rb
+2
-6
app/services/ci/create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+7
-1
changelogs/unreleased/issue_27168_2.yml
changelogs/unreleased/issue_27168_2.yml
+4
-0
db/migrate/20170427205316_add_head_pipeline_id_to_merge_requests.rb
.../20170427205316_add_head_pipeline_id_to_merge_requests.rb
+7
-0
db/schema.rb
db/schema.rb
+2
-0
spec/lib/gitlab/import_export/safe_model_attributes.yml
spec/lib/gitlab/import_export/safe_model_attributes.yml
+1
-0
spec/services/ci/create_pipeline_service_spec.rb
spec/services/ci/create_pipeline_service_spec.rb
+12
-0
No files found.
app/controllers/concerns/issuable_collections.rb
View file @
4ae411ff
...
...
@@ -47,7 +47,7 @@ module IssuableCollections
end
def
merge_requests_collection
merge_requests_finder
.
execute
.
preload
(
:source_project
,
:target_project
,
:author
,
:assignee
,
:labels
,
:milestone
,
:merge_request_diff
,
target_project: :namespace
)
merge_requests_finder
.
execute
.
preload
(
:source_project
,
:target_project
,
:author
,
:assignee
,
:labels
,
:milestone
,
:merge_request_diff
,
:head_pipeline
,
target_project: :namespace
)
end
def
issues_finder
...
...
app/models/merge_request.rb
View file @
4ae411ff
...
...
@@ -13,6 +13,8 @@ class MergeRequest < ActiveRecord::Base
has_one
:merge_request_diff
,
->
{
order
(
'merge_request_diffs.id DESC'
)
}
belongs_to
:head_pipeline
,
foreign_key:
"head_pipeline_id"
,
class_name:
"Ci::Pipeline"
has_many
:events
,
as: :target
,
dependent: :destroy
has_many
:merge_requests_closing_issues
,
class_name:
'MergeRequestsClosingIssues'
,
dependent: :delete_all
...
...
@@ -829,12 +831,6 @@ class MergeRequest < ActiveRecord::Base
diverged_commits_count
>
0
end
def
head_pipeline
return
unless
diff_head_sha
&&
source_project
@head_pipeline
||=
source_project
.
pipeline_for
(
source_branch
,
diff_head_sha
)
end
def
all_pipelines
return
Ci
::
Pipeline
.
none
unless
source_project
...
...
app/services/ci/create_pipeline_service.rb
View file @
4ae411ff
...
...
@@ -47,7 +47,7 @@ module Ci
end
Ci
::
Pipeline
.
transaction
do
pipeline
.
save
update_merge_requests_head_pipeline
if
pipeline
.
save
Ci
::
CreatePipelineBuildsService
.
new
(
project
,
current_user
)
...
...
@@ -118,6 +118,12 @@ module Ci
origin_sha
&&
origin_sha
!=
Gitlab
::
Git
::
BLANK_SHA
end
def
update_merge_requests_head_pipeline
merge_requests
=
MergeRequest
.
where
(
source_branch:
@pipeline
.
ref
,
source_project:
@pipeline
.
project
)
merge_requests
.
update_all
(
head_pipeline_id:
@pipeline
.
id
)
if
merge_requests
.
any?
end
def
error
(
message
,
save:
false
)
pipeline
.
errors
.
add
(
:base
,
message
)
pipeline
.
drop
if
save
...
...
changelogs/unreleased/issue_27168_2.yml
0 → 100644
View file @
4ae411ff
---
title
:
Preloads head pipeline for each merge request
merge_request
:
author
:
db/migrate/20170427205316_add_head_pipeline_id_to_merge_requests.rb
0 → 100644
View file @
4ae411ff
class
AddHeadPipelineIdToMergeRequests
<
ActiveRecord
::
Migration
DOWNTIME
=
false
def
change
add_column
:merge_requests
,
:head_pipeline_id
,
:integer
end
end
db/schema.rb
View file @
4ae411ff
...
...
@@ -123,6 +123,7 @@ ActiveRecord::Schema.define(version: 20170506185517) do
t
.
integer
"cached_markdown_version"
t
.
boolean
"clientside_sentry_enabled"
,
default:
false
,
null:
false
t
.
string
"clientside_sentry_dsn"
t
.
string
"default_artifacts_expire_in"
,
default:
"0"
,
null:
false
end
create_table
"audit_events"
,
force: :cascade
do
|
t
|
...
...
@@ -690,6 +691,7 @@ ActiveRecord::Schema.define(version: 20170506185517) do
t
.
integer
"cached_markdown_version"
t
.
datetime
"last_edited_at"
t
.
integer
"last_edited_by_id"
t
.
integer
"head_pipeline_id"
end
add_index
"merge_requests"
,
[
"assignee_id"
],
name:
"index_merge_requests_on_assignee_id"
,
using: :btree
...
...
spec/lib/gitlab/import_export/safe_model_attributes.yml
View file @
4ae411ff
...
...
@@ -158,6 +158,7 @@ MergeRequest:
-
time_estimate
-
last_edited_at
-
last_edited_by_id
-
head_pipeline_id
MergeRequestDiff
:
-
id
-
state
...
...
spec/services/ci/create_pipeline_service_spec.rb
View file @
4ae411ff
...
...
@@ -34,6 +34,18 @@ describe Ci::CreatePipelineService, services: true do
it
{
expect
(
pipeline
).
to
have_attributes
(
status:
'pending'
)
}
it
{
expect
(
pipeline
.
builds
.
first
).
to
be_kind_of
(
Ci
::
Build
)
}
it
'updates head pipeline of each merge request'
do
merge_request_1
=
create
(
:merge_request
,
source_branch:
'master'
,
target_branch:
"branch_1"
,
source_project:
project
)
merge_request_2
=
create
(
:merge_request
,
source_branch:
'master'
,
target_branch:
"branch_2"
,
source_project:
project
)
merge_request_3
=
create
(
:merge_request
,
source_branch:
'other_branch'
,
target_branch:
"branch_2"
,
source_project:
project
)
head_pipeline
=
pipeline
expect
(
merge_request_1
.
reload
.
head_pipeline
).
to
eq
(
head_pipeline
)
expect
(
merge_request_2
.
reload
.
head_pipeline
).
to
eq
(
head_pipeline
)
expect
(
merge_request_3
.
reload
.
head_pipeline
).
to
be_nil
end
context
'auto-cancel enabled'
do
before
do
project
.
update
(
auto_cancel_pending_pipelines:
'enabled'
)
...
...
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