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
9300ad3f
Commit
9300ad3f
authored
Nov 11, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement Project mirror helper methods.
parent
aea55a12
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
1 deletion
+60
-1
app/models/project.rb
app/models/project.rb
+60
-1
No files found.
app/models/project.rb
View file @
9300ad3f
...
...
@@ -156,6 +156,7 @@ class Project < ActiveRecord::Base
validates
:import_url
,
format:
{
with:
/\A
#{
URI
.
regexp
(
%w(ssh git http https)
)
}
\z/
,
message:
'should be a valid url'
},
if: :external_import?
validates
:import_url
,
presence:
true
,
if: :mirror?
validates
:star_count
,
numericality:
{
greater_than_or_equal_to:
0
}
validate
:check_limit
,
on: :create
validate
:avatar_type
,
...
...
@@ -180,6 +181,7 @@ class Project < ActiveRecord::Base
scope
:public_only
,
->
{
where
(
visibility_level:
Project
::
PUBLIC
)
}
scope
:public_and_internal_only
,
->
{
where
(
visibility_level:
Project
.
public_and_internal_levels
)
}
scope
:non_archived
,
->
{
where
(
archived:
false
)
}
scope
:mirror
,
->
{
where
(
mirror:
true
)
}
state_machine
:import_status
,
initial: :none
do
event
:import_start
do
...
...
@@ -204,6 +206,21 @@ class Project < ActiveRecord::Base
after_transition
any
=>
:started
,
do: :schedule_add_import_job
after_transition
any
=>
:finished
,
do: :clear_import_data
after_transition
started: :finished
do
|
project
,
transaction
|
if
project
.
mirror?
timestamp
=
DateTime
.
now
project
.
mirror_last_update_at
=
timestamp
project
.
mirror_last_successful_update_at
=
timestamp
project
.
save
end
end
after_transition
started: :failed
do
|
project
,
transaction
|
if
project
.
mirror?
project
.
update
(
mirror_last_update_at:
DateTime
.
now
)
end
end
end
class
<<
self
...
...
@@ -254,7 +271,7 @@ class Project < ActiveRecord::Base
joins
(
:namespace
).
iwhere
(
'namespaces.path'
=>
namespace_path
)
projects
.
where
(
'projects.path'
=>
project_path
).
take
||
projects
.
where
(
'projects.path'
=>
project_path
).
take
||
projects
.
iwhere
(
'projects.path'
=>
project_path
).
take
end
...
...
@@ -358,6 +375,48 @@ class Project < ActiveRecord::Base
original_url
end
def
mirror_updated?
mirror?
&&
self
.
mirror_last_update_at
end
def
updating_mirror?
mirror?
&&
import_in_progress?
&&
!
empty_repo?
end
def
mirror_last_update_status
return
unless
mirror_updated?
if
self
.
mirror_last_update_at
==
self
.
mirror_last_successful_update_at
:success
else
:failed
end
end
def
mirror_last_update_success?
mirror_last_update_status
==
:success
end
def
mirror_last_update_failed?
mirror_last_update_status
==
:failed
end
def
mirror_ever_updated_successfully?
mirror_updated?
&&
self
.
mirror_last_successful_update_at
end
def
update_mirror
return
unless
mirror?
return
if
import_in_progress?
if
import_failed?
import_retry
else
import_start
end
end
def
check_limit
unless
creator
.
can_create_project?
or
namespace
.
kind
==
'group'
errors
[
:limit_reached
]
<<
(
"Your project limit is
#{
creator
.
projects_limit
}
projects! Please contact your administrator to increase it"
)
...
...
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