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
d317042f
Commit
d317042f
authored
Jun 21, 2021
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move tags matching queries to TaggableQueries concern
parent
9004b29d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
26 deletions
+24
-26
app/models/ci/build.rb
app/models/ci/build.rb
+0
-1
app/models/commit_status.rb
app/models/commit_status.rb
+1
-23
app/models/concerns/taggable_queries.rb
app/models/concerns/taggable_queries.rb
+21
-0
app/services/ci/build_queue_service.rb
app/services/ci/build_queue_service.rb
+2
-2
No files found.
app/models/ci/build.rb
View file @
d317042f
...
...
@@ -11,7 +11,6 @@ module Ci
include
Importable
include
Ci
::
HasRef
include
IgnorableColumns
include
TaggableQueries
BuildArchivedError
=
Class
.
new
(
StandardError
)
...
...
app/models/commit_status.rb
View file @
d317042f
...
...
@@ -7,6 +7,7 @@ class CommitStatus < ApplicationRecord
include
Presentable
include
EnumWithNil
include
BulkInsertableAssociations
include
TaggableQueries
self
.
table_name
=
'ci_builds'
...
...
@@ -85,29 +86,6 @@ class CommitStatus < ApplicationRecord
merge
(
or_conditions
)
end
##
# The temporary `on:` argument has been introduced to make it possible to
# reuse these scopes as a subquery for a different table (ci_pending_builds).
#
scope
:matches_tag_ids
,
->
(
tag_ids
,
on:
'ci_builds.id'
)
do
matcher
=
::
ActsAsTaggableOn
::
Tagging
.
where
(
taggable_type:
CommitStatus
.
name
)
.
where
(
context:
'tags'
)
.
where
(
"taggable_id =
#{
on
}
"
)
.
where
.
not
(
tag_id:
tag_ids
).
select
(
'1'
)
where
(
"NOT EXISTS (?)"
,
matcher
)
end
scope
:with_any_tags
,
->
(
on:
'ci_builds.id'
)
do
matcher
=
::
ActsAsTaggableOn
::
Tagging
.
where
(
taggable_type:
CommitStatus
.
name
)
.
where
(
context:
'tags'
)
.
where
(
"taggable_id =
#{
on
}
"
).
select
(
'1'
)
where
(
"EXISTS (?)"
,
matcher
)
end
# We use `Enums::Ci::CommitStatus.failure_reasons` here so that EE can more easily
# extend this `Hash` with new values.
enum_with_nil
failure_reason:
Enums
::
Ci
::
CommitStatus
.
failure_reasons
...
...
app/models/concerns/taggable_queries.rb
View file @
d317042f
...
...
@@ -12,5 +12,26 @@ module TaggableQueries
.
where
(
taggings:
{
context:
context
,
taggable_type:
polymorphic_name
})
.
select
(
'COALESCE(array_agg(tags.name ORDER BY name), ARRAY[]::text[])'
)
end
def
matches_tag_ids
(
tag_ids
,
table:
quoted_table_name
,
column:
'id'
)
matcher
=
::
ActsAsTaggableOn
::
Tagging
.
where
(
taggable_type:
CommitStatus
.
name
)
.
where
(
context:
'tags'
)
.
where
(
"taggable_id =
#{
table
}
.
#{
column
}
"
)
.
where
.
not
(
tag_id:
tag_ids
)
.
select
(
'1'
)
where
(
"NOT EXISTS (?)"
,
matcher
)
end
def
with_any_tags
(
table:
quoted_table_name
,
column:
'id'
)
matcher
=
::
ActsAsTaggableOn
::
Tagging
.
where
(
taggable_type:
CommitStatus
.
name
)
.
where
(
context:
'tags'
)
.
where
(
"taggable_id =
#{
table
}
.
#{
column
}
"
)
.
select
(
'1'
)
where
(
"EXISTS (?)"
,
matcher
)
end
end
end
app/services/ci/build_queue_service.rb
View file @
d317042f
...
...
@@ -148,11 +148,11 @@ module Ci
end
def
builds_matching_tag_ids
(
relation
,
ids
)
relation
.
merge
(
CommitStatus
.
matches_tag_ids
(
ids
,
on:
'ci_pending_builds.
build_id'
))
relation
.
merge
(
CommitStatus
.
matches_tag_ids
(
ids
,
table:
'ci_pending_builds'
,
column:
'
build_id'
))
end
def
builds_with_any_tags
(
relation
)
relation
.
merge
(
CommitStatus
.
with_any_tags
(
on:
'ci_pending_builds.
build_id'
))
relation
.
merge
(
CommitStatus
.
with_any_tags
(
table:
'ci_pending_builds'
,
column:
'
build_id'
))
end
def
builds_queued_before
(
relation
,
time
)
...
...
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