Skip to content

Cleanup branches and issues #40

Cleanup branches and issues

Cleanup branches and issues #40

name: Cleanup branches and issues
on:
schedule:
- cron: '0 0 * * *' # Run this workflow every day at midnight
workflow_dispatch:
env:
DAYS: 7
jobs:
deleteOldBranches:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install jq
run: sudo apt-get install -y jq
- name: Fetch all branches
run: git fetch --all
- name: Delete old branches
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./src/delete_old_branches.sh
closeOldIssues:
runs-on: ubuntu-latest
steps:
- name: Close old data request issues
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const max_age = process.env.DAYS * 24 * 60 * 60 * 1000;
const now = new Date();
const issues = await github.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: 'data request',
state: 'open'
});
for (const issue of issues.data) {
const createdAt = new Date(issue.created_at);
if (now - createdAt > max_age) {
await github.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});
}
}