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
52c31165
Commit
52c31165
authored
Sep 20, 2019
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Creating events on design creation
Each time design is created we need to push notification to secondaries
parent
ebb9f2ce
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
120 additions
and
37 deletions
+120
-37
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+1
-0
ee/app/models/ee/repository.rb
ee/app/models/ee/repository.rb
+0
-4
ee/app/models/geo/repository_updated_event.rb
ee/app/models/geo/repository_updated_event.rb
+12
-1
ee/app/services/design_management/save_designs_service.rb
ee/app/services/design_management/save_designs_service.rb
+3
-0
ee/app/services/geo/repository_updated_service.rb
ee/app/services/geo/repository_updated_service.rb
+8
-1
ee/lib/ee/gitlab/gl_repository/repo_type.rb
ee/lib/ee/gitlab/gl_repository/repo_type.rb
+13
-0
ee/spec/lib/gitlab/gl_repository/repo_type_spec.rb
ee/spec/lib/gitlab/gl_repository/repo_type_spec.rb
+20
-0
ee/spec/models/geo/repository_updated_event_spec.rb
ee/spec/models/geo/repository_updated_event_spec.rb
+1
-1
ee/spec/models/project_spec.rb
ee/spec/models/project_spec.rb
+7
-0
ee/spec/services/design_management/save_designs_service_spec.rb
...c/services/design_management/save_designs_service_spec.rb
+8
-0
ee/spec/services/geo/repository_updated_service_spec.rb
ee/spec/services/geo/repository_updated_service_spec.rb
+14
-0
lib/gitlab/gl_repository/repo_type.rb
lib/gitlab/gl_repository/repo_type.rb
+2
-0
spec/lib/gitlab/gl_repository/repo_type_spec.rb
spec/lib/gitlab/gl_repository/repo_type_spec.rb
+0
-30
spec/support/shared_examples/repo_type_shared_examples.rb
spec/support/shared_examples/repo_type_shared_examples.rb
+31
-0
No files found.
ee/app/models/ee/project.rb
View file @
52c31165
...
...
@@ -537,6 +537,7 @@ module EE
super
repository
.
log_geo_updated_event
wiki
.
repository
.
log_geo_updated_event
design_repository
.
log_geo_updated_event
end
override
:import?
...
...
ee/app/models/ee/repository.rb
View file @
52c31165
...
...
@@ -95,10 +95,6 @@ module EE
::
Geo
::
RepositoryUpdatedService
.
new
(
self
).
execute
end
def
geo_updated_event_source
repo_type
.
wiki?
?
Geo
::
RepositoryUpdatedEvent
::
WIKI
:
Geo
::
RepositoryUpdatedEvent
::
REPOSITORY
end
def
code_owners_blob
(
ref:
'HEAD'
)
possible_code_owner_blobs
=
::
Gitlab
::
CodeOwners
::
FILE_PATHS
.
map
{
|
path
|
[
ref
,
path
]
}
blobs_at
(
possible_code_owner_blobs
).
compact
.
first
...
...
ee/app/models/geo/repository_updated_event.rb
View file @
52c31165
...
...
@@ -7,11 +7,22 @@ module Geo
REPOSITORY
=
0
WIKI
=
1
DESIGN
=
2
REPOSITORY_TYPE_MAP
=
{
::
Gitlab
::
GlRepository
::
PROJECT
=>
REPOSITORY
,
::
Gitlab
::
GlRepository
::
WIKI
=>
WIKI
,
::
Gitlab
::
GlRepository
::
DESIGN
=>
DESIGN
}.
freeze
belongs_to
:project
enum
source:
{
repository:
REPOSITORY
,
wiki:
WIKI
}
enum
source:
{
repository:
REPOSITORY
,
wiki:
WIKI
,
design:
DESIGN
}
validates
:project
,
presence:
true
def
self
.
source_for
(
repository
)
REPOSITORY_TYPE_MAP
[
repository
.
repo_type
]
end
end
end
ee/app/services/design_management/save_designs_service.rb
View file @
52c31165
...
...
@@ -22,6 +22,9 @@ module DesignManagement
uploaded_designs
=
upload_designs!
skipped_designs
=
designs
-
uploaded_designs
# Create a Geo event so changes will be replicated to secondary node(s)
repository
.
log_geo_updated_event
success
({
designs:
uploaded_designs
,
skipped_designs:
skipped_designs
})
rescue
::
ActiveRecord
::
RecordInvalid
=>
e
error
(
e
.
message
)
...
...
ee/app/services/geo/repository_updated_service.rb
View file @
52c31165
...
...
@@ -11,12 +11,16 @@ module Geo
@params
=
params
@refs
=
params
.
fetch
(
:refs
,
[])
@changes
=
params
.
fetch
(
:changes
,
[])
@source
=
repository
.
geo_updated_event_source
@source
=
Geo
::
RepositoryUpdatedEvent
.
source_for
(
repository
)
end
def
execute
return
false
unless
Gitlab
::
Geo
.
primary?
if
source
==
Geo
::
RepositoryUpdatedEvent
::
DESIGN
&&
Feature
.
disabled?
(
:enable_geo_design_sync
)
return
false
end
reset_repository_checksum!
create_repository_updated_event!
...
...
@@ -36,6 +40,9 @@ module Geo
end
def
reset_repository_checksum!
# We don't yet support verification for Design repositories
return
if
source
==
Geo
::
RepositoryUpdatedEvent
::
DESIGN
return
if
repository_state
.
nil?
repository_state
.
update!
(
...
...
ee/lib/ee/gitlab/gl_repository/repo_type.rb
0 → 100644
View file @
52c31165
# frozen_string_literal: true
module
EE
module
Gitlab
module
GlRepository
module
RepoType
def
design?
self
==
DESIGN
end
end
end
end
end
ee/spec/lib/gitlab/gl_repository/repo_type_spec.rb
0 → 100644
View file @
52c31165
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
GlRepository
::
RepoType
do
set
(
:project
)
{
create
(
:project
)
}
describe
Gitlab
::
GlRepository
::
DESIGN
do
it_behaves_like
'a repo type'
do
let
(
:expected_identifier
)
{
"design-
#{
project
.
id
}
"
}
let
(
:expected_id
)
{
project
.
id
.
to_s
}
let
(
:expected_suffix
)
{
".design"
}
let
(
:expected_repository
)
{
project
.
design_repository
}
end
it
"knows its type"
do
expect
(
described_class
).
to
be_design
expect
(
described_class
).
not_to
be_project
end
end
end
ee/spec/models/geo/repository_updated_event_spec.rb
View file @
52c31165
...
...
@@ -12,6 +12,6 @@ RSpec.describe Geo::RepositoryUpdatedEvent, type: :model do
end
describe
'#source'
do
it
{
is_expected
.
to
define_enum_for
(
:source
).
with
([
:repository
,
:wiki
])
}
it
{
is_expected
.
to
define_enum_for
(
:source
).
with
([
:repository
,
:wiki
,
:design
])
}
end
end
ee/spec/models/project_spec.rb
View file @
52c31165
...
...
@@ -1318,6 +1318,7 @@ describe Project do
let
(
:project
)
{
create
(
:project
)
}
let
(
:repository_updated_service
)
{
instance_double
(
'::Geo::RepositoryUpdatedService'
)
}
let
(
:wiki_updated_service
)
{
instance_double
(
'::Geo::RepositoryUpdatedService'
)
}
let
(
:design_updated_service
)
{
instance_double
(
'::Geo::RepositoryUpdatedService'
)
}
before
do
create
(
:import_state
,
project:
project
)
...
...
@@ -1331,6 +1332,11 @@ describe Project do
.
to
receive
(
:new
)
.
with
(
project
.
wiki
.
repository
)
.
and_return
(
wiki_updated_service
)
allow
(
::
Geo
::
RepositoryUpdatedService
)
.
to
receive
(
:new
)
.
with
(
project
.
design_repository
)
.
and_return
(
design_updated_service
)
end
it
'calls Geo::RepositoryUpdatedService when running on a Geo primary node'
do
...
...
@@ -1338,6 +1344,7 @@ describe Project do
expect
(
repository_updated_service
).
to
receive
(
:execute
).
once
expect
(
wiki_updated_service
).
to
receive
(
:execute
).
once
expect
(
design_updated_service
).
to
receive
(
:execute
).
once
project
.
after_import
end
...
...
ee/spec/services/design_management/save_designs_service_spec.rb
View file @
52c31165
...
...
@@ -172,6 +172,14 @@ describe DesignManagement::SaveDesignsService do
expect
(
updated_designs
.
first
.
versions
.
size
).
to
eq
(
1
)
end
end
it
'calls repository#log_geo_updated_event'
do
expect
(
design_repository
).
to
receive
(
:log_geo_updated_event
)
allow_any_instance_of
(
described_class
).
to
receive
(
:repository
).
and_return
(
design_repository
)
run_service
end
end
context
'when a design has not changed since its previous version'
do
...
...
ee/spec/services/geo/repository_updated_service_spec.rb
View file @
52c31165
...
...
@@ -85,5 +85,19 @@ describe Geo::RepositoryUpdatedService do
let
(
:method_prefix
)
{
'wiki'
}
end
end
context
'when design repository is being updated'
do
let
(
:repository
)
{
project
.
design_repository
}
it
'creates a design repository updated event'
do
expect
{
subject
.
execute
}.
to
change
(
Geo
::
RepositoryUpdatedEvent
,
:count
).
by
(
1
)
end
it
'does not create a design repository updated event when feature is disabled'
do
stub_feature_flags
(
enable_geo_design_sync:
false
)
expect
{
subject
.
execute
}.
not_to
change
(
Geo
::
RepositoryUpdatedEvent
,
:count
)
end
end
end
end
lib/gitlab/gl_repository/repo_type.rb
View file @
52c31165
...
...
@@ -40,3 +40,5 @@ module Gitlab
end
end
end
Gitlab
::
GlRepository
::
RepoType
.
prepend_if_ee
(
'EE::Gitlab::GlRepository::RepoType'
)
spec/lib/gitlab/gl_repository/repo_type_spec.rb
View file @
52c31165
...
...
@@ -4,36 +4,6 @@ require 'spec_helper'
describe
Gitlab
::
GlRepository
::
RepoType
do
set
(
:project
)
{
create
(
:project
)
}
shared_examples
'a repo type'
do
describe
"#identifier_for_subject"
do
subject
{
described_class
.
identifier_for_subject
(
project
)
}
it
{
is_expected
.
to
eq
(
expected_identifier
)
}
end
describe
"#fetch_id"
do
it
"finds an id match in the identifier"
do
expect
(
described_class
.
fetch_id
(
expected_identifier
)).
to
eq
(
expected_id
)
end
it
'does not break on other identifiers'
do
expect
(
described_class
.
fetch_id
(
"wiki-noid"
)).
to
eq
(
nil
)
end
end
describe
"#path_suffix"
do
subject
{
described_class
.
path_suffix
}
it
{
is_expected
.
to
eq
(
expected_suffix
)
}
end
describe
"#repository_for"
do
it
"finds the repository for the repo type"
do
expect
(
described_class
.
repository_for
(
project
)).
to
eq
(
expected_repository
)
end
end
end
describe
Gitlab
::
GlRepository
::
PROJECT
do
it_behaves_like
'a repo type'
do
let
(
:expected_identifier
)
{
"project-
#{
project
.
id
}
"
}
...
...
spec/support/shared_examples/repo_type_shared_examples.rb
0 → 100644
View file @
52c31165
# frozen_string_literal: true
shared_examples
'a repo type'
do
describe
"#identifier_for_subject"
do
subject
{
described_class
.
identifier_for_subject
(
project
)
}
it
{
is_expected
.
to
eq
(
expected_identifier
)
}
end
describe
"#fetch_id"
do
it
"finds an id match in the identifier"
do
expect
(
described_class
.
fetch_id
(
expected_identifier
)).
to
eq
(
expected_id
)
end
it
'does not break on other identifiers'
do
expect
(
described_class
.
fetch_id
(
"wiki-noid"
)).
to
eq
(
nil
)
end
end
describe
"#path_suffix"
do
subject
{
described_class
.
path_suffix
}
it
{
is_expected
.
to
eq
(
expected_suffix
)
}
end
describe
"#repository_for"
do
it
"finds the repository for the repo type"
do
expect
(
described_class
.
repository_for
(
project
)).
to
eq
(
expected_repository
)
end
end
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