{"id":42403955,"url":"https://github.com/yamadayuki/ogh","last_synced_at":"2026-01-28T01:28:52.817Z","repository":{"id":37850033,"uuid":"170510432","full_name":"yamadayuki/ogh","owner":"yamadayuki","description":"Open Git Hooks","archived":false,"fork":false,"pushed_at":"2023-01-15T15:04:14.000Z","size":2411,"stargazers_count":1,"open_issues_count":25,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-04T08:18:35.776Z","etag":null,"topics":["git","githook","monorepo"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/yamadayuki.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-02-13T13:13:37.000Z","updated_at":"2021-02-19T07:33:34.000Z","dependencies_parsed_at":"2023-02-09T22:45:16.803Z","dependency_job_id":null,"html_url":"https://github.com/yamadayuki/ogh","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/yamadayuki/ogh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamadayuki%2Fogh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamadayuki%2Fogh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamadayuki%2Fogh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamadayuki%2Fogh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yamadayuki","download_url":"https://codeload.github.com/yamadayuki/ogh/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamadayuki%2Fogh/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28831400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T23:29:49.665Z","status":"ssl_error","status_checked_at":"2026-01-27T23:25:58.379Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["git","githook","monorepo"],"created_at":"2026-01-28T01:28:52.337Z","updated_at":"2026-01-28T01:28:52.805Z","avatar_url":"https://github.com/yamadayuki.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ogh (Open Git Hooks)\n\nThis package enables to treat the git hooks and your script can be invoked via hooks.\n\n## Installation\n\n```sh\n$ npm install --save @yamadayuki/ogh\n# or\n$ yarn add @yamadayuki/ogh\n```\n\n## Usage\n\nCreate your script file to perform your script for the package users. This sample means the users commit and then `pre-commit` hook is invoked, the script prints the `Hello world` string in the users console. This script holds the githooks installer and uninstaller. `entrypoint` function's first parameter is your building package name.\n\n```js\n// index.js\nconst { entrypoint, extractHookFromArgs } = require(\"@yamadayuki/ogh\");\n\nconst perform = (args, config) =\u003e {\n  if (extractHookFromArgs(args) === \"pre-commit\") {\n    console.log(\"Hello world!\");\n  }\n};\n\nentrypoint(\"foo\", { scriptPath: \"index.js\", hooks: [\"pre-commit\"] })\n  .registerPerformHook(perform)\n  .parse(process.argv);\n```\n\nAnd register your `postinstall` / `preuninstall` npm hook in your package's `package.json`.\n\n```json\n{\n  \"name\": \"foo\",\n  ...,\n  \"scripts\": [\n    ...,\n    \"postinstall\": \"node index.js install\",\n    \"preuninstall\": \"node index.js uninstall\"\n  ]\n}\n```\n\nAnd then your package users have the `.git/hooks/pre-commit` file such as below.\n\n```sh\n#!/bin/sh\n# DO NOT EDIT foo START\n\nscriptPath=\"node_modules/foo/index.js\"\nhookName=\"pre-commit\"\ngitParams=\"$*\"\n\nif ! command -v node \u003e/dev/null 2\u003e\u00261; then\n  echo \"Can't find node in PATH, trying to find a node binary on your system\"\nfi\nif [ -f $scriptPath ]; then\n  node $scriptPath $hookName \"$gitParams\"\nfi\n\n# DO NOT EDIT foo END\n```\n\nA sample package is in the [@yamadayuki/ogh-sample](https://github.com/yamadayuki/ogh/tree/master/packages/ogh-sample) directory.\n\n## API\n\n`@yamadayuki/ogh` has 3 functions.\n\n### `entrypoint(packageName, options)`\n\nThis function returns the `Ogh` class instance.\n\n`packageName` indicates the name of your building package. It is required. This is used in constructing the content of the githook.\n\n`options` has some optional parameters.\n\n- `options.scriptName` indicates the script path which is invoked via git hooks. It is relative path from the package root. Default value is `lib/index.js`.\n- `options.hooks` indicates the hooks which are installed. If you want to specify the hooks only `pre-commit` and `pre-push`, you should pass the array as `[\"pre-commit\", \"pre-push\"]`. Default value is array of all githooks. See https://git-scm.com/docs/githooks.\n\n### `extractHookFromArgs(args)`\n\nIt can retrieve the githook name from `args`. This `args` is `process.argv`.\n\n```js\nconst perform = (args, config) =\u003e {\n  if (extractHookFromArgs(args) === \"pre-commit\") {\n    console.log(\"Hello world!\");\n  }\n};\n```\n\n### `extractGitRootDirFromArgs(args)`\n\nIt can retrieve the installed project root which has the `.git` directory. This `args` is `process.argv`.\n\n```js\nconst perform = (args, config) =\u003e {\n  console.log(extractGitRootDirFromArgs(args)); // =\u003e /path/to/project/root\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyamadayuki%2Fogh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyamadayuki%2Fogh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyamadayuki%2Fogh/lists"}