{"id":18394408,"url":"https://github.com/romac/node-flick","last_synced_at":"2026-05-10T19:04:41.039Z","repository":{"id":5482326,"uuid":"6679661","full_name":"romac/node-flick","owner":"romac","description":"GitHub post-receive hooks handler for Node.js (ABANDONED)","archived":false,"fork":false,"pushed_at":"2014-03-20T16:37:59.000Z","size":376,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T13:19:03.930Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://help.github.com/articles/post-receive-hooks","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/romac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-13T23:35:09.000Z","updated_at":"2016-11-02T15:28:13.000Z","dependencies_parsed_at":"2022-07-06T20:44:57.168Z","dependency_job_id":null,"html_url":"https://github.com/romac/node-flick","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romac%2Fnode-flick","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romac%2Fnode-flick/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romac%2Fnode-flick/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romac%2Fnode-flick/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/romac","download_url":"https://codeload.github.com/romac/node-flick/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571839,"owners_count":21126522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T02:05:38.234Z","updated_at":"2026-05-10T19:04:35.964Z","avatar_url":"https://github.com/romac.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://secure.travis-ci.org/romac/node-flick.png?branch=master)](https://travis-ci.org/romac/node-flick)\n[![Dependencies Status](https://david-dm.org/romac/node-flick.png)](https://david-dm.org/romac/node-flick)\n# node-flick\n\nnode-flick is a [GitHub post-receive hooks](https://help.github.com/articles/post-receive-hooks) handler for Node.js.\n\n## Installation\n\nInstall the latest version by running\n\n    $ npm install flick\n\n## Usage\n\nLet's say you want to run `git pull --rebase` on a repository clone every time commits are pushed to GitHub.\n\nFirst, import everything we need (this assumes that you installed node-flick via the above command).\n\n```js\nvar connect = require('connect'),\n    shell = require('shelljs'),\n    flick = require('flick'),\n    app = connect();\n```\n\nThen, define the action to run once we'll receive the notification from GitHub.\n\n```js\nfunction gitPull(root, options)\n{\n    return function(req, res, next) {\n        var cmd = 'git pull' + (options.rebase ? ' --rebase' : '');\n\n        shell.cd(root);\n        shell.exec(cmd, function(code, output) {\n            console.log(cmd + ' exited with code ' + code);\n        });\n\n        next();\n    };\n}\n```\n\nTell node-flick to run that action everytime we receive a notification for a specific repository.\n\n```js\nvar handler = flick();\n\nhandler.use('your-username/a-repository', gitPull('/path/to/working-copy', { rebase: true }));\n```\n\nLet's then configure connect.\n\n```js\n// Parse body of POST requests\napp.use(connect.bodyParser());\n\n// Hook flick with express\napp.use(flick.secret(process.env.GITHUB_SECRET));\napp.use(flick.payload());\napp.use(handler);\n```\n\nLaunch the HTTP server.\n\n```js\n// Thank GitHub for their niceness\napp.use(function(req, res) {\n    res.writeHead(200);\n    res.end('Thank you, dear friend.\\n');\n});\n\napp.listen(4001);\nconsole.log('flick is listening on port 4001');\n```\n\nNow, run the app with\n\n    $ node update.js\n\nAnd configure the endpoint in your repository settings on GitHub, under the **WebHooks** section.\n\nFrom now on, everytime you will push something to GitHub, the handler above will be triggered and the repository clone on the server will get updated.\n\n## Documentation\n\nnode-flick works very much like express. In fact, its API is a lot like express' one:\n\n### flick()\n\nCreate a middleware for express.\n\n```js\nvar express = require('express'),\n    flick = require('flick'),\n    app = express(),\n    handler = flick();\n\nhandler.use(function(req, res, next) {\n    console.log('Got a WebHook!');\n    next();\n});\n\napp.use('/webhook', handler);\napp.listen(3000);\n```\n\n### flick.github(secret)\n\nCreate a middleware for express, that makes sure that the incoming request comes from GitHub.  \nIt takes a single argument, which is the GitHub secret key that you configured in\nthe \"web\" [service hook](http://developer.github.com/v3/repos/hooks/).\n\n```js\nvar express = require('express'),\n    flick = require('flick'),\n    app = express(),\n    handler = flick();\n\nhandler.use(function(req, res, next) {\n    console.log('Got a WebHook!');\n    next();\n});\n\napp.use('/webhook', flick.secret(process.env.GITHUB_SECRET));\napp.use('/webhook', handler);\napp.listen(3000);\n```\n\n### flick.whitelist([options])\n\n**If you want to make sure the request comes from GitHub, use flick.github() instead.**\n\nCreate a middleware for express, that makes sure that the incoming request comes from a whitelisted IP.  \nIt takes an optional object argument with can hold the following properties:\n* `known` Check the request's remote IP against the known GitHub IPs. Defaults to `true`. (deprecated)\n* `ips` An array of allowed IPs, that will be merged with GitHub's known IPs if `known` is enabled. Defaults to `[]`.\n* `local` Allow requests from the local machine. It's basically a shortcut for `ips: ['127.0.0.1']`. Defaults to `false`.\n\n```js\nvar express = require('express'),\n    flick = require('flick'),\n    app = express(),\n    handler = flick();\n\nhandler.use(function(req, res, next) {\n    console.log('Got a WebHook!');\n    next();\n});\n\napp.use('/webhook', flick.whitelist({ known: true, ips: ['192.168.1.23'], local: true }));\napp.use('/webhook', handler);\napp.listen(3000);\n```\n\n### flick.payload([name])\n\nCreate a middleware for express, that checks if the payload sent by GitHub is there, parse it, and assign it to `req.flick.payload`.  \nYou don't have to use it, but it's quite handy to avoid doing that check and calling `JSON.parse` on `req.body.payload` manually.\n\nTakes an optional argument holding the name of the POST body field that holds the payload. Defaults to `payload`, which is what GitHub uses.\n\n```js\nvar express = require('express'),\n    flick = require('flick'),\n    app = express(),\n    handler = flick();\n\nhandler.use(function(req, res, next) {\n    var repository = req.flick.payload.repository;\n    console.log('Got WebHook for %s/%s', repository.owner.name, repository.name);\n    next();\n});\n\napp.use('/webhook', flick.secret(process.env.GITHUB_SECRET));\napp.use('/webhook', flick.payload());\napp.use('/webhook', handler);\napp.listen(3000);\n```\n\n### handler.use([repo], fn)\n\nUse the given handler `fn(req, res, next)` with optional `repo`, whose form is `username/repository`, defaulting to `*`.  \n\n`req` represents the current HTTP request. It's the same object that express would give us, only augmented with a `flick` property which is an object with for now only one property `payload`, holding the payload GitHub sent us.  \n\n`res` represents the current HTTP response. It's exactly the same object that express would give us.  \n\nCalling `next` will call the next flick handler, or give the control back to express if there aren't any.\n\nSay you want to log to the console whenever a WebHook is fired, for any repository this hook is configured for:\n```js\nhandler.use(function(req, res, next) {\n    var repository = req.flick.payload.repository;\n    console.log('Got WebHook for %s/%s', repository.owner.name, repository.name);\n    next();\n});\n```\n\nOr maybe you only want to do that for a specific repository:\n```js\nhandler.use('romac/node-houdini', function(req, res, next) {\n    console.log('Got WebHook for Houdini!');\n    next();\n});\n```\n\n## License\n\nnode-flick is released under the [MIT License](http://romac.mit-license.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromac%2Fnode-flick","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromac%2Fnode-flick","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromac%2Fnode-flick/lists"}