Alessio Caiazza avatar Alessio Caiazza committed de60f57

github -> bitbucket

Comments (0)

Files changed (3)

app/controllers/bitbucket_hook_controller.rb

+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

app/controllers/github_hook_controller.rb

-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
 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.