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
163983e0
Commit
163983e0
authored
May 24, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add triggered by to pipeline to support relation between dependent pipelines
parent
0a70942f
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
178 additions
and
8 deletions
+178
-8
app/models/ci/build.rb
app/models/ci/build.rb
+2
-0
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+7
-0
app/models/ci/sources/pipeline.rb
app/models/ci/sources/pipeline.rb
+14
-0
app/models/project.rb
app/models/project.rb
+4
-0
app/serializers/pipeline_details_entity.rb
app/serializers/pipeline_details_entity.rb
+3
-0
app/serializers/pipeline_serializer.rb
app/serializers/pipeline_serializer.rb
+2
-0
app/serializers/triggered_pipeline_entity.rb
app/serializers/triggered_pipeline_entity.rb
+30
-0
app/workers/expire_pipeline_cache_worker.rb
app/workers/expire_pipeline_cache_worker.rb
+10
-4
db/fixtures/development/14_pipelines.rb
db/fixtures/development/14_pipelines.rb
+14
-3
db/migrate/20170525174157_create_pipeline_source_pipeline.rb
db/migrate/20170525174157_create_pipeline_source_pipeline.rb
+16
-0
db/migrate/20170525174158_add_ci_pipeline_source_pipeline_indexes.rb
...20170525174158_add_ci_pipeline_source_pipeline_indexes.rb
+25
-0
db/migrate/20170525174159_add_ci_pipeline_source_pipeline_foreign_key.rb
...0525174159_add_ci_pipeline_source_pipeline_foreign_key.rb
+25
-0
db/schema.rb
db/schema.rb
+19
-0
spec/lib/gitlab/import_export/all_models.yml
spec/lib/gitlab/import_export/all_models.yml
+6
-0
spec/serializers/pipeline_serializer_spec.rb
spec/serializers/pipeline_serializer_spec.rb
+1
-1
No files found.
app/models/ci/build.rb
View file @
163983e0
...
...
@@ -9,6 +9,8 @@ module Ci
belongs_to
:trigger_request
belongs_to
:erased_by
,
class_name:
'User'
has_many
:sourced_pipelines
,
class_name:
Ci
::
Sources
::
Pipeline
,
foreign_key: :source_job_id
has_many
:deployments
,
as: :deployable
has_one
:last_deployment
,
->
{
order
(
'deployments.id DESC'
)
},
as: :deployable
,
class_name:
'Deployment'
...
...
app/models/ci/pipeline.rb
View file @
163983e0
...
...
@@ -11,6 +11,13 @@ module Ci
belongs_to
:auto_canceled_by
,
class_name:
'Ci::Pipeline'
belongs_to
:pipeline_schedule
,
class_name:
'Ci::PipelineSchedule'
has_one
:source_pipeline
,
class_name:
Ci
::
Sources
::
Pipeline
has_many
:sourced_pipelines
,
class_name:
Ci
::
Sources
::
Pipeline
,
foreign_key: :source_pipeline_id
has_one
:triggered_by_pipeline
,
through: :source_pipeline
,
source: :source_pipeline
has_many
:triggered_pipelines
,
through: :sourced_pipelines
,
source: :pipeline
has_many
:auto_canceled_pipelines
,
class_name:
'Ci::Pipeline'
,
foreign_key:
'auto_canceled_by_id'
has_many
:auto_canceled_jobs
,
class_name:
'CommitStatus'
,
foreign_key:
'auto_canceled_by_id'
...
...
app/models/ci/sources/pipeline.rb
0 → 100644
View file @
163983e0
module
Ci
module
Sources
class
Pipeline
<
ActiveRecord
::
Base
self
.
table_name
=
"ci_sources_pipelines"
belongs_to
:project
,
class_name:
Project
belongs_to
:pipeline
,
class_name:
Ci
::
Pipeline
belongs_to
:source_project
,
class_name:
Project
,
foreign_key: :source_project_id
belongs_to
:source_job
,
class_name:
Ci
::
Build
,
foreign_key: :source_job_id
belongs_to
:source_pipeline
,
class_name:
Ci
::
Pipeline
,
foreign_key: :source_pipeline_id
end
end
end
app/models/project.rb
View file @
163983e0
...
...
@@ -187,6 +187,10 @@ class Project < ActiveRecord::Base
has_many
:deployments
,
dependent: :destroy
has_many
:pipeline_schedules
,
dependent: :destroy
,
class_name:
'Ci::PipelineSchedule'
has_many
:sourced_pipelines
,
class_name:
Ci
::
Sources
::
Pipeline
,
foreign_key: :source_project_id
has_many
:source_pipelines
,
class_name:
Ci
::
Sources
::
Pipeline
,
foreign_key: :project_id
has_many
:path_locks
,
dependent: :destroy
has_many
:active_runners
,
->
{
active
},
through: :runner_projects
,
source: :runner
,
class_name:
'Ci::Runner'
...
...
app/serializers/pipeline_details_entity.rb
View file @
163983e0
...
...
@@ -4,4 +4,7 @@ class PipelineDetailsEntity < PipelineEntity
expose
:artifacts
,
using:
BuildArtifactEntity
expose
:manual_actions
,
using:
BuildActionEntity
end
expose
:triggered_by_pipeline
,
as: :triggered_by
,
with:
TriggeredPipelineEntity
expose
:triggered_pipelines
,
as: :triggered
,
using:
TriggeredPipelineEntity
end
app/serializers/pipeline_serializer.rb
View file @
163983e0
...
...
@@ -18,6 +18,8 @@ class PipelineSerializer < BaseSerializer
:cancelable_statuses
,
:trigger_requests
,
:project
,
{
triggered_by_pipeline:
[
:project
,
:user
]
},
{
triggered_pipelines:
[
:project
,
:user
]
},
{
pending_builds: :project
},
{
manual_actions: :project
},
{
artifacts: :project
}
...
...
app/serializers/triggered_pipeline_entity.rb
0 → 100644
View file @
163983e0
class
TriggeredPipelineEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:id
expose
:user
,
using:
UserEntity
expose
:active?
,
as: :active
expose
:coverage
expose
:source
expose
:path
do
|
pipeline
|
namespace_project_pipeline_path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
pipeline
)
end
expose
:details
do
expose
:detailed_status
,
as: :status
,
with:
StatusEntity
end
expose
:project
,
using:
ProjectEntity
private
alias_method
:pipeline
,
:object
def
detailed_status
pipeline
.
detailed_status
(
request
.
current_user
)
end
end
app/workers/expire_pipeline_cache_worker.rb
View file @
163983e0
...
...
@@ -10,13 +10,19 @@ class ExpirePipelineCacheWorker
store
=
Gitlab
::
EtagCaching
::
Store
.
new
store
.
touch
(
project_pipelines_path
(
project
))
store
.
touch
(
project_pipeline_path
(
p
roject
,
p
ipeline
))
store
.
touch
(
project_pipeline_path
(
pipeline
))
store
.
touch
(
commit_pipelines_path
(
project
,
pipeline
.
commit
))
if
pipeline
.
commit
store
.
touch
(
new_merge_request_pipelines_path
(
project
))
each_pipelines_merge_request_path
(
project
,
pipeline
)
do
|
path
|
store
.
touch
(
path
)
end
store
.
touch
(
project_pipeline_path
(
pipeline
.
triggered_by_pipeline
))
if
pipeline
.
triggered_by_pipeline
pipeline
.
triggered_pipelines
.
each
do
|
triggered
|
store
.
touch
(
project_pipeline_path
(
triggered
))
end
Gitlab
::
Cache
::
Ci
::
ProjectPipelineStatus
.
update_for_pipeline
(
pipeline
)
end
...
...
@@ -29,10 +35,10 @@ class ExpirePipelineCacheWorker
format: :json
)
end
def
project_pipeline_path
(
p
roject
,
p
ipeline
)
def
project_pipeline_path
(
pipeline
)
Gitlab
::
Routing
.
url_helpers
.
namespace_project_pipeline_path
(
project
.
namespace
,
project
,
p
ipeline
.
p
roject
.
namespace
,
p
ipeline
.
p
roject
,
pipeline
,
format: :json
)
end
...
...
db/fixtures/development/14_pipelines.rb
View file @
163983e0
...
...
@@ -75,7 +75,15 @@ class Gitlab::Seeder::Pipelines
def
create_master_pipelines
@project
.
repository
.
commits
(
'master'
,
limit:
4
).
map
do
|
commit
|
create_pipeline!
(
@project
,
'master'
,
commit
)
create_pipeline!
(
@project
,
'master'
,
commit
,
triggerer_pipeline
).
tap
do
|
pipeline
|
triggerer_pipeline
.
tap
do
|
triggerer_pipeline
|
triggerer_pipeline
.
sourced_pipelines
.
create
(
source_job:
triggerer_pipeline
.
builds
.
all
.
sample
,
source_project:
triggerer_pipeline
.
project
,
project:
pipeline
.
project
,
pipeline:
pipeline
)
end
end
end
rescue
[]
...
...
@@ -96,8 +104,7 @@ class Gitlab::Seeder::Pipelines
[]
end
def
create_pipeline!
(
project
,
ref
,
commit
)
def
create_pipeline!
(
project
,
ref
,
commit
,
triggerer
=
nil
)
project
.
pipelines
.
create
(
sha:
commit
.
id
,
ref:
ref
,
source: :push
)
end
...
...
@@ -151,6 +158,10 @@ class Gitlab::Seeder::Pipelines
@project
.
team
.
users
.
sample
end
def
triggerer_pipeline
Ci
::
Pipeline
.
limit
(
4
).
all
.
sample
end
def
build_status
Ci
::
Build
::
AVAILABLE_STATUSES
.
sample
end
...
...
db/migrate/20170525174157_create_pipeline_source_pipeline.rb
0 → 100644
View file @
163983e0
class
CreatePipelineSourcePipeline
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
create_table
:ci_sources_pipelines
,
force: :cascade
do
|
t
|
t
.
integer
:project_id
t
.
integer
:pipeline_id
t
.
integer
:source_project_id
t
.
integer
:source_job_id
t
.
integer
:source_pipeline_id
end
end
end
db/migrate/20170525174158_add_ci_pipeline_source_pipeline_indexes.rb
0 → 100644
View file @
163983e0
class
AddCiPipelineSourcePipelineIndexes
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_index
:ci_sources_pipelines
,
:project_id
add_concurrent_index
:ci_sources_pipelines
,
:pipeline_id
add_concurrent_index
:ci_sources_pipelines
,
:source_project_id
add_concurrent_index
:ci_sources_pipelines
,
:source_job_id
add_concurrent_index
:ci_sources_pipelines
,
:source_pipeline_id
end
def
down
remove_concurrent_index
:ci_sources_pipelines
,
:project_id
remove_concurrent_index
:ci_sources_pipelines
,
:pipeline_id
remove_concurrent_index
:ci_sources_pipelines
,
:source_project_id
remove_concurrent_index
:ci_sources_pipelines
,
:source_job_id
remove_concurrent_index
:ci_sources_pipelines
,
:source_pipeline_id
end
end
db/migrate/20170525174159_add_ci_pipeline_source_pipeline_foreign_key.rb
0 → 100644
View file @
163983e0
class
AddCiPipelineSourcePipelineForeignKey
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_foreign_key
:ci_sources_pipelines
,
:projects
,
column: :project_id
add_concurrent_foreign_key
:ci_sources_pipelines
,
:ci_pipelines
,
column: :pipeline_id
add_concurrent_foreign_key
:ci_sources_pipelines
,
:projects
,
column: :source_project_id
add_concurrent_foreign_key
:ci_sources_pipelines
,
:ci_builds
,
column: :source_job_id
add_concurrent_foreign_key
:ci_sources_pipelines
,
:ci_pipelines
,
column: :source_pipeline_id
end
def
down
remove_foreign_key
:ci_sources_pipelines
,
:projects
,
column: :project_id
remove_foreign_key
:ci_sources_pipelines
,
:ci_pipelines
,
column: :pipeline_id
remove_foreign_key
:ci_sources_pipelines
,
:projects
,
column: :source_project_id
remove_foreign_key
:ci_sources_pipelines
,
:ci_builds
,
column: :source_job_id
remove_foreign_key
:ci_sources_pipelines
,
:ci_pipelines
,
column: :source_pipeline_id
end
end
db/schema.rb
View file @
163983e0
...
...
@@ -316,6 +316,20 @@ ActiveRecord::Schema.define(version: 20170602003304) do
add_index
"ci_pipeline_schedules"
,
[
"next_run_at"
,
"active"
],
name:
"index_ci_pipeline_schedules_on_next_run_at_and_active"
,
using: :btree
add_index
"ci_pipeline_schedules"
,
[
"project_id"
],
name:
"index_ci_pipeline_schedules_on_project_id"
,
using: :btree
create_table
"ci_sources_pipelines"
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
t
.
integer
"pipeline_id"
t
.
integer
"source_project_id"
t
.
integer
"source_job_id"
t
.
integer
"source_pipeline_id"
end
add_index
"ci_sources_pipelines"
,
[
"pipeline_id"
],
name:
"index_ci_pipeline_source_pipelines_on_pipeline_id"
,
using: :btree
add_index
"ci_sources_pipelines"
,
[
"project_id"
],
name:
"index_ci_pipeline_source_pipelines_on_project_id"
,
using: :btree
add_index
"ci_sources_pipelines"
,
[
"source_job_id"
],
name:
"index_ci_pipeline_source_pipelines_on_source_job_id"
,
using: :btree
add_index
"ci_sources_pipelines"
,
[
"source_pipeline_id"
],
name:
"index_ci_pipeline_source_pipelines_on_source_pipeline_id"
,
using: :btree
add_index
"ci_sources_pipelines"
,
[
"source_project_id"
],
name:
"index_ci_pipeline_source_pipelines_on_source_project_id"
,
using: :btree
create_table
"ci_pipelines"
,
force: :cascade
do
|
t
|
t
.
string
"ref"
t
.
string
"sha"
...
...
@@ -1681,6 +1695,11 @@ ActiveRecord::Schema.define(version: 20170602003304) do
add_foreign_key
"ci_builds"
,
"ci_pipelines"
,
column:
"auto_canceled_by_id"
,
name:
"fk_a2141b1522"
,
on_delete: :nullify
add_foreign_key
"ci_pipeline_schedules"
,
"projects"
,
name:
"fk_8ead60fcc4"
,
on_delete: :cascade
add_foreign_key
"ci_pipeline_schedules"
,
"users"
,
column:
"owner_id"
,
name:
"fk_9ea99f58d2"
,
on_delete: :nullify
add_foreign_key
"ci_sources_pipelines"
,
"ci_builds"
,
column:
"source_job_id"
,
name:
"fk_3f0c88d7dc"
,
on_delete: :cascade
add_foreign_key
"ci_sources_pipelines"
,
"ci_pipelines"
,
column:
"pipeline_id"
,
name:
"fk_b8c0fac459"
,
on_delete: :cascade
add_foreign_key
"ci_sources_pipelines"
,
"ci_pipelines"
,
column:
"source_pipeline_id"
,
name:
"fk_3a3e3cb83a"
,
on_delete: :cascade
add_foreign_key
"ci_sources_pipelines"
,
"projects"
,
column:
"source_project_id"
,
name:
"fk_8868d0f3e4"
,
on_delete: :cascade
add_foreign_key
"ci_sources_pipelines"
,
"projects"
,
name:
"fk_83b4346e48"
,
on_delete: :cascade
add_foreign_key
"ci_pipelines"
,
"ci_pipeline_schedules"
,
column:
"pipeline_schedule_id"
,
name:
"fk_3d34ab2e06"
,
on_delete: :nullify
add_foreign_key
"ci_pipelines"
,
"ci_pipelines"
,
column:
"auto_canceled_by_id"
,
name:
"fk_262d4c2d19"
,
on_delete: :nullify
add_foreign_key
"ci_trigger_requests"
,
"ci_triggers"
,
column:
"trigger_id"
,
name:
"fk_b8ec8b7245"
,
on_delete: :cascade
...
...
spec/lib/gitlab/import_export/all_models.yml
View file @
163983e0
...
...
@@ -108,6 +108,10 @@ pipelines:
-
artifacts
-
pipeline_schedule
-
merge_requests
-
source_pipeline
-
sourced_pipelines
-
triggered_by_pipeline
-
triggered_pipelines
statuses
:
-
project
-
pipeline
...
...
@@ -263,6 +267,8 @@ project:
-
container_repositories
-
uploads
-
mirror_data
-
source_pipelines
-
sourced_pipelines
award_emoji
:
-
awardable
-
user
...
...
spec/serializers/pipeline_serializer_spec.rb
View file @
163983e0
...
...
@@ -113,7 +113,7 @@ describe PipelineSerializer do
it
"verifies number of queries"
do
recorded
=
ActiveRecord
::
QueryRecorder
.
new
{
subject
}
expect
(
recorded
.
count
).
to
be_within
(
1
).
of
(
6
1
)
expect
(
recorded
.
count
).
to
be_within
(
1
).
of
(
6
2
)
expect
(
recorded
.
cached_count
).
to
eq
(
0
)
end
...
...
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