-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (54 loc) · 1.82 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
'use strict';
import { getInput } from '@actions/core';
import { context, getOctokit } from '@actions/github';
const targetUserLogin = getInput('userLogin');
const targetUserId = getInput('userId');
const targetUserType = getInput('usertype');
const substrings = [
'[0 New issues]',
'[0 Accepted issues]',
'[0 Security Hotspots]',
"passed-16px.png '') [0.0% Coverage on New Code",
"passed-16px.png '') [0.0% Duplication on New Code",
];
const repo = context.repo; // is an object {owner: string; repo: string}
const comment = context.payload.comment;
const userLogin = comment.user.login;
const userId = comment.user.id;
const userType = comment.user.type;
const body = comment.body;
const commentId = comment.id;
console.log(`User login: ${userLogin}, user id: ${userId}, user type: ${userType}`);
// context user.id is a number, input userId is a string, comparing loosely
if (userLogin === targetUserLogin && userId == targetUserId && userType === targetUserType) {
console.log('✅ User matches');
} else {
console.log(`⏭ Only looking for user login: ${targetUserLogin}, user id: ${targetUserId}, user type: ${targetUserType}`);
process.exit(0);
}
if (isMatching(body, substrings)) {
console.log('✅ Comment body matches');
} else {
console.log('⏭ Comment body doesn\'t match');
process.exit(0);
}
const octokit = getOctokit(process.env.GITHUB_TOKEN);
const request = {
...repo,
comment_id: commentId,
};
console.log(`Request: ${ JSON.stringify(request) }`);
octokit.rest.issues.deleteComment(request)
.then(({ status, url }) => {
console.log(`✅ Response: ${ JSON.stringify({ status, url }) }`);
})
.catch(error => {
console.error(`🔥 Error: ${error}`);
});
function isMatching(body, substrings) {
return substrings.every(s => {
const f = body.includes(s);
console.log(`${s}: ${f}`);
return f;
});
}