surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Comments on a GitHub issue with a list of potential duplicates. |
| 4 | # Usage: ./comment-on-duplicates.sh --base-issue 123 --potential-duplicates 456 789 101 |
| 5 | # |
| 6 | |
| 7 | set -euo pipefail |
| 8 | |
| 9 | REPO="anthropics/claude-code" |
| 10 | BASE_ISSUE="" |
| 11 | DUPLICATES=() |
| 12 | |
| 13 | # Parse arguments |
| 14 | while [[ $# -gt 0 ]]; do |
| 15 | case $1 in |
| 16 | --base-issue) |
| 17 | BASE_ISSUE="$2" |
| 18 | shift 2 |
| 19 | ;; |
| 20 | --potential-duplicates) |
| 21 | shift |
| 22 | while [[ $# -gt 0 && ! "$1" =~ ^-- ]]; do |
| 23 | DUPLICATES+=("$1") |
| 24 | shift |
| 25 | done |
| 26 | ;; |
| 27 | *) |
| 28 | echo "Unknown option: $1" >&2 |
| 29 | exit 1 |
| 30 | ;; |
| 31 | esac |
| 32 | done |
| 33 | |
| 34 | # Validate base issue |
| 35 | if [[ -z "$BASE_ISSUE" ]]; then |
| 36 | echo "Error: --base-issue is required" >&2 |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | if ! [[ "$BASE_ISSUE" =~ ^[0-9]+$ ]]; then |
| 41 | echo "Error: --base-issue must be a number, got: $BASE_ISSUE" >&2 |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | # Validate duplicates |
| 46 | if [[ ${#DUPLICATES[@]} -eq 0 ]]; then |
| 47 | echo "Error: --potential-duplicates requires at least one issue number" >&2 |
| 48 | exit 1 |
| 49 | fi |
| 50 | |
| 51 | if [[ ${#DUPLICATES[@]} -gt 3 ]]; then |
| 52 | echo "Error: --potential-duplicates accepts at most 3 issues" >&2 |
| 53 | exit 1 |
| 54 | fi |
| 55 | |
| 56 | for dup in "${DUPLICATES[@]}"; do |
| 57 | if ! [[ "$dup" =~ ^[0-9]+$ ]]; then |
| 58 | echo "Error: duplicate issue must be a number, got: $dup" >&2 |
| 59 | exit 1 |
| 60 | fi |
| 61 | done |
| 62 | |
| 63 | # Validate that base issue exists |
| 64 | if ! gh issue view "$BASE_ISSUE" --repo "$REPO" &>/dev/null; then |
| 65 | echo "Error: issue #$BASE_ISSUE does not exist in $REPO" >&2 |
| 66 | exit 1 |
| 67 | fi |
| 68 | |
| 69 | # Validate that all duplicate issues exist |
| 70 | for dup in "${DUPLICATES[@]}"; do |
| 71 | if ! gh issue view "$dup" --repo "$REPO" &>/dev/null; then |
| 72 | echo "Error: issue #$dup does not exist in $REPO" >&2 |
| 73 | exit 1 |
| 74 | fi |
| 75 | done |
| 76 | |
| 77 | # Build comment body |
| 78 | COUNT=${#DUPLICATES[@]} |
| 79 | if [[ $COUNT -eq 1 ]]; then |
| 80 | HEADER="Found 1 possible duplicate issue:" |
| 81 | else |
| 82 | HEADER="Found $COUNT possible duplicate issues:" |
| 83 | fi |
| 84 | |
| 85 | BODY="$HEADER"$'\n\n' |
| 86 | INDEX=1 |
| 87 | for dup in "${DUPLICATES[@]}"; do |
| 88 | BODY+="$INDEX. https://github.com/$REPO/issues/$dup"$'\n' |
| 89 | ((INDEX++)) |
| 90 | done |
| 91 | |
| 92 | BODY+=$'\n'"This issue will be automatically closed as a duplicate in 3 days."$'\n\n' |
| 93 | BODY+="- If your issue is a duplicate, please close it and 👍 the existing issue instead"$'\n' |
| 94 | BODY+="- To prevent auto-closure, add a comment or 👎 this comment"$'\n\n' |
| 95 | BODY+="🤖 Generated with [Claude Code](https://claude.ai/code)" |
| 96 | |
| 97 | # Post the comment |
| 98 | gh issue comment "$BASE_ISSUE" --repo "$REPO" --body "$BODY" |
| 99 | |
| 100 | echo "Posted duplicate comment on issue #$BASE_ISSUE" |