-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (48 loc) · 1.49 KB
/
cleanup_branches_and_issues.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
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'
});
}
}