{"id":23010740,"url":"https://github.com/johnfoderaro/github-webhook","last_synced_at":"2025-08-12T13:44:11.555Z","repository":{"id":57121801,"uuid":"105839246","full_name":"johnfoderaro/github-webhook","owner":"johnfoderaro","description":"⚡️Easily interact with GitHub Webhooks","archived":false,"fork":false,"pushed_at":"2019-02-04T01:19:26.000Z","size":92,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-08T18:24:49.445Z","etag":null,"topics":["cd","ci","github-webhook","payload","post-receive"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johnfoderaro.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-05T01:56:43.000Z","updated_at":"2019-02-04T01:18:11.000Z","dependencies_parsed_at":"2022-08-24T14:59:20.662Z","dependency_job_id":null,"html_url":"https://github.com/johnfoderaro/github-webhook","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/johnfoderaro/github-webhook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfoderaro%2Fgithub-webhook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfoderaro%2Fgithub-webhook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfoderaro%2Fgithub-webhook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfoderaro%2Fgithub-webhook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnfoderaro","download_url":"https://codeload.github.com/johnfoderaro/github-webhook/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfoderaro%2Fgithub-webhook/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270071615,"owners_count":24522344,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cd","ci","github-webhook","payload","post-receive"],"created_at":"2024-12-15T09:25:35.257Z","updated_at":"2025-08-12T13:44:11.469Z","avatar_url":"https://github.com/johnfoderaro.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GitHub Webhook\n\nSimple module for interacting with GitHub Webhooks. Listen for GitHub JSON payloads and then optionally execute commands asychronously based upon data from the payload. This class is essentially a wrapper around several core Node.js modules -- specifically: `http`, `crypto` and `child_process`.\n\n## Benefits\n\nThis is a slimmed down version of code that I have been using over the past several months which helps facilitate some of my project's continous integration and deployment needs. I find that the GitHub Webhook feature is very useful, especially with \"release\" events, as different builds and destinations can be triggered. That way, a project can be built, tested, and deployed automatically with little manual intervention beyond standard release notes and GitHub best practices. Place this app behind an NGINX reverse proxy, pair it up with PM2, and you'll be all set. Enjoy!\n\n## Installing\n\n`npm install @johnfoderaro/github-webhook`\n\n## Examples\n\n#### Listen for a JSON paylaod response from GitHub\n\n```javascript\nconst webhook = require('@johnfoderaro/github-webhook');\n\nconst project01 = webhook({\n  port: 3000,\n  endPoint: '/build/',\n  secret: '\u003cYOUR GITHUB WEB HOOK SECRET\u003e',\n  response: 'Payload received. Check logs for details.',\n});\n\nproject01.listen((response) =\u003e {\n  if (response.error) {\n    console.error(response.error);\n    return;\n  }\n  const data = JSON.parse(response.data);\n  console.log(data);\n});\n```\n\n#### Execute commands after recieving a JSON payload from GitHub\n\n```javascript\nconst webhook = require('@johnfoderaro/github-webhook');\n\nconst project01 = webhook({\n  port: 3000,\n  endPoint: '/build/',\n  secret: '\u003cYOUR GITHUB WEB HOOK SECRET\u003e',\n  response: 'Payload received. Check logs for details.',\n});\n\nproject01.listen((response) =\u003e {\n  if (response.error) {\n    console.log(response.error);\n    return;\n  }\n  const data = JSON.parse(response.data);\n  const repo = data.name;\n  const url = data.repository.html_url;\n  const commands = [{\n    command: 'git',\n    args: ['clone', url],\n    options: { env: process.env },\n  }, {\n    command: 'cd',\n    args: [repo],\n    options: { env: process.env },\n  }, {\n    command: 'npm',\n    args: ['run', 'build'],\n    options: { env: process.env },\n  }];\n  project01.execute(commands, (error, output) =\u003e {\n    if (error) {\n      console.error(error);\n      return;\n    }\n    console.log({ output });\n  });\n});\n```\n\n## Usage\n\n#### `webhook(object)`\n\n`webhook(object)` returns an instance of the `Webhook` class and accepts an options object as its only argument. The options object must contain the following required pieces of inforation:\n\n```\n{\n  port: \u003cnumber\u003e,\n  endPoint: \u003cstring\u003e,\n  secret: \u003cstring\u003e,\n  response: \u003cstring\u003e,\n}\n```\n\n`port` must be a number and is passed to the instantiated `http` server. This will most likely want to be reverse proxied by through something like NGINX.\n\n`endPoint` must be a string and is the specific pathname that your Node app is accessible at, such as `/build/` or `/postreceive`. This is also provided to GitHub within the repository's webhook settings. Example `https://example.com/postreceive`.\n\n`secret` must be string for an HMAC hext digest of the payload itself. This is provided to GitHub within the repository's webhook settings.\n\n`response` must be a string. This is the response body to GitHub after a successful POST request.\n\nThe `Webhook` class instance returns a `settings` and `server` object. The `server` object is the `http` instance instantiated by the `Webhook` instance.\n\n### Instance Methods\n\n#### `listen(callback)`\n\nThe `listen` method accepts a callback function as its argument, returning an object containing `error` and `data` properties from the class's instantiated `http` server. The `data` property is a JSON object containing the payload from GitHub.\n\n#### `execute(array, callback)`\n\nThe `execute` method accepts an array and a callback as its arguments. The array represents an array of commands to be executed asychronously from the `spawn` method within the class's own `child_process` instance. This array must contain objects in an format identical to that of what's defined within the Node.js documentation for the `spawn` method itself. For more information, please read about the [`spawn` method in the Child Processes documentation](https://nodejs.org/docs/latest-v8.x/api/child_process.html#child_process_child_process_spawn_command_args_options).\n\n```\n{\n  command: \u003cstring\u003e,\n  args: \u003carray\u003e,\n  options: \u003cobject\u003e,\n}\n```\n\nThe callback function returns an `error` and an `output`. `output` is an object with:\n\n```\n{\n  stdout: \u003carray\u003e,\n  stderr: \u003carray\u003e,\n}\n```\n\n`stdout` and `stderr` are both arrays containing all stdout and stderr streams, per command execution, converted to strings.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2017 John Foderaro\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnfoderaro%2Fgithub-webhook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnfoderaro%2Fgithub-webhook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnfoderaro%2Fgithub-webhook/lists"}