@@ -28,7 +28,6 @@ class Project < ActiveRecord::Base
28
28
include Gitlab ::VisibilityLevel
29
29
extend Enumerize
30
30
31
- default_value_for :imported , false
32
31
default_value_for :archived , false
33
32
34
33
ActsAsTaggableOn . strict_case_match = true
@@ -59,13 +58,10 @@ class Project < ActiveRecord::Base
59
58
has_one :gemnasium_service , dependent : :destroy
60
59
has_one :forked_project_link , dependent : :destroy , foreign_key : "forked_to_project_id"
61
60
has_one :forked_from_project , through : :forked_project_link
62
-
63
61
# Merge Requests for target project should be removed with it
64
62
has_many :merge_requests , dependent : :destroy , foreign_key : "target_project_id"
65
-
66
63
# Merge requests from source project should be kept when source project was removed
67
64
has_many :fork_merge_requests , foreign_key : "source_project_id" , class_name : MergeRequest
68
-
69
65
has_many :issues , -> { order "state DESC, created_at DESC" } , dependent : :destroy
70
66
has_many :services , dependent : :destroy
71
67
has_many :events , dependent : :destroy
@@ -74,10 +70,8 @@ class Project < ActiveRecord::Base
74
70
has_many :snippets , dependent : :destroy , class_name : "ProjectSnippet"
75
71
has_many :hooks , dependent : :destroy , class_name : "ProjectHook"
76
72
has_many :protected_branches , dependent : :destroy
77
-
78
73
has_many :users_projects , dependent : :destroy
79
74
has_many :users , through : :users_projects
80
-
81
75
has_many :deploy_keys_projects , dependent : :destroy
82
76
has_many :deploy_keys , through : :deploy_keys_projects
83
77
@@ -97,15 +91,12 @@ class Project < ActiveRecord::Base
97
91
validates :issues_enabled , :wall_enabled , :merge_requests_enabled ,
98
92
:wiki_enabled , inclusion : { in : [ true , false ] }
99
93
validates :issues_tracker_id , length : { maximum : 255 } , allow_blank : true
100
-
101
94
validates :namespace , presence : true
102
95
validates_uniqueness_of :name , scope : :namespace_id
103
96
validates_uniqueness_of :path , scope : :namespace_id
104
-
105
97
validates :import_url ,
106
98
format : { with : URI ::regexp ( %w( git http https ) ) , message : "should be a valid url" } ,
107
99
if : :import?
108
-
109
100
validate :check_limit , on : :create
110
101
111
102
# Scopes
@@ -118,14 +109,36 @@ class Project < ActiveRecord::Base
118
109
scope :sorted_by_activity , -> { reorder ( "projects.last_activity_at DESC" ) }
119
110
scope :personal , -> ( user ) { where ( namespace_id : user . namespace_id ) }
120
111
scope :joined , -> ( user ) { where ( "namespace_id != ?" , user . namespace_id ) }
121
-
122
112
scope :public_only , -> { where ( visibility_level : Project ::PUBLIC ) }
123
113
scope :public_and_internal_only , -> { where ( visibility_level : Project . public_and_internal_levels ) }
124
-
125
114
scope :non_archived , -> { where ( archived : false ) }
126
115
127
116
enumerize :issues_tracker , in : ( Gitlab . config . issues_tracker . keys ) . append ( :gitlab ) , default : :gitlab
128
117
118
+ state_machine :import_status , initial : :none do
119
+ event :import_start do
120
+ transition :none => :started
121
+ end
122
+
123
+ event :import_finish do
124
+ transition :started => :finished
125
+ end
126
+
127
+ event :import_fail do
128
+ transition :started => :failed
129
+ end
130
+
131
+ event :import_retry do
132
+ transition :failed => :started
133
+ end
134
+
135
+ state :started
136
+ state :finished
137
+ state :failed
138
+
139
+ after_transition any => :started , :do => :add_import_job
140
+ end
141
+
129
142
class << self
130
143
def public_and_internal_levels
131
144
[ Project ::PUBLIC , Project ::INTERNAL ]
@@ -202,12 +215,28 @@ def saved?
202
215
id && persisted?
203
216
end
204
217
218
+ def add_import_job
219
+ RepositoryImportWorker . perform_in ( 2 . seconds , id )
220
+ end
221
+
205
222
def import?
206
223
import_url . present?
207
224
end
208
225
209
226
def imported?
210
- imported
227
+ import_finished?
228
+ end
229
+
230
+ def import_in_progress?
231
+ import? && import_status == 'started'
232
+ end
233
+
234
+ def import_failed?
235
+ import_status == 'failed'
236
+ end
237
+
238
+ def import_finished?
239
+ import_status == 'finished'
211
240
end
212
241
213
242
def check_limit
0 commit comments