PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/app/controllers/bitbucketgit_hook_controller.rb

https://bitbucket.org/susansalkeld/redmine-bitbucket-git
Ruby | 58 lines | 19 code | 15 blank | 24 comment | 2 complexity | e23ecf6638dcd8bb5bfa6f20de69137a MD5 | raw file
  1. require 'json'
  2. # Update by Bastian Bringenberg <typo3@bastian-bringenberg.de> 2012
  3. class BitbucketgitHookController < ApplicationController
  4. skip_before_filter :verify_authenticity_token, :check_if_login_required
  5. def index
  6. payload = JSON.parse(params[:payload])
  7. logger.debug { "Received from Bitbucket: #{payload.inspect}" }
  8. # For now, we assume that the repository name is the same as the project identifier
  9. #identifier = payload['repository']['name']
  10. searchPath = Dir.getwd + '/' + Setting.plugin_redmine_bitbucketgit_hook[:bitbucketgit_dir].to_s + '/' + payload['repository']['owner'] + '_' + payload['repository']['name']
  11. #repository = Repository.find_by_url(searchPath)
  12. #raise TypeError, "Project '#{identifier}' has no repository" if repository.nil?
  13. #raise TypeError, "Repository for project '#{identifier}' is not a Git repository" unless repository.is_a?(Repository::Git)
  14. # Get updates from the bitbucket repository
  15. #aFile = File.new(repository.url + '/config', "r")
  16. #if aFile
  17. # content = aFile.sysread(2000)
  18. # content = /^\surl\s=\s(.*)$/.match( content )
  19. #logger.info{content[1]}
  20. #else
  21. # logger.info {"Unable to open file!"}
  22. #end
  23. #bFile = File.new(repository.url, "r")
  24. #if bFile
  25. # logger.info("File exists")
  26. #command = "cd \"#{searchPath}\" && git fetch"
  27. command = "cd \"#{searchPath}\" && git pull && bundle exec rake redmine:fetch_changesets RAILS_ENV=production"
  28. #else
  29. # logger.info("File does not Exist")
  30. #end
  31. logger.info {command}
  32. exec(command)
  33. # Fetch the new changesets into Redmine
  34. #repository.fetch_changesets
  35. render(:text => 'OK')
  36. end
  37. private
  38. def exec(command)
  39. logger.info { "BitbucketGitHook: Executing command: '#{command}'" }
  40. output = `#{command}`
  41. logger.info { "BitbucketGitHook: Shell returned '#{output}'" }
  42. end
  43. end