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
Boxiang Sun
gitlab-ce
Commits
2ccee716
Commit
2ccee716
authored
May 05, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small code improvements and add migration spec
parent
d9bebd89
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
72 additions
and
19 deletions
+72
-19
app/services/ci/create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+2
-3
db/migrate/20170507205316_add_head_pipeline_id_to_merge_requests.rb
.../20170507205316_add_head_pipeline_id_to_merge_requests.rb
+0
-0
db/post_migrate/20170508170547_add_head_pipeline_for_each_merge_request.rb
...0170508170547_add_head_pipeline_for_each_merge_request.rb
+0
-0
db/schema.rb
db/schema.rb
+1
-2
spec/features/cycle_analytics_spec.rb
spec/features/cycle_analytics_spec.rb
+2
-4
spec/lib/gitlab/import_export/all_models.yml
spec/lib/gitlab/import_export/all_models.yml
+1
-0
spec/migrations/add_head_pipeline_for_each_merge_request_spec.rb
...grations/add_head_pipeline_for_each_merge_request_spec.rb
+33
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+1
-2
spec/services/ci/create_pipeline_service_spec.rb
spec/services/ci/create_pipeline_service_spec.rb
+32
-8
No files found.
app/services/ci/create_pipeline_service.rb
View file @
2ccee716
...
@@ -119,9 +119,8 @@ module Ci
...
@@ -119,9 +119,8 @@ module Ci
end
end
def
update_merge_requests_head_pipeline
def
update_merge_requests_head_pipeline
merge_requests
=
MergeRequest
.
where
(
source_branch:
@pipeline
.
ref
,
source_project:
@pipeline
.
project
)
MergeRequest
.
where
(
source_branch:
@pipeline
.
ref
,
source_project:
@pipeline
.
project
).
update_all
(
head_pipeline_id:
@pipeline
.
id
)
merge_requests
.
update_all
(
head_pipeline_id:
@pipeline
.
id
)
if
merge_requests
.
any?
end
end
def
error
(
message
,
save:
false
)
def
error
(
message
,
save:
false
)
...
...
db/migrate/20170
42
7205316_add_head_pipeline_id_to_merge_requests.rb
→
db/migrate/20170
50
7205316_add_head_pipeline_id_to_merge_requests.rb
View file @
2ccee716
File moved
db/post_migrate/20170
42
8170547_add_head_pipeline_for_each_merge_request.rb
→
db/post_migrate/20170
50
8170547_add_head_pipeline_for_each_merge_request.rb
View file @
2ccee716
File moved
db/schema.rb
View file @
2ccee716
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2017050
618551
7
)
do
ActiveRecord
::
Schema
.
define
(
version:
2017050
817054
7
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
@@ -114,7 +114,6 @@ ActiveRecord::Schema.define(version: 20170506185517) do
...
@@ -114,7 +114,6 @@ ActiveRecord::Schema.define(version: 20170506185517) do
t
.
string
"plantuml_url"
t
.
string
"plantuml_url"
t
.
boolean
"plantuml_enabled"
t
.
boolean
"plantuml_enabled"
t
.
integer
"terminal_max_session_time"
,
default:
0
,
null:
false
t
.
integer
"terminal_max_session_time"
,
default:
0
,
null:
false
t
.
string
"default_artifacts_expire_in"
,
default:
"0"
,
null:
false
t
.
integer
"unique_ips_limit_per_user"
t
.
integer
"unique_ips_limit_per_user"
t
.
integer
"unique_ips_limit_time_window"
t
.
integer
"unique_ips_limit_time_window"
t
.
boolean
"unique_ips_limit_enabled"
,
default:
false
,
null:
false
t
.
boolean
"unique_ips_limit_enabled"
,
default:
false
,
null:
false
...
...
spec/features/cycle_analytics_spec.rb
View file @
2ccee716
...
@@ -9,10 +9,6 @@ feature 'Cycle Analytics', feature: true, js: true do
...
@@ -9,10 +9,6 @@ feature 'Cycle Analytics', feature: true, js: true do
let
(
:mr
)
{
create_merge_request_closing_issue
(
issue
,
commit_message:
"References
#{
issue
.
to_reference
}
"
)
}
let
(
:mr
)
{
create_merge_request_closing_issue
(
issue
,
commit_message:
"References
#{
issue
.
to_reference
}
"
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
mr
.
source_branch
,
sha:
mr
.
source_branch_sha
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
mr
.
source_branch
,
sha:
mr
.
source_branch_sha
)
}
before
do
allow_any_instance_of
(
Gitlab
::
ReferenceExtractor
).
to
receive
(
:issues
).
and_return
([
issue
])
end
context
'as an allowed user'
do
context
'as an allowed user'
do
context
'when project is new'
do
context
'when project is new'
do
before
do
before
do
...
@@ -36,8 +32,10 @@ feature 'Cycle Analytics', feature: true, js: true do
...
@@ -36,8 +32,10 @@ feature 'Cycle Analytics', feature: true, js: true do
context
"when there's cycle analytics data"
do
context
"when there's cycle analytics data"
do
before
do
before
do
allow_any_instance_of
(
Gitlab
::
ReferenceExtractor
).
to
receive
(
:issues
).
and_return
([
issue
])
mr
.
update
(
head_pipeline:
pipeline
)
mr
.
update
(
head_pipeline:
pipeline
)
project
.
add_master
(
user
)
project
.
add_master
(
user
)
create_cycle
create_cycle
deploy_master
deploy_master
...
...
spec/lib/gitlab/import_export/all_models.yml
View file @
2ccee716
...
@@ -103,6 +103,7 @@ pipelines:
...
@@ -103,6 +103,7 @@ pipelines:
-
manual_actions
-
manual_actions
-
artifacts
-
artifacts
-
pipeline_schedule
-
pipeline_schedule
-
merge_requests
statuses
:
statuses
:
-
project
-
project
-
pipeline
-
pipeline
...
...
spec/migrations/add_head_pipeline_for_each_merge_request_spec.rb
0 → 100644
View file @
2ccee716
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20170508170547_add_head_pipeline_for_each_merge_request.rb'
)
describe
AddHeadPipelineForEachMergeRequest
do
let
(
:migration
)
{
described_class
.
new
}
let!
(
:project
)
{
create
(
:empty_project
)
}
let!
(
:forked_project_link
)
{
create
(
:forked_project_link
,
forked_from_project:
project
)
}
let!
(
:other_project
)
{
forked_project_link
.
forked_to_project
}
let!
(
:pipeline_1
)
{
create
(
:ci_pipeline
,
project:
project
,
ref:
"branch_1"
)
}
let!
(
:pipeline_2
)
{
create
(
:ci_pipeline
,
project:
other_project
,
ref:
"branch_1"
)
}
let!
(
:pipeline_3
)
{
create
(
:ci_pipeline
,
project:
other_project
,
ref:
"branch_1"
)
}
let!
(
:pipeline_4
)
{
create
(
:ci_pipeline
,
project:
project
,
ref:
"branch_2"
)
}
let!
(
:mr_1
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
,
source_branch:
"branch_1"
,
target_branch:
"target_1"
)
}
let!
(
:mr_2
)
{
create
(
:merge_request
,
source_project:
other_project
,
target_project:
project
,
source_branch:
"branch_1"
,
target_branch:
"target_2"
)
}
let!
(
:mr_3
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
,
source_branch:
"branch_2"
,
target_branch:
"master"
)
}
let!
(
:mr_4
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
,
source_branch:
"branch_3"
,
target_branch:
"master"
)
}
context
"#up"
do
context
"when source_project and source_branch of pipeline are the same of merge request"
do
it
"sets head_pipeline_id of given merge requests"
do
migration
.
up
expect
(
mr_1
.
reload
.
head_pipeline_id
).
to
eq
(
pipeline_1
.
id
)
expect
(
mr_2
.
reload
.
head_pipeline_id
).
to
eq
(
pipeline_3
.
id
)
expect
(
mr_3
.
reload
.
head_pipeline_id
).
to
eq
(
pipeline_4
.
id
)
expect
(
mr_4
.
reload
.
head_pipeline_id
).
to
be_nil
end
end
end
end
spec/models/merge_request_spec.rb
View file @
2ccee716
...
@@ -760,8 +760,7 @@ describe MergeRequest, models: true do
...
@@ -760,8 +760,7 @@ describe MergeRequest, models: true do
describe
'#head_pipeline'
do
describe
'#head_pipeline'
do
describe
'when the source project exists'
do
describe
'when the source project exists'
do
it
'returns the latest pipeline'
do
it
'returns the latest pipeline'
do
sha
=
"123abc"
pipeline
=
create
(
:ci_empty_pipeline
,
project:
subject
.
source_project
,
ref:
'master'
,
status:
'running'
,
sha:
"123abc"
)
pipeline
=
create
(
:ci_empty_pipeline
,
project:
subject
.
source_project
,
ref:
'master'
,
status:
'running'
,
sha:
sha
)
subject
.
update
(
head_pipeline:
pipeline
)
subject
.
update
(
head_pipeline:
pipeline
)
expect
(
subject
.
head_pipeline
).
to
eq
(
pipeline
)
expect
(
subject
.
head_pipeline
).
to
eq
(
pipeline
)
...
...
spec/services/ci/create_pipeline_service_spec.rb
View file @
2ccee716
...
@@ -34,16 +34,40 @@ describe Ci::CreatePipelineService, services: true do
...
@@ -34,16 +34,40 @@ describe Ci::CreatePipelineService, services: true do
it
{
expect
(
pipeline
).
to
have_attributes
(
status:
'pending'
)
}
it
{
expect
(
pipeline
).
to
have_attributes
(
status:
'pending'
)
}
it
{
expect
(
pipeline
.
builds
.
first
).
to
be_kind_of
(
Ci
::
Build
)
}
it
{
expect
(
pipeline
.
builds
.
first
).
to
be_kind_of
(
Ci
::
Build
)
}
it
'updates head pipeline of each merge request
'
do
context
'#update_merge_requests_head_pipeline
'
do
merge_request_1
=
create
(
:merge_request
,
source_branch:
'master'
,
target_branch:
"branch_1"
,
source_project:
project
)
it
'updates head pipeline of each merge request'
do
merge_request_2
=
create
(
:merge_request
,
source_branch:
'master'
,
target_branch:
"branch_2
"
,
source_project:
project
)
merge_request_1
=
create
(
:merge_request
,
source_branch:
'master'
,
target_branch:
"branch_1
"
,
source_project:
project
)
merge_request_3
=
create
(
:merge_request
,
source_branch:
'other_branch
'
,
target_branch:
"branch_2"
,
source_project:
project
)
merge_request_2
=
create
(
:merge_request
,
source_branch:
'master
'
,
target_branch:
"branch_2"
,
source_project:
project
)
head_pipeline
=
pipeline
head_pipeline
=
pipeline
expect
(
merge_request_1
.
reload
.
head_pipeline
).
to
eq
(
head_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_2
.
reload
.
head_pipeline
).
to
eq
(
head_pipeline
)
expect
(
merge_request_3
.
reload
.
head_pipeline
).
to
be_nil
end
context
'when there is no pipeline for source branch'
do
it
"does not update merge request head pipeline"
do
merge_request
=
create
(
:merge_request
,
source_branch:
'other_branch'
,
target_branch:
"branch_1"
,
source_project:
project
)
head_pipeline
=
pipeline
expect
(
merge_request
.
reload
.
head_pipeline
).
not_to
eq
(
head_pipeline
)
end
end
context
'when merge request target project is different from source project'
do
let!
(
:target_project
)
{
create
(
:empty_project
)
}
let!
(
:forked_project_link
)
{
create
(
:forked_project_link
,
forked_to_project:
project
,
forked_from_project:
target_project
)
}
it
'updates head pipeline for merge request'
do
merge_request
=
create
(
:merge_request
,
source_branch:
'master'
,
target_branch:
"branch_1"
,
source_project:
project
,
target_project:
target_project
)
head_pipeline
=
pipeline
expect
(
merge_request
.
reload
.
head_pipeline
).
to
eq
(
head_pipeline
)
end
end
end
end
context
'auto-cancel enabled'
do
context
'auto-cancel enabled'
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