{"id":17790016,"url":"https://github.com/samrocksc/haphazard-hooks","last_synced_at":"2025-10-10T19:35:51.848Z","repository":{"id":69547855,"uuid":"82975591","full_name":"samrocksc/haphazard-hooks","owner":"samrocksc","description":"GitHooks with Hapi","archived":false,"fork":false,"pushed_at":"2017-02-27T21:58:14.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-07T19:07:44.856Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/samrocksc.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-23T21:58:24.000Z","updated_at":"2017-02-24T15:59:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"de49ebbb-8c36-4044-bc23-62e32080cac5","html_url":"https://github.com/samrocksc/haphazard-hooks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/samrocksc/haphazard-hooks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samrocksc%2Fhaphazard-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samrocksc%2Fhaphazard-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samrocksc%2Fhaphazard-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samrocksc%2Fhaphazard-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samrocksc","download_url":"https://codeload.github.com/samrocksc/haphazard-hooks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samrocksc%2Fhaphazard-hooks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259466796,"owners_count":22862393,"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-10-27T10:39:42.147Z","updated_at":"2025-10-10T19:35:46.828Z","avatar_url":"https://github.com/samrocksc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# haphazard-hooks\nGitHooks with Hapi\n---\n\nThe goal of haphazard hooks is to implement a hapi server that can be opened up via nginx and set up with Basic Auth to be able to set up GitHooks quickly using [child_process](https://nodejs.org/api/child_process.html) to be able to quickly receive githooks specifically from GitHub and deploy them to your apps quickly and easily!\n\n## Creating a GitHook\n---\n\nThe primary thing to understand is that GitHooks are primarily just webhooks from anything really, you can use TravisCI, Github, whatever.  The ultimate understanding point is the following:\n\n**REPO API RECEIVES PUSH, DEPLOYS WEBHOOK-\u003eREPO ON SERVER RECEIVES WEBHOOK IN HAPI-\u003eHAPI EXECUTES A GITHOOK-\u003eGITHOOK EXECUTES A COMMAND OF EXECUTION**\n\n## Files Needed\n---\n\n(obviously opinionated)\nAs with any API we are going to be creating a Route, Handler, and if any handler reuses code, then a lib to create a repeatable method.\n\nIn this case the following file structure ensures:\n\n1. `index.js` -\u003e Primary Hapi file, starts the server, you node this.\n2. `server/routes/index.js`\n3. `server/routes/githooks.js`\n4. `server/handlers/githooks.js`\n5. `server/lib/master.js`\n6. `server/lib/develop.js`\n\n## For sake of Brevity I will explain GitHub Githooks\n---\n\nWhen GitHub actually receives a push is when it actually will deploy it's webhook.  This webhook will send a json package with a `POST` to your server.  The information in the `payload.ref` is what we're actually looking for on this.  `payload.ref` will tell us if it is relevant to our githook to run our post-update.\n\nIn Git all of the standard GitHooks are stored in `.git/hooks`.  This is a great place to find out information about it.\n\n## Whitelisting the GitHub GitHook IP\n---\n\nI'm a huge fan of whitelisting IP's and also basic auth.  Right now we currently have whitelisting set up with UFW on ubuntu.  If you would like to set it up here is an easy command to make that happen\n\n```\nsudo ufw allow from 192.30.252.0/22 to any port 3000\n```\n*_assuming you have port 3000 as your port_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamrocksc%2Fhaphazard-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamrocksc%2Fhaphazard-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamrocksc%2Fhaphazard-hooks/lists"}