From 2f6ccb16fa5ab92b0feb646350bf019bed96b732 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Sat, 8 Jan 2022 20:42:39 +0500 Subject: [PATCH] Added: Replaces issue link with link anchor --- create-conventional-changelog | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/create-conventional-changelog b/create-conventional-changelog index 9b96a98..7eb7274 100755 --- a/create-conventional-changelog +++ b/create-conventional-changelog @@ -77,6 +77,7 @@ ccc_run() { local changelog_text local release_timestamp local repo_owner + local repo_url_escaped ccc_log 1 "GIT_DIR_PATH=\"$GIT_DIR_PATH\"" ccc_log 1 "CHANGELOG_FILE_PATH=\"$CHANGELOG_FILE_PATH\"" @@ -133,6 +134,7 @@ ccc_run() { return 1 fi + repo_url_escaped="$(ccc_get_escaped_string_for_sed "$REPO_URL")" repo_owner="$(printf "%s" "$REPO_URL" | sed -r -z -e "s/$valid_repo_url_regex/\2/")" # If RELEASE_TAG is not set @@ -293,6 +295,10 @@ ccc_run() { # Example: "closes #666" with "closes [#666]($REPO_URL/issues/666) # https://github.com/gitbucket/gitbucket/wiki/How-to-Close-Reference-issues-and-pull-request commit_message="$(printf "%s" "$commit_message" | sed -r -e 's/(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved|issue) #([0-9]+)/\1 [#\2\]('"${REPO_URL//\//\\\/}"'\/issues\/\2)/gI')" + + # Replaces issue link with link anchor + # Example: "issue #666" with "issue [#666]($REPO_URL/issues/666) + commit_message="$(printf "%s" "$commit_message" | sed -r -e 's/(issue:?) '"$repo_url_escaped"'\/issues\/([0-9]+)/\1 [#\2\]('"${REPO_URL//\//\\\/}"'\/issues\/\2)/gI')" # Add 4 spaces to start of each line so that markdown list does not break commit_message="$(printf "%s" "$commit_message" | sed -r -e 's/^(.)/ \1/g')" @@ -404,6 +410,19 @@ ccc_create_parent_path() { } +## +# Escape `[]/$*.^` with backslashes for sed +# . +# . +# ccc_contains_newline `variable_value` +## +ccc_get_escaped_string_for_sed() { + + # Test with: printf "%s" "[]/$.*^" | sed -zE -e 's/[][/$*.^]/\\&/g' + printf "%s" "$1" | sed -zE -e 's/[][/$*.^]/\\&/g' + +} + ## # ccc_contains_newline `variable_value` ##