spacehub

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

claude-code / scripts / comment-on-duplicates.sh
86 lines · 2.0 KBRaw
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
7set -euo pipefail
8
9REPO="anthropics/claude-code"
10BASE_ISSUE=""
11DUPLICATES=()
12
13# Parse arguments
14while [[ $# -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
32done
33
34# Validate base issue
35if [[ -z "$BASE_ISSUE" ]]; then
36 echo "Error: --base-issue is required" >&2
37 exit 1
38fi
39
40if ! [[ "$BASE_ISSUE" =~ ^[0-9]+$ ]]; then
41 echo "Error: --base-issue must be a number, got: $BASE_ISSUE" >&2
42 exit 1
43fi
44
45# Validate duplicates
46if [[ ${#DUPLICATES[@]} -eq 0 ]]; then
47 echo "Error: --potential-duplicates requires at least one issue number" >&2
48 exit 1
49fi
50
51if [[ ${#DUPLICATES[@]} -gt 3 ]]; then
52 echo "Error: --potential-duplicates accepts at most 3 issues" >&2
53 exit 1
54fi
55
56for 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
61done
62
63# Build comment body
64COUNT=${#DUPLICATES[@]}
65if [[ $COUNT -eq 1 ]]; then
66 HEADER="Found 1 possible duplicate issue:"
67else
68 HEADER="Found $COUNT possible duplicate issues:"
69fi
70
71BODY="$HEADER"$'\n\n'
72INDEX=1
73for dup in "${DUPLICATES[@]}"; do
74 BODY+="$INDEX. https://github.com/$REPO/issues/$dup"$'\n'
75 ((INDEX++))
76done
77
78BODY+=$'\n'"This issue will be automatically closed as a duplicate in 3 days."$'\n\n'
79BODY+="- If your issue is a duplicate, please close it and 👍 the existing issue instead"$'\n'
80BODY+="- To prevent auto-closure, add a comment or 👎 this comment"$'\n\n'
81BODY+="🤖 Generated with [Claude Code](https://claude.ai/code)"
82
83# Post the comment
84gh issue comment "$BASE_ISSUE" --repo "$REPO" --body "$BODY"
85
86echo "Posted duplicate comment on issue #$BASE_ISSUE"