Skip to content

Commit

Permalink
Update prepare-commit-msg +semver: minor (#132)
Browse files Browse the repository at this point in the history
* Update prepare-commit-msg

* Update ci.yml

* Update GitVersion.ym +semver: minor
  • Loading branch information
guibranco authored Nov 23, 2024
1 parent 5b90366 commit c790376
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
30 changes: 20 additions & 10 deletions .githooks/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ then
exit 1
fi

COMMIT_MSG_FILE=$1
CURRENT_MESSAGE=$(cat "$COMMIT_MSG_FILE")
if [ -z "$1" ]; then
echo "Error: Commit message file not provided" >&2
exit 1
fi

# From version 0.6.1, this is not needed anymore.
# GIT_DIFF=$(git diff --staged)
# GIT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
COMMIT_MSG_FILE=$1
if [ ! -f "$COMMIT_MSG_FILE" ]; then
echo "Error: Commit message file '$COMMIT_MSG_FILE' not found" >&2
exit 1
fi

# Run dotnet-aicommitmessage with error handling
# From version 0.6.1 branch and diff are now retrieved by the tool and don't need to be passed manually.
# Version 0.6.1 and higher: dotnet-aicommitmessage generate-message -m "$CURRENT_MESSAGE"
# Version 0.6.0 and lower: dotnet-aicommitmessage generate-message -m "$CURRENT_MESSAGE" -b "$GIT_BRANCH_NAME" -d "$GIT_DIFF"
CURRENT_MESSAGE=$(cat "$COMMIT_MSG_FILE")
cp "$COMMIT_MSG_FILE" "${COMMIT_MSG_FILE}.bak"

if ! AI_MESSAGE=$(dotnet-aicommitmessage generate-message -m "$CURRENT_MESSAGE"); then
echo "Error: Failed to generate AI commit message. Using original message." >&2
Expand All @@ -36,5 +38,13 @@ if [ -z "$AI_MESSAGE" ] || [ "$AI_MESSAGE" =~ ^[[:space:]]*$ ]; then
echo "Error: Generated commit message is empty." >&2
exit 1
fi
echo "$AI_MESSAGE" >"$COMMIT_MSG_FILE"

if ! echo "$AI_MESSAGE" > "$COMMIT_MSG_FILE" 2>/dev/null; then
echo "Error: Failed to write new commit message" >&2
cp "${COMMIT_MSG_FILE}.bak" "$COMMIT_MSG_FILE"
rm "${COMMIT_MSG_FILE}.bak"
exit 1
fi

rm "${COMMIT_MSG_FILE}.bak"
exit 0
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.x'
versionSpec: '6.x'

- name: Determine Version
id: gitversion
Expand Down
5 changes: 3 additions & 2 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mode: Mainline
workflow: GitHubFlow/v1
mode: ContinuousDeployment
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
assembly-informational-format: '{MajorMinorPatch}{PreReleaseTagWithDash}+{ShortSha}'
tag-prefix: '[vV]'
tag-prefix: '[vV]'

0 comments on commit c790376

Please sign in to comment.