-
Notifications
You must be signed in to change notification settings - Fork 12
122 lines (107 loc) · 4.47 KB
/
delete-duplicate-issues.yml
File metadata and controls
122 lines (107 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Delete Duplicate Issues
on:
workflow_dispatch:
inputs:
confirm:
description: 'Type "DELETE-PERMANENTLY" to confirm permanent deletion of duplicate issues'
required: true
type: string
dry_run:
description: 'Dry run (preview only, no deletion)'
required: false
type: boolean
default: true
jobs:
delete-duplicates:
name: Permanently delete duplicate issues
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
- name: Validate confirmation
if: ${{ github.event.inputs.dry_run == 'false' }}
run: |
if [ "${{ github.event.inputs.confirm }}" != "DELETE-PERMANENTLY" ]; then
echo "❌ Confirmation failed. You must type 'DELETE-PERMANENTLY' to proceed."
exit 1
fi
echo "✓ Confirmation validated - proceeding with permanent deletion"
- name: Find and delete duplicate issues
env:
REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DRY_RUN: ${{ github.event.inputs.dry_run }}
run: |
set -e
if [ "$DRY_RUN" = "true" ]; then
echo "🔍 DRY RUN MODE - No issues will be deleted"
else
echo "⚠️ WARNING: This will PERMANENTLY DELETE duplicate issues"
fi
echo "Fetching all open issues with 'hacktoberfest' label..."
# Fetch all open issues with hacktoberfest label
issues=$(curl -sS -H "Authorization: token $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$REPO/issues?state=open&labels=hacktoberfest&per_page=100")
# Create a temporary file to track titles and their issue numbers
temp_file=$(mktemp)
echo "$issues" | jq -r '.[] | "\(.title)|\(.number)|\(.created_at)"' | sort > "$temp_file"
# Find duplicates (same title) and keep the oldest one
duplicates_found=false
current_title=""
oldest_issue=""
oldest_date=""
while IFS='|' read -r title issue_num created_at; do
if [ "$title" = "$current_title" ]; then
# This is a duplicate
duplicates_found=true
# Compare dates to keep the oldest
if [ -z "$oldest_date" ] || [ "$created_at" \< "$oldest_date" ]; then
# Current issue is older, delete the previous one
if [ -n "$oldest_issue" ]; then
echo "🗑️ Found duplicate: #$oldest_issue - '$title' (newer, will delete)"
if [ "$DRY_RUN" = "false" ]; then
gh issue delete "$oldest_issue" --repo "$REPO" --yes
if [ $? -eq 0 ]; then
echo "✓ Deleted duplicate issue #$oldest_issue"
else
echo "✗ Failed to delete issue #$oldest_issue"
fi
else
echo " [DRY RUN] Would delete issue #$oldest_issue"
fi
fi
oldest_issue="$issue_num"
oldest_date="$created_at"
else
# Previous issue is older, delete this one
echo "🗑️ Found duplicate: #$issue_num - '$title' (newer, will delete)"
if [ "$DRY_RUN" = "false" ]; then
gh issue delete "$issue_num" --repo "$REPO" --yes
if [ $? -eq 0 ]; then
echo "✓ Deleted duplicate issue #$issue_num"
else
echo "✗ Failed to delete issue #$issue_num"
fi
else
echo " [DRY RUN] Would delete issue #$issue_num"
fi
fi
else
# New title, reset tracking
current_title="$title"
oldest_issue="$issue_num"
oldest_date="$created_at"
fi
done < "$temp_file"
rm "$temp_file"
if [ "$duplicates_found" = "false" ]; then
echo "✓ No duplicate issues found."
elif [ "$DRY_RUN" = "true" ]; then
echo ""
echo "🔍 Dry run complete. Re-run with 'Dry run: false' and type 'DELETE-PERMANENTLY' to actually delete duplicates."
else
echo "✓ Duplicate deletion complete."
echo "⚠️ Note: Deleted issues cannot be recovered!"
fi