Search code examples
jsonnode.jsgithubwebhooksautodeploy

nodejs and gith doesn't work


i am trying to make a autodeploy with github, i execute this js to have a "server" to receive the hook from github, that work amazing, but i need then to execute a script to download the repository, but this code don't execute my hook.sh. I don't have experience with node earlier, so, i am lost here.

// Listen on port 9001
var gith = require('gith').create( 9001 );
// Import execFile, to run our bash script
var execFile = require('child_process').execFile;

gith({
    repo: 'username/autodeploy'
}).on( 'all', function( payload ) {
    if( payload.branch === 'master' )
    {
            // Exec a shell script
            execFile('/root/nodeapp/hook.sh', function(error, stdout, stderr) {
                    // Log success in some manner
                    console.log( 'exec complete' );
            });
    }
});

ok, i was testing this manually and seems that the problem is with gith({.... all that is inside this doesn't work, anyone have an idea?

thanks to everyone


Solution

  • well, the problem was with

    gith({
        repo: 'username/autodeploy'
    }).on( 'all', function( payload ) {....
    

    i changed that for

    gith({
        repo: 'username/autodeploy'
    }).on( 'file:all', function( payload ) {....
    

    and that solved my problem. thanks @mscdex and @alandarev for tell me to test.