Skip to content

Commit

Permalink
Create stale_branches.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
arshadmhabib authored Mar 5, 2024
0 parents commit 13d0231
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/stale_branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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

0 comments on commit 13d0231

Please sign in to comment.