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
58f229af
Commit
58f229af
authored
May 03, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Atomic Internal ID work for pipelines
parent
35cf604b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
8 deletions
+17
-8
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+3
-1
app/models/concerns/atomic_internal_id.rb
app/models/concerns/atomic_internal_id.rb
+11
-7
lib/gitlab/ci/pipeline/chain/create.rb
lib/gitlab/ci/pipeline/chain/create.rb
+3
-0
No files found.
app/models/ci/pipeline.rb
View file @
58f229af
...
@@ -14,7 +14,9 @@ module Ci
...
@@ -14,7 +14,9 @@ module Ci
belongs_to
:auto_canceled_by
,
class_name:
'Ci::Pipeline'
belongs_to
:auto_canceled_by
,
class_name:
'Ci::Pipeline'
belongs_to
:pipeline_schedule
,
class_name:
'Ci::PipelineSchedule'
belongs_to
:pipeline_schedule
,
class_name:
'Ci::PipelineSchedule'
has_internal_id
:iid
,
scope: :project
,
init:
->
(
s
)
{
s
&
.
project
&
.
pipelines
.
count
}
has_internal_id
:iid
,
scope: :project
,
presence:
false
,
to_param:
false
,
init:
->
do
|
s
|
s
&
.
project
&
.
pipelines
&
.
maximum
(
:iid
)
||
s
&
.
project
&
.
pipelines
.
count
end
has_many
:stages
has_many
:stages
has_many
:statuses
,
class_name:
'CommitStatus'
,
foreign_key: :commit_id
,
inverse_of: :pipeline
has_many
:statuses
,
class_name:
'CommitStatus'
,
foreign_key: :commit_id
,
inverse_of: :pipeline
...
...
app/models/concerns/atomic_internal_id.rb
View file @
58f229af
...
@@ -25,9 +25,13 @@ module AtomicInternalId
...
@@ -25,9 +25,13 @@ module AtomicInternalId
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
module
ClassMethods
module
ClassMethods
def
has_internal_id
(
column
,
scope
:,
init
:)
# rubocop:disable Naming/PredicateName
def
has_internal_id
(
column
,
scope
:,
init
:,
presence:
true
,
to_param:
true
)
# rubocop:disable Naming/PredicateName
before_validation
(
on: :create
)
do
before_validation
:"ensure_
#{
column
}
!"
,
on: :create
validates
column
,
presence:
presence
,
numericality:
true
define_method
(
"ensure_
#{
column
}
!"
)
do
scope_value
=
association
(
scope
).
reader
scope_value
=
association
(
scope
).
reader
if
read_attribute
(
column
).
blank?
&&
scope_value
if
read_attribute
(
column
).
blank?
&&
scope_value
scope_attrs
=
{
scope_value
.
class
.
table_name
.
singularize
.
to_sym
=>
scope_value
}
scope_attrs
=
{
scope_value
.
class
.
table_name
.
singularize
.
to_sym
=>
scope_value
}
usage
=
self
.
class
.
table_name
.
to_sym
usage
=
self
.
class
.
table_name
.
to_sym
...
@@ -35,13 +39,13 @@ module AtomicInternalId
...
@@ -35,13 +39,13 @@ module AtomicInternalId
new_iid
=
InternalId
.
generate_next
(
self
,
scope_attrs
,
usage
,
init
)
new_iid
=
InternalId
.
generate_next
(
self
,
scope_attrs
,
usage
,
init
)
write_attribute
(
column
,
new_iid
)
write_attribute
(
column
,
new_iid
)
end
end
read_attribute
(
column
)
end
end
validates
column
,
presence:
true
,
numericality:
true
define_method
(
"to_param"
)
do
read_attribute
(
column
)
end
if
to_param
end
end
end
end
def
to_param
iid
.
to_s
end
end
end
lib/gitlab/ci/pipeline/chain/create.rb
View file @
58f229af
...
@@ -6,6 +6,9 @@ module Gitlab
...
@@ -6,6 +6,9 @@ module Gitlab
include
Chain
::
Helpers
include
Chain
::
Helpers
def
perform!
def
perform!
# TODO: allocate next IID outside of transaction
pipeline
.
ensure_iid!
::
Ci
::
Pipeline
.
transaction
do
::
Ci
::
Pipeline
.
transaction
do
pipeline
.
save!
pipeline
.
save!
...
...
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