Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow for branch age notification #496

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/branch-notification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Branch Age Notification

on:
schedule:
- cron: '0 12 * * 5' # Run every Friday at 12pm CET

jobs:
branch-age-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check for branches older than 180 days
uses: actions/github-script@v6
with:
script: |
const { data: branches } = await github.repos.listBranches({
owner: context.repo.owner,
repo: context.repo.repo,
});
const oldBranches = branches.filter(branch => {
const lastCommitDate = new Date(branch.commit.commit.author.date);
const daysOld = (new Date() - lastCommitDate) / (1000 * 60 * 60 * 24);
return daysOld > 180;
});
if (oldBranches.length > 0) {
console.log(`Found ${oldBranches.length} branches older than 180 days.`);
for (const branch of oldBranches) {
const { data: commits } = await github.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
sha: branch.name,
per_page: 1,
});
const commitAuthorEmail = commits[0].commit.author.email;
await github.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: commits[0].sha,
body: `This branch is more than 180 days old. Consider deleting or archiving it.`
});
}
} else {
console.log('No branches older than 180 days were found.');
}
Loading