Skip to content

Commit a712820

Browse files
committed
ci: create issues on GitHub for puzzles
Part of #1610
1 parent c02dc39 commit a712820

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

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

+32
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ export GH_TOKEN="$(gh auth token)"
5454
# a non-empty string enabled debug output
5555
ENABLE_DEBUG=
5656

57+
# What a label to put on the issue
58+
ISSUE_LABEL=techdebt
59+
60+
ISSUE_BODY_TEMPLATE='echo "The puzzle $PUZZLE_ID from #$ORIG_ISSUE has to be resolved:
61+
62+
https://github.com/${GITHUB_REPOSITORY}/blob/${GITHUB_SHA}/${PUZZLE_FILE}#L${PUZZLE_LINE_START}-L${PUZZLE_LINE_END}
63+
64+
Tech debt for: $GITHUB_SHA (#$ORIG_ISSUE)"'
65+
5766
DIR="$(dirname "$1")"
5867
MAPPING_FILE="$DIR/todos-on-github.tsv"
5968

@@ -64,6 +73,10 @@ else
6473
info "$MAPPING_FILE exists"
6574
fi
6675

76+
[ -f "$DIR/todos-in-code.tsv" ] || fatal "$DIR/todos-in-code.tsv doesn't exists!"
77+
[ -n "${GITHUB_SHA:-}" ] || fatal 'GITHUB_SHA env variable is not set!'
78+
[ -n "${GITHUB_REPOSITORY:-}" ] || fatal 'GITHUB_REPOSITORY env variable is not set!'
79+
6780
PUZZLES_COUNT=0
6881
NEW_ISSUES_COUNT=0
6982

@@ -136,6 +149,25 @@ while IFS=$'\t' read PUZZLE_ID TICKET TITLE REST; do
136149

137150
if [ $ISSUES_COUNT -le 0 ]; then
138151
info "$PUZZLE_ID: no related issues found. Need to create a new issue: $TITLE"
152+
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")
154+
155+
# "50-51" => {50, 51}
156+
IFS='-' read PUZZLE_LINE_START PUZZLE_LINE_END < <(echo "$PUZZLE_LINES")
157+
158+
ISSUE_BODY="$(eval "$ISSUE_BODY_TEMPLATE")"
159+
debug "$PUZZLE_ID: issue body:"
160+
debug '--- BEGIN ---'
161+
debug "$ISSUE_BODY"
162+
debug '--- END ---'
163+
164+
ISSUE_LINK="$(gh issue create --repo "$REPO" --label "$ISSUE_LABEL" --title "$TITLE" --body "$ISSUE_BODY" | sed -n '/issues/p')"
165+
# https://github.com/php-coder/mystamps/issues/1111 => 1111
166+
ISSUE_ID="$(echo "$ISSUE_LINK" | sed -E 's|.*/issues/([0-9]+)$|\1|')"
167+
info "$PUZZLE_ID => #$ISSUE_ID: issue has been created: $ISSUE_LINK"
168+
169+
info "$PUZZLE_ID => #$ISSUE_ID: link with $ISSUE_ID (just created)"
170+
printf '%s\t%s\topen\tautomatically\n' "$PUZZLE_ID" "$ISSUE_ID" >> "$MAPPING_FILE"
139171
NEW_ISSUES_COUNT=$[NEW_ISSUES_COUNT + 1]
140172
continue
141173
fi

0 commit comments

Comments
 (0)