Skip to content

Commit d7e2e30

Browse files
authored
build: include comments and code snippets in created issues
PR-URL: #5301 Closes: stdlib-js/metr-issue-tracker#7 Reviewed-by: Athan Reines <[email protected]>
1 parent 353ca8c commit d7e2e30

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

.github/workflows/scripts/create_address_commit_comments_issues

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,25 @@ is_core_contributor() {
233233

234234
# Updates two indexed arrays (commit_keys and commit_counts) to simulate a map.
235235
#
236-
# $1 - Commit SHA (the key)
237-
# $2 - Comment URL (the link)
236+
# $1 - Full comment object (JSON)
238237
update_commit_map() {
239-
local key="$1"
240-
local link="$2"
238+
local comment="$1"
239+
local key=$(echo "$comment" | jq -r '.commit_id')
240+
local link=$(echo "$comment" | jq -r '.html_url')
241+
local body=$(echo "$comment" | jq -r '.body')
242+
local line=$(echo "$comment" | jq -r '.line')
243+
local path=$(echo "$comment" | jq -r '.path')
241244
local found=0
242245
local i=0
243246

247+
local startLine=$(( line - 3 ))
248+
local endLine=$(( line + 3 ))
249+
local code_snippet="https://github.com/stdlib-js/stdlib/blob/${key}/${path}#L${startLine}-L${endLine}"
250+
244251
for existing in "${commit_keys[@]}"; do
245252
if [ "$existing" = "$key" ]; then
246253
commit_counts[i]=$(( commit_counts[i] + 1 ))
247-
# Append the comment URL (on a new bullet) to the existing list:
248-
commit_links[i]="${commit_links[i]}"$'\n'"- ${link}"
254+
commit_comments[i]="${commit_comments[i]}"$'\n\n'"- ${link}"$'\n\n'" > **Line ${line}**: ${body}"$'\n\n'" ${code_snippet}"
249255
found=1
250256
break
251257
fi
@@ -255,7 +261,7 @@ update_commit_map() {
255261
if [ "$found" -eq 0 ]; then
256262
commit_keys+=("$key")
257263
commit_counts+=("1")
258-
commit_links+=("- ${link}")
264+
commit_comments+=("- ${link}"$'\n\n'" > **Line ${line}**: ${body}"$'\n\n'" ${code_snippet}")
259265
fi
260266
}
261267

@@ -339,12 +345,12 @@ main() {
339345

340346
commit_keys=()
341347
commit_counts=()
342-
commit_links=()
348+
commit_comments=()
343349

344350
for comment in "${all_comments[@]}"; do
345351
# Extract the comment body:
346-
local comment_body
347-
comment_body=$(echo "$comment" | jq -r '.body')
352+
local comment_body=$(echo "$comment" | jq -r '.body')
353+
local comment_line=$(echo "$comment" | jq -r '.line')
348354

349355
# Check if the comment body contains '@stdlib-bot':
350356
if [[ "$comment_body" == *"@stdlib-bot"* ]]; then
@@ -357,10 +363,7 @@ main() {
357363
local commit_sha
358364
commit_sha=$(echo "$comment" | jq -r '.commit_id')
359365
if [ -n "$commit_sha" ]; then
360-
# Extract the comment URL:
361-
local comment_url
362-
comment_url=$(echo "$comment" | jq -r '.html_url')
363-
update_commit_map "$commit_sha" "$comment_url"
366+
update_commit_map "$comment"
364367
fi
365368
else
366369
echo "Skipping comment by non-core contributor: ${comment_author}" >&2
@@ -373,7 +376,7 @@ main() {
373376
for idx in $(seq 0 $(( ${#commit_keys[@]} - 1 ))); do
374377
local commit_sha="${commit_keys[$idx]}"
375378
local count="${commit_counts[$idx]}"
376-
local links="${commit_links[$idx]}"
379+
local comments="${commit_comments[$idx]}"
377380

378381
# Generate a short SHA (first 7 characters):
379382
local short_sha=${commit_sha:0:7}
@@ -385,7 +388,7 @@ main() {
385388
386389
**Comments:**
387390
388-
${links}
391+
${comments}
389392
390393
Interested in helping improve the project? If you are, the comment linked to above has **${count}** comment(s) from core contributors that could use your attention.
391394

0 commit comments

Comments
 (0)