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
de7d82d6
Commit
de7d82d6
authored
Nov 16, 2018
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ProjectRepository model
parent
7f16af18
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
0 deletions
+60
-0
app/models/project.rb
app/models/project.rb
+7
-0
app/models/project_repository.rb
app/models/project_repository.rb
+13
-0
changelogs/unreleased/tc-repo-full-path-in-db.yml
changelogs/unreleased/tc-repo-full-path-in-db.yml
+5
-0
spec/models/project_repository_spec.rb
spec/models/project_repository_spec.rb
+22
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+13
-0
No files found.
app/models/project.rb
View file @
de7d82d6
...
...
@@ -120,6 +120,8 @@ class Project < ActiveRecord::Base
after_create
:ensure_storage_path_exists
after_save
:ensure_storage_path_exists
,
if: :namespace_id_changed?
after_create
:create_project_repository
acts_as_ordered_taggable
attr_accessor
:old_path_with_namespace
...
...
@@ -130,6 +132,7 @@ class Project < ActiveRecord::Base
alias_attribute
:title
,
:name
# Relations
belongs_to
:project_repository
,
foreign_key: :repository_id
belongs_to
:pool_repository
belongs_to
:creator
,
class_name:
'User'
belongs_to
:group
,
->
{
where
(
type:
'Group'
)
},
foreign_key:
'namespace_id'
...
...
@@ -1207,6 +1210,10 @@ class Project < ActiveRecord::Base
false
end
def
create_project_repository
update
(
project_repository:
ProjectRepository
.
create!
(
shard_name:
repository_storage
,
disk_path:
disk_path
))
end
def
create_repository
(
force:
false
)
# Forked import is handled asynchronously
return
if
forked?
&&
!
force
...
...
app/models/project_repository.rb
0 → 100644
View file @
de7d82d6
# frozen_string_literal: true
class
ProjectRepository
<
ActiveRecord
::
Base
include
RepositoryOnShard
has_one
:project
,
foreign_key: :repository_id
class
<<
self
def
find_project
(
disk_path
)
find_by
(
disk_path:
disk_path
)
&
.
project
end
end
end
changelogs/unreleased/tc-repo-full-path-in-db.yml
0 → 100644
View file @
de7d82d6
---
title
:
Add model and relation to store repo full path in database
merge_request
:
23143
author
:
type
:
added
spec/models/project_repository_spec.rb
0 → 100644
View file @
de7d82d6
# frozen_string_literal: true
require
'spec_helper'
describe
ProjectRepository
do
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:shard
)
}
it
{
is_expected
.
to
have_one
(
:project
)
}
end
describe
'.find_project'
do
it
'finds project by disk path'
do
project
=
create
(
:project
)
expect
(
described_class
.
find_project
(
project
.
disk_path
)).
to
eq
(
project
)
end
it
'returns nil when it does not find the project'
do
expect
(
described_class
.
find_project
(
'@@unexisting/path/to/project'
)).
to
be_nil
end
end
end
spec/models/project_spec.rb
View file @
de7d82d6
...
...
@@ -8,6 +8,7 @@ describe Project do
it
{
is_expected
.
to
belong_to
(
:group
)
}
it
{
is_expected
.
to
belong_to
(
:namespace
)
}
it
{
is_expected
.
to
belong_to
(
:creator
).
class_name
(
'User'
)
}
it
{
is_expected
.
to
belong_to
(
:project_repository
)
}
it
{
is_expected
.
to
belong_to
(
:pool_repository
)
}
it
{
is_expected
.
to
have_many
(
:users
)
}
it
{
is_expected
.
to
have_many
(
:services
)
}
...
...
@@ -1729,6 +1730,18 @@ describe Project do
end
end
describe
'#create_project_repository'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
it
'creates a project_repository'
do
project
.
create_project_repository
expect
(
project
).
to
have_project_repository
expect
(
project
.
project_repository
.
disk_path
).
to
eq
(
project
.
disk_path
)
expect
(
project
.
project_repository
.
shard_name
).
to
eq
(
project
.
repository_storage
)
end
end
describe
'#create_repository'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:shell
)
{
Gitlab
::
Shell
.
new
}
...
...
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