Skip to content

Commit

Permalink
Refactor commit message validation and output logic
Browse files Browse the repository at this point in the history
  • Loading branch information
SamBroomy committed Dec 7, 2024
1 parent caa647f commit b84cf56
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -179,43 +179,37 @@ commit-message:

# Check if the first character is a backtick
FIRST_CHAR=$(echo "$COMMIT_MSG_TRIMMED" | cut -c1)

if [ "$FIRST_CHAR" = '`' ]; then
echo -e "${R}Error: ${Y}Commit message generated starts with a backtick.${END}" >&2
echo -e "${Y}Generated Commit Message: ${B}$COMMIT_MSG_TRIMMED${END}" >&2
exit 1
fi

# Optionally, check for JSON or code block patterns
# Check for JSON or code block patterns
if echo "$COMMIT_MSG_TRIMMED" | grep -qE '^\{|\`\`\`|^```|^\[|\('; then
echo -e "${R}Error: ${Y}Commit message contains invalid formatting, e.g., JSON or code blocks.${END}" >&2
echo -e "${B}Generated Commit Message: ${B}$COMMIT_MSG_TRIMMED${END}" >&2
exit 1
fi

# Optionally, ensure the commit message is not empty
# Ensure the commit message is not empty
if [ -z "$COMMIT_MSG_TRIMMED" ]; then
echo -e "${R}Error: ${Y}Commit message is empty.${END}" >&2
exit 1
fi

# Output the validated commit message without color codes
# Output the commit message
echo "$COMMIT_MSG_TRIMMED"

[group('git')]
commit-all m="": stage-all
just commit "{{ m }}"

# Commit the changes
[group('git')]
commit m="":
#! /bin/bash

#!/bin/bash
B='\033[0;34m' # Blue
Y='\033[0;33m' # Yellow
END='\033[0m' # Reset color
#!/bin/bash
if [ -z "{{ m }}" ]; then
m=$(just commit-message)

else
m="{{ m }}"
fi
Expand Down

0 comments on commit b84cf56

Please sign in to comment.