Skip to content

Commit e5b1072

Browse files
committed
chore: fix or ignore ShellCheck violations
src/main/scripts/ci/connect-todos-to-issues.sh:44:8: warning: Declare and assign separately to avoid masking return values. [SC2155] src/main/scripts/ci/connect-todos-to-issues.sh:60:21: note: Expressions don't expand in single quotes, use double quotes for that. [SC2016] src/main/scripts/ci/connect-todos-to-issues.sh:83:17: note: read without -r will mangle backslashes. [SC2162] src/main/scripts/ci/connect-todos-to-issues.sh:83:32: warning: TICKET appears unused. Verify use (or export if used externally). [SC2034] src/main/scripts/ci/connect-todos-to-issues.sh:84:19: note: Use $((..)) instead of deprecated $[..] [SC2007] src/main/scripts/ci/connect-todos-to-issues.sh:90:38: note: Double quote to prevent globbing and word splitting. [SC2086] src/main/scripts/ci/connect-todos-to-issues.sh:92:19: note: read without -r will mangle backslashes. [SC2162] src/main/scripts/ci/connect-todos-to-issues.sh:92:24: warning: ID appears unused. Verify use (or export if used externally). [SC2034] src/main/scripts/ci/connect-todos-to-issues.sh:131:18: note: echo may not expand escape sequences. Use printf. [SC2028] src/main/scripts/ci/connect-todos-to-issues.sh:135:10: note: Double quote to prevent globbing and word splitting. [SC2086] src/main/scripts/ci/connect-todos-to-issues.sh:144:36: note: read without -r will mangle backslashes. [SC2162] src/main/scripts/ci/connect-todos-to-issues.sh:150:10: note: Double quote to prevent globbing and word splitting. [SC2086] src/main/scripts/ci/connect-todos-to-issues.sh:153:19: note: read without -r will mangle backslashes. [SC2162] src/main/scripts/ci/connect-todos-to-issues.sh:153:24: warning: SKIP_PUZZLE_ID appears unused. Verify use (or export if used externally). [SC2034] src/main/scripts/ci/connect-todos-to-issues.sh:153:39: warning: ORIG_ISSUE appears unused. Verify use (or export if used externally). [SC2034] src/main/scripts/ci/connect-todos-to-issues.sh:153:50: warning: SKIP_TITLE appears unused. Verify use (or export if used externally). [SC2034] src/main/scripts/ci/connect-todos-to-issues.sh:153:61: warning: PUZZLE_FILE appears unused. Verify use (or export if used externally). [SC2034] src/main/scripts/ci/connect-todos-to-issues.sh:156:17: note: read without -r will mangle backslashes. [SC2162] src/main/scripts/ci/connect-todos-to-issues.sh:156:22: warning: PUZZLE_LINE_START appears unused. Verify use (or export if used externally). [SC2034] src/main/scripts/ci/connect-todos-to-issues.sh:156:40: warning: PUZZLE_LINE_END appears unused. Verify use (or export if used externally). [SC2034] src/main/scripts/ci/connect-todos-to-issues.sh:171:26: note: Use $((..)) instead of deprecated $[..] [SC2007] src/main/scripts/ci/connect-todos-to-issues.sh:175:10: note: Double quote to prevent globbing and word splitting. [SC2086] Part of #1610
1 parent 2263615 commit e5b1072

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/main/scripts/ci/connect-todos-to-issues.sh

