-
Notifications
You must be signed in to change notification settings - Fork 0
61 lines (51 loc) · 2.38 KB
/
stale_branches.yml
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
name: Remind and Delete Stale Branches
on:
schedule:
- cron: '0 0 * * *' # Runs daily
jobs:
remind_delete_stale_branches:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Identify Stale Branches
run: |
# Write your script here to identify stale branches
# For demonstration purposes, I'll provide a simple example using git commands
# Fetch all branches from the remote repository
git fetch --all
# Define the threshold for stale branches (for example, branches not updated in the last 1 day)
threshold_date=$(date -d "1 day ago" +"%Y-%m-%d")
# List all remote branches and iterate over each one
git branch -r --format="%(refname:short) %(authordate:short)" | while read branch_date branch_name; do
# Remove "origin/" prefix from the branch name
branch_name=${branch_name#"origin/"}
# Compare the branch's last commit date with the threshold date
if [[ "$branch_date" < "$threshold_date" ]]; then
# Check if a reminder count file exists for the branch
reminder_file=".github/reminders/$branch_name"
if [[ -f "$reminder_file" ]]; then
# Read the reminder count from the file
reminder_count=$(<"$reminder_file")
else
# Create a reminder count file for the branch
reminder_count=0
fi
# Increment the reminder count
((reminder_count++))
# Save the updated reminder count to the file
echo "$reminder_count" > "$reminder_file"
# If the reminder count exceeds 5, delete the stale branch
if ((reminder_count >= 5)); then
# Delete the stale branch
git push origin --delete "$branch_name"
echo "Deleted stale branch: $branch_name"
# Optionally, you can also remove the reminder count file after deletion
rm "$reminder_file"
else
# Send a reminder notification to the branch owner
# Replace the following line with your notification logic
echo "Reminder $reminder_count: Please delete stale branch '$branch_name'."
fi
fi
done