-
-
Notifications
You must be signed in to change notification settings - Fork 560
40 lines (33 loc) · 1.47 KB
/
close_old_prs.yaml
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
name: Close PRs Without Linked Issues
on:
schedule:
- cron: '0 0 * * *'
jobs:
close_prs_without_issue:
runs-on: ubuntu-latest
steps:
- name: Check and Close PRs Without Linked Issues
id: close_prs
uses: actions/checkout@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const daysThreshold = 30;
const { owner, repo } = context.repo;
const { data: pullRequests } = await github.pulls.list({ owner, repo, state: 'open' });
pullRequests.forEach(async (pr) => {
const { data: issues } = await github.issues.listForRepo({ owner, repo, per_page: 100 });
const linkedIssue = issues.find((issue) =>
issue.pull_request && issue.pull_request.url === pr.url
);
if (!linkedIssue) {
await github.pulls.update({ owner, repo, pull_number: pr.number, state: 'closed' });
await github.issues.createComment({
owner,
repo,
issue_number: pr.number,
body: "This pull request has been closed because it does not mention the issue that it solves. Please refer to the [Contributing files](https://github.com/rupali-codes/LinksHub/blob/main/CONTRIBUTING.md#issues) to help you add this information. Then, tag the maintainers so your PR can be reopened."
});
}
});