Skip to content

Commit 6463d38

Browse files
committed
Refactor Pre-commit config. Add more docs to README.
- Tell Pre-commit that commit-msg-sentiment.py is a commit-msg script. - Add more docs on how to test and how to configure commit-msg-sentiment.py
1 parent fd009a8 commit 6463d38

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

.pre-commit-hooks.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
additional_dependencies: [textblob, afinn]
99
always_run: true
1010
fail_fast: true
11-
minimum_pre_commit_version: '0'
11+
stages: [commit-msg]
12+
minimum_pre_commit_version: '3.2.0'

README.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,25 @@ See also: https://github.com/pre-commit/pre-commit
1515

1616
[Pre-Commit](https://github.com/pre-commit/pre-commit) is a really nice
1717
framework, and it has lots of extra goodies you should definitely check out and
18-
use. But for the commit-msg-sentiment.py script, you'll need to do a bit more
19-
work to install the script so that it will run. Because it is actually a
20-
[commit-msg hook script](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks).
18+
use. Pre-commit is capable of installing commit-msg-sentiment.py as a commit-msg Git
19+
Hook script, and has been configured to do so.
2120

2221
## How to install
2322

2423
Add this to your `.pre-commit-config.yaml`
2524

2625
```yaml
2726
- repo: https://github.com/hardyoyo/hardy_pre_commit_hooks
28-
rev: v1.2
27+
rev: v1.3
2928
hooks:
3029
- id: commit-msg-sentiment.py
3130
```
3231
33-
That will handle downloading and installing the commit-msg-sentinment.py hook
34-
script. But it's not a pre-commit hook script, and will never be called
35-
correctly if you call it as a pre-commit hook script.
32+
And then ask pre-commit to install the script(s) to your repository:
3633
37-
You will need to manually copy the [commit-msg](commit-msg) shell script to your
38-
project's `.git/hooks` folder. This will correctly call the hook script for every
39-
commit, and evaluate your commit messages for negative sentiment.
40-
41-
It's possible that Pre-commit has a post-install phase which I can use to
42-
automate the creation of the commit-msg hook script. If I figure that out, I
43-
will release a new version of this code.
34+
```
35+
pre-commit install
36+
```
4437

4538
## How to test
4639

@@ -49,6 +42,33 @@ To run the test suite, cd to the tests folder, then run
4942
python3 ./test_commit_messages.py
5043
```
5144

45+
You can also test your own example commit messages whenever you wish with:
46+
47+
```
48+
echo "this is a dumb commit message" | commit-msg-sentiment.py
49+
```
50+
51+
This is useful when you are adjusting your configuration (see below).
52+
53+
## Configuring
54+
55+
There are a few environment variables you can set to affect how
56+
commit-msg-sentiment.py functions:
57+
58+
**MIN_COMMIT_MSG_LENGTH** (defaults to 120)
59+
Minum number of characters at which we'll switch to using TextBlob instead of
60+
Affin for sentiment analysis. TextBlob doesn't handle short strings very well,
61+
Affin does better. You may need to adjust this number to suit your own commit
62+
message style.
63+
64+
**SENTIMENT_THRESHOLD** (defaults to 0.01)
65+
Both Affin and TextBlob have a similar concept of a Sentiment Threshold. You can
66+
tinker with this number if you like, but 0.01 seems to be the sweet spot for
67+
typical commit messages.
68+
69+
**REJECT_MSG**
70+
You can customize the message that is used when rejecting a commit for negative
71+
sentiment. But, do try to be kind to yourself. That's the whole point of this.
5272
## The Story
5373

5474
I started thinking about this project a few years ago. I was collaborating with

0 commit comments

Comments
 (0)