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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
1436433c
Commit
1436433c
authored
Mar 12, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add project import state machine
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
7f50c7f6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
12 deletions
+22
-12
app/models/project.rb
app/models/project.rb
+18
-10
app/workers/repository_import_worker.rb
app/workers/repository_import_worker.rb
+4
-2
No files found.
app/models/project.rb
View file @
1436433c
...
@@ -59,13 +59,10 @@ class Project < ActiveRecord::Base
...
@@ -59,13 +59,10 @@ class Project < ActiveRecord::Base
has_one
:gemnasium_service
,
dependent: :destroy
has_one
:gemnasium_service
,
dependent: :destroy
has_one
:forked_project_link
,
dependent: :destroy
,
foreign_key:
"forked_to_project_id"
has_one
:forked_project_link
,
dependent: :destroy
,
foreign_key:
"forked_to_project_id"
has_one
:forked_from_project
,
through: :forked_project_link
has_one
:forked_from_project
,
through: :forked_project_link
# Merge Requests for target project should be removed with it
# Merge Requests for target project should be removed with it
has_many
:merge_requests
,
dependent: :destroy
,
foreign_key:
"target_project_id"
has_many
:merge_requests
,
dependent: :destroy
,
foreign_key:
"target_project_id"
# Merge requests from source project should be kept when source project was removed
# Merge requests from source project should be kept when source project was removed
has_many
:fork_merge_requests
,
foreign_key:
"source_project_id"
,
class_name:
MergeRequest
has_many
:fork_merge_requests
,
foreign_key:
"source_project_id"
,
class_name:
MergeRequest
has_many
:issues
,
->
{
order
"state DESC, created_at DESC"
},
dependent: :destroy
has_many
:issues
,
->
{
order
"state DESC, created_at DESC"
},
dependent: :destroy
has_many
:services
,
dependent: :destroy
has_many
:services
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
...
@@ -74,10 +71,8 @@ class Project < ActiveRecord::Base
...
@@ -74,10 +71,8 @@ class Project < ActiveRecord::Base
has_many
:snippets
,
dependent: :destroy
,
class_name:
"ProjectSnippet"
has_many
:snippets
,
dependent: :destroy
,
class_name:
"ProjectSnippet"
has_many
:hooks
,
dependent: :destroy
,
class_name:
"ProjectHook"
has_many
:hooks
,
dependent: :destroy
,
class_name:
"ProjectHook"
has_many
:protected_branches
,
dependent: :destroy
has_many
:protected_branches
,
dependent: :destroy
has_many
:users_projects
,
dependent: :destroy
has_many
:users_projects
,
dependent: :destroy
has_many
:users
,
through: :users_projects
has_many
:users
,
through: :users_projects
has_many
:deploy_keys_projects
,
dependent: :destroy
has_many
:deploy_keys_projects
,
dependent: :destroy
has_many
:deploy_keys
,
through: :deploy_keys_projects
has_many
:deploy_keys
,
through: :deploy_keys_projects
...
@@ -97,15 +92,12 @@ class Project < ActiveRecord::Base
...
@@ -97,15 +92,12 @@ class Project < ActiveRecord::Base
validates
:issues_enabled
,
:wall_enabled
,
:merge_requests_enabled
,
validates
:issues_enabled
,
:wall_enabled
,
:merge_requests_enabled
,
:wiki_enabled
,
inclusion:
{
in:
[
true
,
false
]
}
:wiki_enabled
,
inclusion:
{
in:
[
true
,
false
]
}
validates
:issues_tracker_id
,
length:
{
maximum:
255
},
allow_blank:
true
validates
:issues_tracker_id
,
length:
{
maximum:
255
},
allow_blank:
true
validates
:namespace
,
presence:
true
validates
:namespace
,
presence:
true
validates_uniqueness_of
:name
,
scope: :namespace_id
validates_uniqueness_of
:name
,
scope: :namespace_id
validates_uniqueness_of
:path
,
scope: :namespace_id
validates_uniqueness_of
:path
,
scope: :namespace_id
validates
:import_url
,
validates
:import_url
,
format:
{
with:
URI
::
regexp
(
%w(git http https)
),
message:
"should be a valid url"
},
format:
{
with:
URI
::
regexp
(
%w(git http https)
),
message:
"should be a valid url"
},
if: :import?
if: :import?
validate
:check_limit
,
on: :create
validate
:check_limit
,
on: :create
# Scopes
# Scopes
...
@@ -118,14 +110,30 @@ class Project < ActiveRecord::Base
...
@@ -118,14 +110,30 @@ class Project < ActiveRecord::Base
scope
:sorted_by_activity
,
->
{
reorder
(
"projects.last_activity_at DESC"
)
}
scope
:sorted_by_activity
,
->
{
reorder
(
"projects.last_activity_at DESC"
)
}
scope
:personal
,
->
(
user
)
{
where
(
namespace_id:
user
.
namespace_id
)
}
scope
:personal
,
->
(
user
)
{
where
(
namespace_id:
user
.
namespace_id
)
}
scope
:joined
,
->
(
user
)
{
where
(
"namespace_id != ?"
,
user
.
namespace_id
)
}
scope
:joined
,
->
(
user
)
{
where
(
"namespace_id != ?"
,
user
.
namespace_id
)
}
scope
:public_only
,
->
{
where
(
visibility_level:
Project
::
PUBLIC
)
}
scope
:public_only
,
->
{
where
(
visibility_level:
Project
::
PUBLIC
)
}
scope
:public_and_internal_only
,
->
{
where
(
visibility_level:
Project
.
public_and_internal_levels
)
}
scope
:public_and_internal_only
,
->
{
where
(
visibility_level:
Project
.
public_and_internal_levels
)
}
scope
:non_archived
,
->
{
where
(
archived:
false
)
}
scope
:non_archived
,
->
{
where
(
archived:
false
)
}
enumerize
:issues_tracker
,
in:
(
Gitlab
.
config
.
issues_tracker
.
keys
).
append
(
:gitlab
),
default: :gitlab
enumerize
:issues_tracker
,
in:
(
Gitlab
.
config
.
issues_tracker
.
keys
).
append
(
:gitlab
),
default: :gitlab
state_machine
:import_status
,
initial: :none
do
event
:import_start
do
transition
:none
=>
:started
end
event
:import_finish
do
transition
:started
=>
:finished
end
event
:import_fail
do
transition
:started
=>
:timeout
end
state
:started
state
:finished
state
:timeout
end
class
<<
self
class
<<
self
def
public_and_internal_levels
def
public_and_internal_levels
[
Project
::
PUBLIC
,
Project
::
INTERNAL
]
[
Project
::
PUBLIC
,
Project
::
INTERNAL
]
...
...
app/workers/repository_import_worker.rb
View file @
1436433c
...
@@ -6,16 +6,18 @@ class RepositoryImportWorker
...
@@ -6,16 +6,18 @@ class RepositoryImportWorker
def
perform
(
project_id
)
def
perform
(
project_id
)
project
=
Project
.
find
(
project_id
)
project
=
Project
.
find
(
project_id
)
project
.
import_start
result
=
gitlab_shell
.
send
(
:import_repository
,
result
=
gitlab_shell
.
send
(
:import_repository
,
project
.
path_with_namespace
,
project
.
path_with_namespace
,
project
.
import_url
)
project
.
import_url
)
if
result
if
result
project
.
import
ed
=
true
project
.
import
_finish
project
.
save
project
.
save
project
.
satellite
.
create
unless
project
.
satellite
.
exists?
project
.
satellite
.
create
unless
project
.
satellite
.
exists?
else
else
project
.
import
ed
=
false
project
.
import
_fail
end
end
end
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