-
Notifications
You must be signed in to change notification settings - Fork 5
/
remove-old-lokalise-prs.js
52 lines (48 loc) · 1.3 KB
/
remove-old-lokalise-prs.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
40
41
42
43
44
45
46
47
48
49
50
51
52
const github = require("@actions/github");
async function main() {
const token = process.env.TOKEN;
const owner = github.context.repo.owner;
const repo = github.context.repo.repo;
const octo = github.getOctokit(token);
const currentPR = github.context.issue.number;
//Fetch PRs
octo.rest.pulls.list({
owner: owner,
repo: repo,
}).then(prs => {
//Filter PRs
let filteredPrs = prs.data.filter(pr => {
let regex = new RegExp('^Lokalise:[ _a-zA-Z0-9]+');
return regex.test(pr.title) && pr.number != currentPR;
});
if (filteredPrs && filteredPrs.length) {
filteredPrs.forEach(pr => {
//Close Branch
octo.rest.pulls.update({
owner: owner,
repo: repo,
pull_number: pr.number,
state: 'closed'
});
//Delete Branch
octo.rest.pulls.get({
owner: owner,
repo: repo,
pull_number: pr.number
}).then(({ data }) => {
const ref = 'heads/' + data['head']['ref'];
try {
octo.rest.git.deleteRef({
owner: owner,
repo: repo,
ref
});
} catch ({ message }) { console.log(message) }
});
});
}
}).catch(e => {
console.error(e);
});
};
main();