di-sukharev / di-sukharev/opencommit
Feature: Work with husky
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 7.5k
- Forks
- 445
- Avg merge
- 18m
- Merged PRs (30d)
- 2
Description
Problem:
Opencommit only works with git hooks.
Solution:
Refactor the code to add some dynamic logic to the tool
Explanation:
-
Identify hooks' path in the repo you are working in. This can be accomplished with the following command:
git config core.hooksPathThis needed to be translated into a util function for git so I wrote the following function:
export const getCoreHooksPath = async(): Promise<string> => { const { stdout } = await execa('git', [ 'config', 'core.hooksPath']); return stdout; }Note: the function throws an error when there is no set path that needs to be caught when used.
-
Determine the path by invoking
getCoreHooksPathcatch the error and give theDEFAULT_SYMLINK_URLifcore.hooksPathis not set.const getHooksPath = async (): Promise<string> => { try { const hooksPath = await getCoreHooksPath(); return `${hooksPath}/${HOOK_NAME}`; } catch (error) { return DEFAULT_SYMLINK_URL; } }; -
Refactor our two helper functions to utilize the
getHooksPathfunction.export const isHookCalled = async (): Promise<boolean> => { const hooksPath = await getHooksPath(); return process.argv[1].endsWith(hooksPath); }; const isHookExists = async (): Promise<boolean> => { const hooksPath = await getHooksPath(); return existsSync(hooksPath); }; -
Replace the variable calls
isHookCalledandisHookExistswith the function callawait isHookCalled()andawait isHookExists()respectively.
Scenarios Tested
When core.hooksPath is not set
- Can you run opencommit from the command line - Yes
- Can you set opencommit as a hook - Yes
- Can you run open commit as a hook - Yes
- Can you unset opencommit as a hook - Yes
When core.hooksPath is set to .husky
- Can you run opencommit from the command line - Yes
- Can you set opencommit as a hook - Yes
- Can you run open commit as a hook - Yes
- Can you unset opencommit as a hook - Yes
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the hook-related helpers named in the issue: isHookCalled, isHookExists, and the hook setup logic, then inspect how git hook paths are currently handled. Verify behavior with and without core.hooksPath, including a .husky path; done means the listed command-line and hook scenarios work in both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, javascript
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100