+24-13
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ fatal() {
4141
export GH_NO_UPDATE_NOTIFIER=yes
4242

4343
# NOTE: requires `gh auth login --hostname github.com --git-protocol https --web` prior executing the script
44-
export GH_TOKEN="$(gh auth token)"
44+
GH_TOKEN="$(gh auth token)"
4545
[ -n "$GH_TOKEN" ] || fatal 'gh auth token returns an empty string'
46+
export GH_TOKEN
4647

4748
# DEBUG (deprecated): set to "1", "true", or "yes" to enable verbose output on standard error.
4849
# GH_DEBUG: set to a truthy value to enable verbose output on standard error. Set to "api" to additionally log details of HTTP traffic.
@@ -57,6 +58,8 @@ ENABLE_DEBUG=
5758
# What a label to put on the issue
5859
ISSUE_LABEL=techdebt
5960

61+
# We intentionally use single quotes as the real values will be substituted during `eval` call later
62+
# shellcheck disable=SC2016
6063
ISSUE_BODY_TEMPLATE='echo "The puzzle \`${PUZZLE_ID}\` from #$ORIG_ISSUE has to be resolved:
6164
6265
https://github.com/${GITHUB_REPOSITORY}/blob/${GITHUB_SHA}/${PUZZLE_FILE}#L${PUZZLE_LINE_START}-L${PUZZLE_LINE_END}
@@ -80,16 +83,18 @@ fi
8083
PUZZLES_COUNT=0
8184
NEW_ISSUES_COUNT=0
8285

83-
while IFS=$'\t' read PUZZLE_ID TICKET TITLE REST; do
84-
PUZZLES_COUNT=$[PUZZLES_COUNT + 1]
86+
# UNUSED_REST is really unused but without it, read appends the rest of a line to the last variable
87+
# shellcheck disable=SC2034
88+
while IFS=$'\t' read -r PUZZLE_ID UNUSED_TICKET TITLE UNUSED_REST; do
89+
PUZZLES_COUNT=$((PUZZLES_COUNT + 1))
8590

8691
# unescape CSV: "a ""quoted"" string" => a "quoted" string
8792
TITLE="$(echo "$TITLE" | sed -e 's|^"||;' -e 's|"$||' -e 's|""|"|g')"
8893

8994
debug "$PUZZLE_ID: has title: '$TITLE'"
90-
MAPPING="$(grep --max-count=1 '^'$PUZZLE_ID'[[:space:]]' "$MAPPING_FILE" || :)"
95+
MAPPING="$(grep --max-count=1 "^${PUZZLE_ID}[[:space:]]" "$MAPPING_FILE" || :)"
9196
if [ -n "$MAPPING" ]; then
92-
IFS=$'\t' read ID ISSUE_ID REST <<<"$MAPPING"
97+
IFS=$'\t' read -r UNUSED_PUZZLE_ID ISSUE_ID UNUSED_REST <<<"$MAPPING"
9398
info "$PUZZLE_ID => #$ISSUE_ID: is already linked"
9499
continue
95100
fi
@@ -128,11 +133,11 @@ while IFS=$'\t' read PUZZLE_ID TICKET TITLE REST; do
128133
# 2) For each puzzle id we have to make 2 search requests instead of one because there is no possibility to use logical OR
129134
# (body contains OR title equals) in a search query. As result, we might get "HTTP 403: API rate limit exceeded" error more often
130135
# if we have a lot of issues to process or we re-run the script frequently.
131-
JSON="$(echo "$SEARCH_BY_BODY\n$SEARCH_BY_TITLE" | sed -e 's|\\n| |g' -e 's|\\r||g' -e 's|`||g' | jq --slurp 'add | unique_by(.number)')"
136+
JSON="$(echo -e "$SEARCH_BY_BODY\n$SEARCH_BY_TITLE" | sed -e 's|\\n| |g' -e 's|\\r||g' -e 's|`||g' | jq --slurp 'add | unique_by(.number)')"
132137
ISSUES_COUNT="$(echo "$JSON" | jq '. | length')"
133138
debug "$PUZZLE_ID: found $ISSUES_COUNT issue(s) overall"
134139
debug "$PUZZLE_ID: result=$JSON"
135-
if [ $ISSUES_COUNT -gt 1 ]; then
140+
if [ "$ISSUES_COUNT" -gt 1 ]; then
136141
# LATER: include in the output type of match -- in:title or in:body
137142
error ''
138143
error "$PUZZLE_ID: found $ISSUES_COUNT issues that match the criterias:"
@@ -141,19 +146,25 @@ while IFS=$'\t' read PUZZLE_ID TICKET TITLE REST; do
141146
error "Ways to resolve:"
142147
error " 1) modify a body of one of the tickets to not contain puzzle id (or to have a different title)"
143148
error " 2) manually create a mapping between this puzzle and one of the issues:"
144-
echo "$CANDIDATES" | while read ISSUE_ID ISSUE_STATE REST; do
149+
# UNUSED_REST is really unused but without it, read appends the rest of a line to the last variable
150+
# shellcheck disable=SC2034
151+
echo "$CANDIDATES" | while read -r ISSUE_ID ISSUE_STATE UNUSED_REST; do
145152
error " echo '$PUZZLE_ID\t$ISSUE_ID\t$ISSUE_STATE\tmanually' >>$MAPPING_FILE"
146153
done
147154
fatal ''
148155
fi
149156

150-
if [ $ISSUES_COUNT -le 0 ]; then
157+
if [ "$ISSUES_COUNT" -le 0 ]; then
151158
info "$PUZZLE_ID: no related issues found. Need to create a new issue: $TITLE"
152159

153-
IFS=$'\t' read SKIP_PUZZLE_ID ORIG_ISSUE SKIP_TITLE PUZZLE_FILE PUZZLE_LINES < <(grep --max-count=1 "^$PUZZLE_ID" "$DIR/todos-in-code.tsv")
160+
# These variables are needed for eval-ing ISSUE_BODY_TEMPLATE
161+
# shellcheck disable=SC2034
162+
IFS=$'\t' read -r UNUSED_PUZZLE_ID ORIG_ISSUE UNUSED_TITLE PUZZLE_FILE PUZZLE_LINES < <(grep --max-count=1 "^$PUZZLE_ID" "$DIR/todos-in-code.tsv")
154163

155164
# "50-51" => {50, 51}
156-
IFS='-' read PUZZLE_LINE_START PUZZLE_LINE_END < <(echo "$PUZZLE_LINES")
165+
# These variables are needed for eval-ing ISSUE_BODY_TEMPLATE
166+
# shellcheck disable=SC2034
167+
IFS='-' read -r PUZZLE_LINE_START PUZZLE_LINE_END < <(echo "$PUZZLE_LINES")
157168

158169
ISSUE_BODY="$(eval "$ISSUE_BODY_TEMPLATE")"
159170
debug "$PUZZLE_ID: issue body:"
@@ -168,11 +179,11 @@ while IFS=$'\t' read PUZZLE_ID TICKET TITLE REST; do
168179

169180
info "$PUZZLE_ID => #$ISSUE_ID: link with $ISSUE_ID (just created)"
170181
printf '%s\t%s\topen\tautomatically\n' "$PUZZLE_ID" "$ISSUE_ID" >> "$MAPPING_FILE"
171-
NEW_ISSUES_COUNT=$[NEW_ISSUES_COUNT + 1]
182+
NEW_ISSUES_COUNT=$((NEW_ISSUES_COUNT + 1))
172183
continue
173184
fi
174185

175-
if [ $ISSUES_COUNT -eq 1 ]; then
186+
if [ "$ISSUES_COUNT" -eq 1 ]; then
176187
ISSUE_ID="$(echo "$JSON" | jq '.[0] | .number')"
177188
ISSUE_URL="$(echo "$JSON" | jq --raw-output '.[0] | .url')"
178189

0 commit comments

Comments
 (0)