This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

gitee-webhook-pro

1.0.3 • Public • Published

gitee-webhook-pro

Gitee allows you to register Webhooks for your repositories. Each time an event occurs on your repository, whether it be pushing code, filling issues or creating pull requests, the webhook address you register can be configured to be pinged with details.

This library is a fork of github-webhook-handler and gitee-webhook-middleware . It is a small handler (or "middleware" if you must) for Node.js web servers that handles all the logic of receiving and verifying webhook requests from Gitee.

if you have any questions, please submit an issue.

Install

npm install gitee-webhook-pro

or

yarn add gitee-webhook-pro

Example

var http = require('http')
var createHandler = require('gitee-webhook-pro')
// multiple-handlers 支持传入数组对象形式,监听一个端口根据path判断来执行不同的脚本(也可以传入一个对象)
var handler = createHandler([
  {
      path: '/front',
      token: 'mytoken'
  },
   {
      path: '/backend',
      token: 'mytoken'
  }
])
function run_cmd(cmd, args, callback) {
  var spawn = require('child_process').spawn;
  var child = spawn(cmd, args);
  var resp = "";
  child.stdout.on('data', function(buffer) { resp += buffer.toString(); });        
  child.stdout.on('end', function() { callback (resp) });
}
http.createServer(function(req, res) {
  handler(req, res, function(err) {
    res.statusCode = 404
    res.end('no such location')
  })
}).listen(6666)
 
handler.on('error', function(err) {
  console.error('Error:', err.message)
})
 
handler.on('*', function(event) {
  console.log(event.event)
  console.log(event.payload)
  console.log(event.protocol)
  console.log(event.host)
  console.log(event.url)
})
 
handler.on('Push Hook', function(event) {
  console.log(event)
  if (event.url === '/front'){ run_cmd('sh', ['./front.sh'], function (text) { console.log(text) }) }
  if (event.url === '/backend'){ run_cmd('sh', ['./backend.sh'], function (text) { console.log(text) }) }
})
 

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i gitee-webhook-pro

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

7.83 kB

Total Files

4

Last publish

Collaborators

  • kungege