/app/controllers/bitbucketgit_hook_controller.rb
Ruby | 58 lines | 19 code | 15 blank | 24 comment | 2 complexity | e23ecf6638dcd8bb5bfa6f20de69137a MD5 | raw file
- require 'json'
- # Update by Bastian Bringenberg <typo3@bastian-bringenberg.de> 2012
- class BitbucketgitHookController < ApplicationController
- skip_before_filter :verify_authenticity_token, :check_if_login_required
- def index
- payload = JSON.parse(params[:payload])
- logger.debug { "Received from Bitbucket: #{payload.inspect}" }
- # For now, we assume that the repository name is the same as the project identifier
- #identifier = payload['repository']['name']
-
- searchPath = Dir.getwd + '/' + Setting.plugin_redmine_bitbucketgit_hook[:bitbucketgit_dir].to_s + '/' + payload['repository']['owner'] + '_' + payload['repository']['name']
- #repository = Repository.find_by_url(searchPath)
- #raise TypeError, "Project '#{identifier}' has no repository" if repository.nil?
- #raise TypeError, "Repository for project '#{identifier}' is not a Git repository" unless repository.is_a?(Repository::Git)
- # Get updates from the bitbucket repository
- #aFile = File.new(repository.url + '/config', "r")
- #if aFile
- # content = aFile.sysread(2000)
- # content = /^\surl\s=\s(.*)$/.match( content )
- #logger.info{content[1]}
- #else
- # logger.info {"Unable to open file!"}
- #end
-
- #bFile = File.new(repository.url, "r")
- #if bFile
- # logger.info("File exists")
-
- #command = "cd \"#{searchPath}\" && git fetch"
- command = "cd \"#{searchPath}\" && git pull && bundle exec rake redmine:fetch_changesets RAILS_ENV=production"
- #else
- # logger.info("File does not Exist")
- #end
-
- logger.info {command}
- exec(command)
- # Fetch the new changesets into Redmine
- #repository.fetch_changesets
- render(:text => 'OK')
- end
- private
-
- def exec(command)
- logger.info { "BitbucketGitHook: Executing command: '#{command}'" }
- output = `#{command}`
- logger.info { "BitbucketGitHook: Shell returned '#{output}'" }
- end
- end