-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleaner.js
39 lines (34 loc) · 1.13 KB
/
cleaner.js
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
const github = require('@actions/github');
const dayjs = require('dayjs');
let cleaner = async function (repositoryToken, repositoryName, repositoryOwner, daysBeforeDeletion, dryRun) {
const query = `query ($name: String!, $owner: String!) {
repository(name: $name, owner: $owner) {
issues(first: 100, states: CLOSED, orderBy: {field: UPDATED_AT, direction: ASC}) {
nodes {
id,
number,
title,
updatedAt
}
}
}
}`;
const mutation = `mutation ($issueId: ID!) {
deleteIssue(input: {issueId: $issueId}) {
clientMutationId
}
}`;
const octokit = github.getOctokit(repositoryToken);
const response = await octokit.graphql(query, {name: repositoryName, owner: repositoryOwner});
const issueList = response.repository.issues.nodes;
const limitDate = dayjs().subtract(daysBeforeDeletion, 'days');
issueList.forEach((issue) => {
const issueDate = dayjs(issue.updatedAt);
if (issueDate.isBefore(limitDate)) {
if (!dryRun)
octokit.graphql(mutation, {issueId: issue.id});
console.log(issue)
}
});
};
module.exports = cleaner;