# HG changeset patch # User Alessio Caiazza # Date 1267466044 -3600 # Node ID de60f57771f8be15b2e31f18fb03a2ebe45e4969 # Parent 50f9e49fa80b47fee2fadf92e088117b6eadb2de github -> bitbucket diff -r 50f9e49fa80b47fee2fadf92e088117b6eadb2de -r de60f57771f8be15b2e31f18fb03a2ebe45e4969 app/controllers/bitbucket_hook_controller.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/controllers/bitbucket_hook_controller.rb Mon Mar 01 18:54:04 2010 +0100 @@ -0,0 +1,40 @@ +require 'json' + +class BitbucketHookController < 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'] + + project = Project.find_by_identifier(identifier) + raise ActiveRecord::RecordNotFound, "No project found with identifier '#{identifier}'" if project.nil? + + repository = project.repository + raise TypeError, "Project '#{identifier}' has no repository" if repository.nil? + raise TypeError, "Repository for project '#{identifier}' is not a Mercurial repository" unless repository.is_a?(Repository::Mercurial) + + # Get updates from the Github repository + #command = "cd '#{repository.url}' && cd .. && git pull --rebase" + command = "cd '#{repository.url}' && hg pull" + exec(command) + + # Fetch the new changesets into Redmine + repository.fetch_changesets + + render(:text => 'OK') + end + + private + + def exec(command) + logger.info { "BitbucketHook: Executing command: '#{command}'" } + output = `#{command}` + logger.info { "BitbucketHook: Shell returned '#{output}'" } + end + +end diff -r 50f9e49fa80b47fee2fadf92e088117b6eadb2de -r de60f57771f8be15b2e31f18fb03a2ebe45e4969 app/controllers/github_hook_controller.rb --- a/app/controllers/github_hook_controller.rb Sat Jan 02 15:50:26 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -require 'json' - -class GithubHookController < ApplicationController - - skip_before_filter :verify_authenticity_token, :check_if_login_required - - def index - payload = JSON.parse(params[:payload]) - logger.debug { "Received from Github: #{payload.inspect}" } - - # For now, we assume that the repository name is the same as the project identifier - identifier = payload['repository']['name'] - - project = Project.find_by_identifier(identifier) - raise ActiveRecord::RecordNotFound, "No project found with identifier '#{identifier}'" if project.nil? - - repository = project.repository - 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 Github repository - #command = "cd '#{repository.url}' && cd .. && git pull --rebase" - command = "cd '#{repository.url}' && git fetch origin && git reset --soft refs/remotes/origin/master" - exec(command) - - # Fetch the new changesets into Redmine - repository.fetch_changesets - - render(:text => 'OK') - end - - private - - def exec(command) - logger.info { "GithubHook: Executing command: '#{command}'" } - output = `#{command}` - logger.info { "GithubHook: Shell returned '#{output}'" } - end - -end diff -r 50f9e49fa80b47fee2fadf92e088117b6eadb2de -r de60f57771f8be15b2e31f18fb03a2ebe45e4969 init.rb --- a/init.rb Sat Jan 02 15:50:26 2010 +0100 +++ b/init.rb Mon Mar 01 18:54:04 2010 +0100 @@ -1,8 +1,8 @@ require 'redmine' -Redmine::Plugin.register :redmine_github_hook do - name 'Redmine Github Hook plugin' - author 'Jakob Skjerning' - description 'This plugin allows your Redmine installation to receive Github post-receive notifications' +Redmine::Plugin.register :redmine_bitbucket_hook do + name 'Redmine Bitbucket Hook plugin' + author 'Alessio Caiazza, Jakob Skjerning' + description 'This plugin allows your Redmine installation to receive Bitbucket post-receive notifications' version '0.1.1' end