koppen / redmine_github_hook

Allow your Redmine installation to be notified when changes have been pushed to a Github repository.
http://mentalized.net/journal/2009/08/03/redmine_plugin_github_hook/
MIT License
478 stars 114 forks source link

Hook does not appear to catch git errors properly #9

Closed cjfields closed 13 years ago

cjfields commented 13 years ago

I had some odd issues when using the github_hook to update our Redmine repositories. When testing the hook I had some git repos update and others not, but nothing showed up in the apache error_log or in the Redmine production.log. I finally tracked it down to a bug in the logger, where it always returns as successful when sending the git commands even when there is a failure.

Redirecting the output to production when successful gave me this, which obviously points to a permissions issue (now fixed):

Processing GithubHookController#index (for 207.97.227.235 at 2011-04-04 15:43:58) [POST]
  Parameters: {"project_id"=>"bioperl", "payload"=>"{\"forced\":false,\"created\":false,\"commits\":[{\"author\":{\"username\":\"cjfields\",\"email\":\"cjfields@bioperl.org\",\"name\":\"Chris Fields\"},\"timestamp\":\"2011-04-03T20:38:46-07:00\",\"modified\":[\"README\"],\"distinct\":true,\"message\":\"test hook\",\"url\":\"https://github.com/bioperl/bioperl-live/commit/983fb37a89be22476b0e4e3880dfb9891bf812b1\",\"added\":[],\"removed\":[],\"id\":\"983fb37a89be22476b0e4e3880dfb9891bf812b1\"},{\"author\":{\"username\":\"cjfields\",\"email\":\"cjfields@bioperl.org\",\"name\":\"Chris Fields\"},\"timestamp\":\"2011-04-03T20:47:22-07:00\",\"modified\":[\"README\"],\"distinct\":true,\"message\":\"test hook\",\"url\":\"https://github.com/bioperl/bioperl-live/commit/5e4f1516b6a4541d6dc3481427101cdffd94dfc7\",\"added\":[],\"removed\":[],\"id\":\"5e4f1516b6a4541d6dc3481427101cdffd94dfc7\"},{\"author\":{\"username\":\"cjfields\",\"email\":\"cjfields@bioperl.org\",\"name\":\"Chris Fields\"},\"timestamp\":\"2011-04-04T07:19:56-07:00\",\"modified\":[\"Bio/Tools/SeqStats.pm\",\"t/SeqTools/SeqStats.t\"],\"distinct\":true,\"message\":\"use residue count for calcs instead of length, fixes bug #3185\",\"url\":\"https://github.com/bioperl/bioperl-live/commit/536fd500d3cd308938513279d755d418ea86e0d5\",\"added\":[],\"removed\":[],\"id\":\"536fd500d3cd308938513279d755d418ea86e0d5\"}],\"repository\":{\"pushed_at\":\"2011/04/04 07:19:59 -0700\",\"watchers\":56,\"description\":\"Core BioPerl code\",\"url\":\"https://github.com/bioperl/bioperl-live\",\"open_issues\":1,\"fork\":false,\"forks\":21,\"language\":\"Perl\",\"has_wiki\":false,\"has_downloads\":true,\"private\":false,\"size\":13584,\"created_at\":\"2010/05/12 10:13:10 -0700\",\"has_issues\":false,\"owner\":{\"email\":\"bioperl-guts-l@bioperl.org\",\"name\":\"bioperl\"},\"name\":\"bioperl-live\",\"organization\":\"bioperl\",\"homepage\":\"http://bioperl.org\"},\"pusher\":{\"name\":\"none\"},\"base_ref\":null,\"before\":\"13813c2b5e8c5c825940a82f62e7c8715fc70f9b\",\"compare\":\"https://github.com/bioperl/bioperl-live/compare/13813c2...536fd50\",\"after\":\"536fd500d3cd308938513279d755d418ea86e0d5\",\"deleted\":false,\"ref\":\"refs/heads/master\"}", "action"=>"index", "controller"=>"github_hook"}
GithubHook: Command output: ["error: cannot open /home/git/bioperl/bioperl-live.git/FETCH_HEAD: Permission denied\n", "\n"]
GithubHook: Command output: ["fatal: ambiguous argument 'refs/remotes/origin/master': unknown revision or path not in the working tree.\n", "Use '--' to separate paths from revisions\n"]
Completed in 206ms (View: 1, DB: 102) | 200 OK [https://redmine.open-bio.org/github_hook]
koppen commented 13 years ago

By default, the plugin doesn't log anything but errors in production. If it somehow doesn't notice git failing, I guess it will stay silent.

So the issue here seems to be that the plugin doesn't properly detect a git failure. I wonder if I'm using the wrong command to kick off the git process.

Could you manually run the git command that the hook attempts to run, please, and tell me the exit code returned?

$ git --git-dir=/home/git/bioperl/bioperl-live.git fetch origin
$ echo $?
cjfields commented 13 years ago

I fixed permissions so couldn't use that set of commands, but using git reset --soft /refs/remotes/origin/master I get:

[ec2-user@redmine ~]$ sudo git --git-dir=/home/git/bioperl/bioperl-live.git reset --soft /refs/remotes/origin/master
fatal: ambiguous argument '/refs/remotes/origin/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
[ec2-user@redmine ~]$ echo $?
128
[ec2-user@redmine ~]$ 

koppen commented 13 years ago

Switch to Kernel.system. We explitly log output and we just need a true return value for successful commands. Closed by c6eafd1944318809ec1e17f95e6b9cb58b24f3be