express-git icon indicating copy to clipboard operation
express-git copied to clipboard

post-receive hook seems to not working?

Open jctophefabre opened this issue 10 years ago • 6 comments

Hi,

Thanks a lot for these package.

It works perfectly when I am trying the example code you are providing:

var express = require("express");
var expressGit = require("express-git");
var app = express();
app.use("/git", expressGit.serve("path/torepos/", {
    auto_init: true,
    serve_static: true,
    authorize: function (service, req, next) {
        // Authorize a service
        next();
    }
});

app.on('post-receive', function (repo, changes) {
    // Do something after a push
    next();
});

app.listen(3000);

But I have two problems:

  • First, it looks like there is a missing closing parenthesis in the example code (before the semicolon on line 11).
  • Second, the post-receive hook seems to not working. The git push works successfully but the app.on('post-receive',... is never called when the push is completed. Is it right?

I saw a closed issue (#2) related to this second problem. I am using express-git 0.7.0, but the expressGit.on() is not recognized (message: expressGit.on is not a function)

Even if am a software developper for years, I am a newbie in using node.js. Maybe I misunderstood something?

Thanks a lot for your answer. Jean-Christophe

jctophefabre avatar Nov 26 '15 10:11 jctophefabre

up!

jctophefabre avatar Jan 11 '16 14:01 jctophefabre

@fabrejc Try chaining the hooks with expressGit.serve. It worked for me. Also, there is no need for calling next(); inside the handlers.

The code would look like:

var express = require("express");
var expressGit = require("express-git");
var app = express();
app.use("/git", expressGit.serve("path/torepos/", {
    auto_init: true,
    serve_static: true,
    authorize: function (service, req, next) {
        // Authorize a service
        next();
    }
}).on('pre-receive', function (repo, changes) {
    // Do something before a push
}).on('post-receive', function (repo, changes) {
    // Do something after a push
}));

app.listen(3000);

aravindgovindan avatar Jan 22 '18 11:01 aravindgovindan

@alxarch Thanks for your reply and code snippet. Unfortunately, it is too late as I choosed another approach for my development (my post was two years ago).

Thanks for your wonderful job on this package

jctophefabre avatar Jan 22 '18 15:01 jctophefabre

hi @fabrejc, what approach did you choose?

everdrone avatar May 17 '18 12:05 everdrone

Hi @everdrone , i finally decided to use the Python Flask framework to build my REST services. The git part of the services was inspired by http://stewartjpark.com/2015/01/02/implementing-a-git-http-server-in-python.html

jctophefabre avatar May 18 '18 06:05 jctophefabre

Thanks! will definitely take a look!

everdrone avatar May 18 '18 17:05 everdrone