Skip to content

Commit 2f6ccb1

Browse files
Added: Replaces issue link with link anchor
1 parent a538b43 commit 2f6ccb1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

create-conventional-changelog

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ ccc_run() {
7777
local changelog_text
7878
local release_timestamp
7979
local repo_owner
80+
local repo_url_escaped
8081

8182
ccc_log 1 "GIT_DIR_PATH=\"$GIT_DIR_PATH\""
8283
ccc_log 1 "CHANGELOG_FILE_PATH=\"$CHANGELOG_FILE_PATH\""
@@ -133,6 +134,7 @@ ccc_run() {
133134
return 1
134135
fi
135136

137+
repo_url_escaped="$(ccc_get_escaped_string_for_sed "$REPO_URL")"
136138
repo_owner="$(printf "%s" "$REPO_URL" | sed -r -z -e "s/$valid_repo_url_regex/\2/")"
137139

138140
# If RELEASE_TAG is not set
@@ -293,6 +295,10 @@ ccc_run() {
293295
# Example: "closes #666" with "closes [#666]($REPO_URL/issues/666)
294296
# https://github.com/gitbucket/gitbucket/wiki/How-to-Close-Reference-issues-and-pull-request
295297
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')"
298+
299+
# Replaces issue link with link anchor
300+
# Example: "issue #666" with "issue [#666]($REPO_URL/issues/666)
301+
commit_message="$(printf "%s" "$commit_message" | sed -r -e 's/(issue:?) '"$repo_url_escaped"'\/issues\/([0-9]+)/\1 [#\2\]('"${REPO_URL//\//\\\/}"'\/issues\/\2)/gI')"
296302

297303
# Add 4 spaces to start of each line so that markdown list does not break
298304
commit_message="$(printf "%s" "$commit_message" | sed -r -e 's/^(.)/ \1/g')"
@@ -404,6 +410,19 @@ ccc_create_parent_path() {
404410

405411
}
406412

413+
##
414+
# Escape `[]/$*.^` with backslashes for sed
415+
# .
416+
# .
417+
# ccc_contains_newline `variable_value`
418+
##
419+
ccc_get_escaped_string_for_sed() {
420+
421+
# Test with: printf "%s" "[]/$.*^" | sed -zE -e 's/[][/$*.^]/\\&/g'
422+
printf "%s" "$1" | sed -zE -e 's/[][/$*.^]/\\&/g'
423+
424+
}
425+
407426
##
408427
# ccc_contains_newline `variable_value`
409428
##

0 commit comments

Comments
 (0)