Skip to content

fix(scripts): make create-github-issues.sh compatible with macOS#82

Merged
adnaan merged 2 commits intomainfrom
fix/github-issues-script
Jan 25, 2026
Merged

fix(scripts): make create-github-issues.sh compatible with macOS#82
adnaan merged 2 commits intomainfrom
fix/github-issues-script

Conversation

@adnaan
Copy link
Copy Markdown
Contributor

@adnaan adnaan commented Jan 25, 2026

Summary

Test plan

  • Verified script works with --dry-run flag
  • Successfully created 30 issues across 6 milestones
  • Verified issues appear correctly on GitHub with proper labels and milestones

🤖 Generated with Claude Code

adnaan and others added 2 commits January 25, 2026 10:37
… 3.2

- Replace declare -A (bash 4+) with file-based key-value storage
- Query JSON file directly instead of storing in bash variables
  (avoids escaping issues with special characters in issue bodies)
- Change label delimiter from : to | to support labels like priority:critical
- Add error output when issue creation fails

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Issues #52-#81 have been created on GitHub. Keeping milestones as
reference for future issue additions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 25, 2026 10:02
@claude
Copy link
Copy Markdown

claude bot commented Jan 25, 2026

PR Review: Fix bash 3.2 Compatibility for macOS

Summary

This PR successfully addresses macOS compatibility issues by replacing bash 4+ features with bash 3.2-compatible alternatives. The changes are well-implemented and solve real problems.

Code Quality & Best Practices ✅

Strengths:

  • Excellent bash 3.2 compatibility solution using file-based storage instead of associative arrays
  • Proper cleanup with trap ensures temp files are removed even on failure
  • Improved error handling (lines 276-279) now shows detailed errors when issue creation fails
  • Smart delimiter change from : to | allows labels like priority:critical to work
  • Better JSON handling by querying files directly avoids bash variable escaping issues

Suggestions for improvement:

  1. Reduce code duplication in the create_issue() function (lines 250-264):
# Instead of duplicating the gh issue create command:
local gh_args=(--repo "$REPO" --title "$full_title" --body-file "$body_file")
[[ -n "$labels" ]] && gh_args+=(--label "$labels")
[[ -n "$milestone" && "$milestone" != "null" ]] && gh_args+=(--milestone "$milestone")
issue_url=$(gh issue create "${gh_args[@]}" 2>&1)
  1. Improve grep safety in get_issue_map() (line 117) for IDs with special characters:
grep "^${1}=" "$ISSUE_MAP_FILE" 2>/dev/null | cut -d= -f2 | tail -1

Potential Issues 🐛

  1. Concurrent write safety: The set_issue_map() function appends to the file, relying on tail -1 to handle duplicates. While unlikely to cause issues in sequential execution, consider making it more robust:
set_issue_map() {
    local key="$1" value="$2"
    grep -v "^${key}=" "$ISSUE_MAP_FILE" > "${ISSUE_MAP_FILE}.tmp" 2>/dev/null || true
    echo "${key}=${value}" >> "${ISSUE_MAP_FILE}.tmp"
    mv "${ISSUE_MAP_FILE}.tmp" "$ISSUE_MAP_FILE"
}
  1. Empty issues array handling: Add graceful handling when issues array is empty:
if [[ $issue_count -eq 0 ]]; then
    echo -e "${YELLOW}No issues to create${NC}"
    exit 0
fi

Performance ⚡

Good:

  • Querying JSON directly is more efficient than storing in bash variables
  • File-based storage is performant for expected volume (<100 issues)

Security 🔒

Good practices observed:

  • ✅ Proper mktemp usage
  • ✅ Cleanup with trap prevents temp file leakage
  • ✅ Using --body-file prevents command injection
  • ✅ Proper quoting throughout

Testing 🧪

Recommendations:

  1. Add ShellCheck to CI to catch common bash issues
  2. Add smoke test that runs --dry-run on both bash 3.2 (macOS) and bash 4+ (Linux)
  3. Document bash version requirement in script header:
# Requires: bash 3.2+, gh CLI, jq
  1. Consider adding version check:
if [[ "${BASH_VERSINFO[0]}" -lt 3 ]]; then
    echo -e "${RED}Error: bash 3.0 or higher required${NC}"
    exit 1
fi

Overall Assessment ⭐

Verdict: Approve with minor suggestions

This is a solid fix that solves real compatibility issues. The core changes are well-designed:

  • File-based mapping is a clean solution for bash 3.2 compatibility
  • Delimiter change fixes label parsing
  • Direct JSON queries avoid escaping issues
  • Error handling improvements aid debugging

The suggestions above are nice-to-haves that would make the script more robust, but they're not blockers. The PR is ready to merge as-is, with optional follow-up improvements.

Score: 8.5/10

Great work! 🎉

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the create-github-issues.sh script compatible with macOS by addressing bash 3.2 limitations and improving JSON parsing robustness. The issues defined in github-issues.json were successfully created on GitHub (issues #52-#81) and subsequently cleared from the file.

Changes:

  • Replaced bash 4+ associative arrays with file-based key-value storage for bash 3.2 compatibility
  • Changed JSON parsing to query the file directly instead of passing through bash variables, avoiding escaping issues
  • Changed label delimiter from : to | to support labels containing colons (e.g., priority:critical)
  • Cleared the issues array in github-issues.json after successful issue creation with a note documenting what happened

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
scripts/create-github-issues.sh Refactored to use file-based mapping instead of associative arrays; improved JSON parsing and error handling; fixed label delimiter
scripts/github-issues.json Cleared issues array after successful creation with documentation note

declare -A ISSUE_MAP
# Using a temp file for bash 3.2 compatibility (macOS default)
ISSUE_MAP_FILE=$(mktemp)
trap "rm -f $ISSUE_MAP_FILE" EXIT
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trap command should quote the variable to ensure proper cleanup even if the path contains spaces. While mktemp typically generates paths without spaces, it's a best practice to quote variables in shell scripts for robustness.

Suggested change
trap "rm -f $ISSUE_MAP_FILE" EXIT
trap 'rm -f "$ISSUE_MAP_FILE"' EXIT

Copilot uses AI. Check for mistakes.
${labels:+--label "$labels"} \
${milestone_num:+--milestone "$milestone_num"} \
2>&1 | grep -oE '[0-9]+$' || echo "")
issue_num=$(echo "$issue_url" | grep -oE '[0-9]+$' || echo "")
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue number extraction assumes the URL ends with just the issue number, but if gh issue create fails, the error message in issue_url might contain numbers that get incorrectly extracted. For example, an error like "rate limit exceeded, try again in 60 seconds" would extract "60" as the issue number. Consider checking if the issue_url contains "github.com" before attempting to extract the number, or check the exit code of gh issue create separately.

Copilot uses AI. Check for mistakes.
Comment on lines 244 to 245
body_file=$(mktemp)
echo "$body" > "$body_file"
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The body_file temporary file is created but may not be cleaned up if the script exits unexpectedly between lines 244 and 269. Consider adding a trap for this temp file similar to the ISSUE_MAP_FILE, or use a cleanup pattern that ensures removal even on early exit.

Copilot uses AI. Check for mistakes.
@adnaan adnaan merged commit 99f2463 into main Jan 25, 2026
8 checks passed
@adnaan adnaan deleted the fix/github-issues-script branch January 25, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants