node-notifier-server
Each subscriber .js file in the notifier.d/ directory should export a function that takes a notify notifier object, and an exec callback to call the shell script of the same name should be executed.
Examples
foo.js
module.exports = function (notifier, exec) {
notifier.on('repo-owner/repo-name/push/heads/main', exec);
};foo.sh
#!/bin/bash
cd /var/lib/some-service
git fetch origin
echo "Checking out $1"
git checkout --force "$1"
npm ci
nohup /etc/init.d/some-service restart &API
notifier.on(eventPath, callback)
Parameters:
-
eventPath {string|: Slash-separated string containing 4 segments:- repo owner,
- repo name,
- webhook event type,
- webhook event ref (this may contain additional slashes)
For example,
jquery/api.jquery.com/push/heads/mainwould subscribe to the https://github.com/jquery/api.jquery.com repository, for a "push" event, with referencerefs/heads/main.You can use a wildcard within the string to listen for many possible references. This is especially useful when subscribing for tags. For example,
example/est/tags/heads/*would listen for any tags, andexample/est/push/heads/*would listen for any branches. -
callback {Function}Called after a matching webhook is received, and passed a
dataparameter. -
callback.data {Object}: For all events:type {string}: webhook event type.owner {string}: repo owner.repo {string}: repo name.
For "push" events:
commit {string}: The head SHA1 of the pushed commit reference.branch {string|undefined}: The branch name, if a branch was pushed.tag {string|undefined}: The tag nae, is a tag was pushed.
subscriber(notifier, exec)
This is the interface that exported subscriber scripts in the notifier.d/ directory should follow.
It is called once, when the server initially starts up.
Parameters:
-
notifier {Notifier} -
exec {Function}: This is a preset callback to use withnotifier.on(), for the common use case of invoking a shell script after a "push" event. It will run a shell script by the name of<basename>.shin the same directory (e.g.foo.shfor afoo.jssubscriber), and pass it one shell argument:data.commit(the SHA1 of the pushed reference).