PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/app/models/repository_observer.rb

https://bitbucket.org/yujiod/redmine-bitbucket-git
Ruby | 33 lines | 27 code | 3 blank | 3 comment | 5 complexity | 6db7209bc55180ac7249b74a46e709b4 MD5 | raw file
  1. class RepositoryObserver < ActiveRecord::Observer
  2. # CREATE DIR Manually
  3. # KNOWN Problem: Changing BitBucket Git Dir in use
  4. # KNOWN Problem: Two Repositorys with the same name from different users
  5. def before_save(repository)
  6. if repository.type == 'Git' && repository.url.match('.*bitbucket.org.*')
  7. base_dir_name = repository.url[/[^\/]+.git/]
  8. url = repository.url
  9. user = /^\S*[:\/](.*)\/\S*$/.match( url )
  10. user = user[1]
  11. git_dir = Setting.plugin_redmine_bitbucketgit_hook[:bitbucketgit_dir].to_s
  12. git_dir = git_dir + '/' + user + '_' + base_dir_name
  13. p git_dir
  14. redminedir = RAILS_ROOT + '/'
  15. p redminedir+git_dir
  16. if Dir[redminedir+git_dir] == []
  17. exec('git clone --mirror '+ url + ' "'+ redminedir + git_dir +'"')
  18. else
  19. p "Dir already in use..."
  20. end
  21. repository.url = redminedir + git_dir
  22. end
  23. end
  24. private
  25. def exec(command)
  26. p "BitbucketGitHook: Executing command: '#{command}'"
  27. output = `#{command}`
  28. p "BitbucketGitHook: Shell returned '#{output}'"
  29. end
  30. end