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 --potential-duplicates 456 789 101 |
| 5 | # |
| 6 | # The base issue number is read from the workflow event payload. |
| 7 | # |
| 8 | |
| 9 | set -euo pipefail |
| 10 | |
| 11 | REPO="anthropics/claude-code" |
| 12 | |
| 13 | # Read from event payload so the issue number is bound to the triggering event. |
| 14 | # Falls back to workflow_dispatch inputs for manual runs. |
| 15 | BASE_ISSUE=$(jq -r '.issue.number // .inputs.issue_number // empty' "${GITHUB_EVENT_PATH:?GITHUB_EVENT_PATH not set}") |
| 16 | if ! [[ "$BASE_ISSUE" =~ ^[0-9]+$ ]]; then |
| 17 | echo "Error: no issue number in event payload" >&2 |
| 18 | exit 1 |
| 19 | fi |
| 20 | |
| 21 | DUPLICATES=() |
| 22 | |
| 23 | # Parse arguments |
| 24 | while [[ $# -gt 0 ]]; do |
| 25 | case $1 in |
| 26 | --potential-duplicates) |
| 27 | shift |
| 28 | while [[ $# -gt 0 && ! "$1" =~ ^-- ]]; do |
| 29 | DUPLICATES+=("$1") |
| 30 | shift |
| 31 | done |
| 32 | ;; |
| 33 | *) |
| 34 | echo "Error: unknown argument (only --potential-duplicates is accepted)" >&2 |
| 35 | exit 1 |
| 36 | ;; |
| 37 | esac |
| 38 | done |
| 39 | |
| 40 | # Validate duplicates |
| 41 | if [[ ${#DUPLICATES[@]} -eq 0 ]]; then |
| 42 | echo "Error: --potential-duplicates requires at least one issue number" >&2 |
| 43 | exit 1 |
| 44 | fi |
| 45 | |
| 46 | if [[ ${#DUPLICATES[@]} -gt 3 ]]; then |
| 47 | echo "Error: --potential-duplicates accepts at most 3 issues" >&2 |
| 48 | exit 1 |
| 49 | fi |
| 50 | |
| 51 | for dup in "${DUPLICATES[@]}"; do |
| 52 | if ! [[ "$dup" =~ ^[0-9]+$ ]]; then |
| 53 | echo "Error: duplicate issue must be a number, got: $dup" >&2 |
| 54 | exit 1 |
| 55 | fi |
| 56 | done |
| 57 | |
| 58 | # Validate that base issue exists |
| 59 | if ! gh issue view "$BASE_ISSUE" --repo "$REPO" &>/dev/null; then |
| 60 | echo "Error: issue #$BASE_ISSUE does not exist in $REPO" >&2 |
| 61 | exit 1 |
| 62 | fi |
| 63 | |
| 64 | # Validate that all duplicate issues exist |
| 65 | for dup in "${DUPLICATES[@]}"; do |
| 66 | if ! gh issue view "$dup" --repo "$REPO" &>/dev/null; then |
| 67 | echo "Error: issue #$dup does not exist in $REPO" >&2 |
| 68 | exit 1 |
| 69 | fi |
| 70 | done |
| 71 | |
| 72 | # Build comment body |
| 73 | COUNT=${#DUPLICATES[@]} |
| 74 | if [[ $COUNT -eq 1 ]]; then |
| 75 | HEADER="Found 1 possible duplicate issue:" |
| 76 | else |
| 77 | HEADER="Found $COUNT possible duplicate issues:" |
| 78 | fi |
| 79 | |
| 80 | BODY="$HEADER"$'\n\n' |
| 81 | INDEX=1 |
| 82 | for dup in "${DUPLICATES[@]}"; do |
| 83 | BODY+="$INDEX. https://github.com/$REPO/issues/$dup"$'\n' |
| 84 | ((INDEX++)) |
| 85 | done |
| 86 | |
| 87 | BODY+=$'\n'"This issue will be automatically closed as a duplicate in 3 days."$'\n\n' |
| 88 | BODY+="- If your issue is a duplicate, please close it and 👍 the existing issue instead"$'\n' |
| 89 | BODY+="- To prevent auto-closure, add a comment or 👎 this comment"$'\n\n' |
| 90 | BODY+="🤖 Generated with [Claude Code](https://claude.ai/code)" |
| 91 | |
| 92 | # Post the comment |
| 93 | gh issue comment "$BASE_ISSUE" --repo "$REPO" --body "$BODY" |
| 94 | |
| 95 | echo "Posted duplicate comment on issue #$BASE_ISSUE" |