System notice: In light of the Debian OpenSSL security issue we've regenerated the server keys. See this thread for instructions and the new key fingerprints.

Commit 40e20d6abb6502e12ca5b3120f1662929608e679

Implemented repository status

I am thinking use it for both graphs and tarball generators

Signed-off-by: David A. Cuadrado <krawek@gmail.com>

Commit diff

app/models/repository.rb

 
219219 cloners.create(:ip => ip, :date => Time.now.utc, :country_code => country_code, :country => country_name)
220220 end
221221
222 def status_file(action, count = nil)
223 count = git.commit_count("HEAD") if !count
224 File.join(RAILS_ROOT, "tmp", "repos",
225 "#{project.slug}_#{self.name}_#{count}_#{action}.status")
226 end
227
228 def has_changed?(action, head = "master")
229 count = git.commit_count(head)
230 !File.exist?(status_file(action, count))
231 end
232
233 def keep_status!(action, head = "master")
234 count = git.commit_count(head)
235 filepath = status_file(action, count)
236 if !File.directory?(File.dirname(filepath))
237 FileUtils.mkpath(File.dirname(filepath))
238 end
239
240 Dir[status_file(action, "*")].each do |st|
241 File.unlink(st)
242 end
243
244 File.open(filepath, "w") do |file|
245 file << Time.now.to_i
246 end
247 end
248
222249 protected
223250 def set_as_mainline_if_first
224251 unless project.repositories.size >= 1
toggle raw diff

spec/models/repository_spec.rb

 
307307 users.values.map(&:login).sort.should == users(:johan, :moe).map(&:login).sort
308308 end
309309
310 it "should keep the status file" do
311 mock_path = Dir.tmpdir+"/repo_status"
312
313 my_git = Grit::Repo.new(@repository.full_repository_path)
314 @repository.should_receive(:git).and_return(my_git)
315
316 my_git.should_receive(:commit_count).with("master").and_return(10)
317 @repository.should_receive(:status_file).with("spec", 10).and_return(mock_path)
318 @repository.should_receive(:status_file).with("spec", "*").and_return("")
319 Dir.should_receive("[]").and_return([])
320 @repository.keep_status!("spec")
321 end
322
323 it "should return the status file path" do
324 @repository.status_file("spec", 10).should =~ /_10_spec\.status$/
325 end
326
327 it "should know if the repository was changed" do
328 my_git = Grit::Repo.new(@repository.full_repository_path)
329 @repository.should_receive(:git).and_return(my_git)
330 my_git.should_receive(:commit_count).with("master").and_return(10)
331
332 @repository.has_changed?("spec", "master").should == true
333 end
334
310335 describe "observers" do
311336 it "sends an email to the admin if there's a parent" do
312337 Mailer.should_receive(:deliver_new_repository_clone).with(@repository).and_return(true)
toggle raw diff