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
100 lines · 2.4 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# Validate that base issue exists
64if ! 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
67fi
68
69# Validate that all duplicate issues exist
70for 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
75done
76
77# Build comment body
78COUNT=${#DUPLICATES[@]}
79if [[ $COUNT -eq 1 ]]; then
80 HEADER="Found 1 possible duplicate issue:"
81else
82 HEADER="Found $COUNT possible duplicate issues:"
83fi
84
85BODY="$HEADER"$'\n\n'
86INDEX=1
87for dup in "${DUPLICATES[@]}"; do
88 BODY+="$INDEX. https://github.com/$REPO/issues/$dup"$'\n'
89 ((INDEX++))
90done
91
92BODY+=$'\n'"This issue will be automatically closed as a duplicate in 3 days."$'\n\n'
93BODY+="- If your issue is a duplicate, please close it and 👍 the existing issue instead"$'\n'
94BODY+="- To prevent auto-closure, add a comment or 👎 this comment"$'\n\n'
95BODY+="🤖 Generated with [Claude Code](https://claude.ai/code)"
96
97# Post the comment
98gh issue comment "$BASE_ISSUE" --repo "$REPO" --body "$BODY"
99
100echo "Posted duplicate comment on issue #$BASE_ISSUE"