Skip to content

Commit

Permalink
fix(insert-icon): šŸ› fix sed command to accept commit messages containā€¦
Browse files Browse the repository at this point in the history
ā€¦ing '/'

Signed-off-by: Eric Villard <[email protected]>
  • Loading branch information
eviweb committed Apr 25, 2022
1 parent c3cb3ee commit dfe45d6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/insert-icon
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ICON="${INI_commit_type_icons["${TYPE}"]}"
if ! echo "${HEADER}" | grep "${ICON}" &>/dev/null; then
NEW_HEADER="$(echo "${HEADER}" | sed -re "s/(${TYPE}[^:]*):\s+/\1: ${ICON} /")"

echo "${MESSAGE}" | sed -e "1 s/${HEADER}/${NEW_HEADER}/"
echo "${MESSAGE}" | sed -e "1 s/${HEADER//\//\\\/}/${NEW_HEADER//\//\\\/}/"
else
echo "${MESSAGE}"
fi
44 changes: 44 additions & 0 deletions tests/fixtures/COMMIT_EDITMSG_WITH_SLASHES
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
chore(scope): šŸ§¹ lorem ipsum dolor sit/amet

Lorem ipsum dolor sit/amet, consectetur adipiscing elit. Proin vitae
tortor dolor. Vestibulum volutpat dolor sem. Proin ut erat id urna
cursus tristique tincidunt sit/amet dolor.

Signed-off-by: Eric Villard <[email protected]>

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
#
# Initial commit
#
# Changes to be committed:
# new file: thirdpartylibs.md
#
# Untracked files:
# .gitignore
# bin/
# cog.toml
# install.sh
# koji-gitmoji.toml
# templates/
# tests/
# vendor/
#
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
diff --git a/thirdpartylibs.md b/thirdpartylibs.md
new file mode 100644
index 0000000..d8e8360
--- /dev/null
+++ b/thirdpartylibs.md
@@ -0,0 +1,7 @@
+# Third Party Libraries
+
+* **Bash Ini Parser**: version [0.1.1][bash-ini-parser]
+* **Cocogitto**: version [5.1.0][cocogitto]
+
+[bash-ini-parser]: https://github.com/tadgy/bash-ini-parser
+[cocogitto]: https://github.com/cocogitto/cocogitto/releases/tag/5.1.0
10 changes: 10 additions & 0 deletions tests/insert-icon-test
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ declare -A messages_amended=(
["chore(scope): šŸ§¹ lorem ipsum dolor sit amet"]="chore(scope): šŸ§¹ lorem ipsum dolor sit amet"
)

declare -A bugs=(
["chore(scope): lorem ipsum dolor sit/amet"]="chore(scope): šŸ§¹ lorem ipsum dolor sit/amet"
)

echo -e "\e[1mInsert Icon Tests\e[0m:"
echo -e "\n> Test messages without scope:"
for message in "${!messages_noscope[@]}"; do
Expand All @@ -103,3 +107,9 @@ echo -e "\n> Test amended messages:"
for message in "${!messages_amended[@]}"; do
assert_equals "${messages_amended["${message}"]}" "$("$(bin_dir)"/insert-icon "${message}")"
done

echo -e "\n> Test bug fixes"
for bug in "${!bugs[@]}"; do
assert_equals "${bugs["${bug}"]}" "$("$(bin_dir)"/insert-icon "${bug}")"
done

0 comments on commit dfe45d6

Please sign in to comment.