|
| 1 | +#!/usr/bin/env zx |
| 2 | +/* |
| 3 | + * ***************************************************************************** |
| 4 | + * Copyright (C) National University of Quilmes 2018-2024 |
| 5 | + * Gobstones (TM) is a trademark of the National University of Quilmes. |
| 6 | + * |
| 7 | + * This program is free software distributed under the terms of the |
| 8 | + * GNU Affero General Public License version 3. |
| 9 | + * Additional terms added in compliance to section 7 of such license apply. |
| 10 | + * |
| 11 | + * You may read the full license at https://gobstones.github.io/gobstones-guidelines/LICENSE. |
| 12 | + * ***************************************************************************** |
| 13 | + */ |
| 14 | + |
| 15 | +/** |
| 16 | + * This hook is invoked by git-commit and git-merge, and can be |
| 17 | + * bypassed with the --no-verify option. It takes a single |
| 18 | + * parameter, the name of the file that holds the proposed commit |
| 19 | + * log message. |
| 20 | + * |
| 21 | + * Exiting with a non-zero status causes the command to abort. |
| 22 | + * |
| 23 | + * The hook is allowed to edit the message file in place, and can |
| 24 | + * be used to normalize the message into some project standard format. |
| 25 | + * It can also be used to refuse the commit after inspecting the |
| 26 | + * message file. |
| 27 | + * |
| 28 | + * The default commit-msg hook, when enabled, detects duplicate |
| 29 | + * Signed-off-by trailers, and aborts the commit if one is found. |
| 30 | + * |
| 31 | + * We use this hook to run "commitlint", that verifies that the |
| 32 | + * message sent has the correct format for the project, aborting otherwise. |
| 33 | + * |
| 34 | + * |
| 35 | + * @author Alan Rodas Bonjour <alanrodas@gmail.com> |
| 36 | + */ |
| 37 | +import process from 'process'; |
| 38 | +import { argv, echo, path } from 'zx'; |
| 39 | +import { fileURLToPath } from 'url'; |
| 40 | +import { $ } from '../.scripts/_helpers.ts'; |
| 41 | + |
| 42 | +const HOOKS_DIRECTORY = __dirname || path.dirname(fileURLToPath(import.meta.url)); |
| 43 | +const SCRIPTS_DIRECTORY = path.join(path.dirname(HOOKS_DIRECTORY), '.scripts'); |
| 44 | + |
| 45 | +const COMMIT_MSG_FILE = argv._.length > 0 ? argv._[0] : undefined; |
| 46 | + |
| 47 | +echo` |
| 48 | +************************** |
| 49 | +Linting the commit message |
| 50 | +************************** |
| 51 | +`; |
| 52 | + |
| 53 | +// Run commitlint |
| 54 | +await $`npx --no -- commitlint --edit "${COMMIT_MSG_FILE}"`; |
| 55 | + |
| 56 | +process.exit(0); |
0 commit comments