PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/app/models/repository_observer.rb

https://bitbucket.org/sudocoders/redmine-bitbucket-git
Ruby | 34 lines | 28 code | 3 blank | 3 comment | 5 complexity | d15453b17e231197021256e65dd65518 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 = Dir.getwd + '/'
  15. p redminedir+git_dir
  16. if Dir[redminedir+git_dir] == []
  17. exec('git clone --mirror '+ url + ' "'+ redminedir + git_dir +'"')
  18. repository.url = redminedir + git_dir
  19. else
  20. p "Dir already in use..."
  21. return false
  22. end
  23. end
  24. end
  25. private
  26. def exec(command)
  27. p "BitbucketGitHook: Executing command: '#{command}'"
  28. output = `#{command}`
  29. p "BitbucketGitHook: Shell returned '#{output}'"
  30. end
  31. end