Skip to content

Commit

Permalink
Allow scope declarations in structured commit messages (#512)
Browse files Browse the repository at this point in the history
* git, doc: document new optional scope and much more readable regex in commit-msg

* feat(commit-msg): print out message even if it is invalid

* feat(commit-msg): print commit message even if it is incorrect

* doc: refer to the contributin md instead of just printing the regex if the git commit message is wrong

* refactor(commit-msg): slightly reformat output

* refactor(commit-msg): remove the `log` type

* doc(contributing): document new scopes for commit messages
  • Loading branch information
EagleoutIce authored Nov 24, 2023
1 parent a76a029 commit 5306718
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 12 additions & 2 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ message_file="$1"
message=$(cat "$message_file")

# Define the regular expression pattern
regex="^((\[(no|skip) ci\] )?(((feat|tests?|lint|refactor|ci|git|special|doc|typo|log|ts|fix|wip|docker|dep)(-fix|-fail)?(, ?)?)+: |Merge (remote-tracking )?branch|Auto-merging).+|\[release:(patch|minor|major)\] .+)"
regex="^((\[(no|skip) ci\] )?" # allow to skip ci steps if required
regex="$regex(Merge (remote-tracking )?branch|Auto-merging|" # allow merge commit messages
regex="$regex(" # allow multiple types
regex="$regex(feat|tests?|lint|refactor|ci|git|special|doc|typo|ts|fix|wip|docker|dep)" # all valid types
regex="$regex(-fix|-fail)?" # optional fail suffix
regex="$regex(\([^)]+\))?" # optional scope
regex="$regex(, ?)?" # optional comma between types
regex="$regex)+: " # at least one type is required
regex="$regex)" # allow arbitrary message (no end marker)
regex="$regex|\[release:(patch|minor|major)\] .+)" # alternatively, allow release commits (only to be done on main)

if ! echo "$message" | grep -qE "$regex"; then
echo "[POLICY] Your message is not formatted correctly. Respect the regex: '$regex'!"
echo "[POLICY] Your message is not formatted correctly. Please respect the style defined in '.github/CONTRIBUTING.md'."
printf "[POLICY] Your message was (ignoring git comments):\n\n%s\n" "$(echo "$message" | grep -vE "^#")"
exit 1
fi
10 changes: 6 additions & 4 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ If you have any questions, refer to the [wiki](https://github.com/Code-Inspect/f

## Commit Messages

We structure our commit messages (enforced by our git-hooks) using the format `<type(s)>: <description>`.
Currently, the following types are at your disposal (more may have been or are still available, but please restrict yourself to the following):
We structure our commit messages (enforced by our git-hooks) using the format `<type(s)>(<scope>): <description>` (with `(<scope>)` being optional).
Currently, the following `<type(s)>` are at your disposal (more may have been or are still available, but please restrict yourself to the following):


| name | description |
Expand All @@ -49,7 +49,6 @@ Currently, the following types are at your disposal (more may have been or are s
| `lint` | Adapted or updated linter-issues. |
| `doc` | Updated the documentation of *flowR*. |
| `typo` | Dealt with a small typo/a grammatical mistake. |
| `log` | Improved or updated the logging of *flowR*. |
| `ts` | Performed something typescript-specific (e.g., reconfigured the `tsconfig.json`). |
| `wip` | *Use this only in combination with another type*. It marks the commit to be unfinished. |
| `special` | *Use this only if none of the other categories apply*. Explain the details in your commit message. |
Expand All @@ -65,9 +64,12 @@ Although you can give the same type repeatedly - if you think you should, please

With this, the artificial message

> `feat, test-fix: Support for branching in dataflow, fixed branching-test`
> `feat, test-fix: Support for branching in dataflow, fixed branching test`
represents the addition of a new feature and the fix of a corresponding test.
With scopes, it could look like this:

> `feat, test-fix(dataflow): Support branching & fixed branching test`
To skip the `ci`, you can prefix the commit message with `[skip ci]`.

Expand Down

2 comments on commit 5306718

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"artificial" Benchmark Suite

Benchmark suite Current: 5306718 Previous: c209d78 Ratio
Total per-file 3421.911465590909 ms (3961.7134779210214) 3354.2152301363635 ms (3860.1297956846133) 1.02
Retrieve AST from R code 73.4463533181818 ms (146.57002279660279) 71.48860922727273 ms (136.54310977165716) 1.03
Normalize R AST 97.6579554090909 ms (155.9669507236663) 95.79139172727274 ms (152.52195436786488) 1.02
Produce dataflow information 65.88063790909091 ms (167.78119120463936) 66.23299468181818 ms (170.60548403093352) 0.99
Total per-slice 1.8940410841771287 ms (1.3146997865817787) 1.8581676256634037 ms (1.2492897864296644) 1.02
Static slicing 1.398171715253492 ms (1.2103138520988181) 1.372047543536089 ms (1.1480006540491348) 1.02
Reconstruct code 0.47676779401478225 ms (0.2521554663522894) 0.46882655148163743 ms (0.2603715463019149) 1.02
failed to reconstruct/re-parse 0 # 0 # NaN
times hit threshold 0 # 0 # NaN
reduction (characters) 0.7329390759026896 # 0.7329390759026896 # 1
reduction (normalized tokens) 0.720988345209971 # 0.720988345209971 # 1

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"social-science" Benchmark Suite

Benchmark suite Current: 5306718 Previous: c209d78 Ratio
Total per-file 5137.55553234 ms (5762.5639757747795) 5464.289228619999 ms (6098.39318648839) 0.94
Retrieve AST from R code 75.13220774 ms (65.47864823331633) 86.76445109999999 ms (77.45681339952834) 0.87
Normalize R AST 111.07694344 ms (66.21471603850259) 113.78691086 ms (69.64981912121678) 0.98
Produce dataflow information 160.92664108000002 ms (273.79329512353445) 166.90590034000002 ms (285.57711744755056) 0.96
Total per-slice 8.398363754683944 ms (13.866278689330848) 8.863963769870134 ms (14.566635289387673) 0.95
Static slicing 7.9200093267564045 ms (13.754182332845517) 8.249822291669334 ms (14.448470605228648) 0.96
Reconstruct code 0.46991020602161254 ms (0.23954512214924625) 0.6040326772298797 ms (0.31033593750624766) 0.78
failed to reconstruct/re-parse 9 # 9 # 1
times hit threshold 967 # 967 # 1
reduction (characters) 0.898713819973478 # 0.898713819973478 # 1
reduction (normalized tokens) 0.8579790415512589 # 0.8579790415512589 # 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.