Skip to content

Commit d34f52c

Browse files
author
testcafe-build-bot
committed
🔄 synced local '.github/scripts/security-checker.mjs' with remote 'scripts/security-checker.mjs'
1 parent c6a8503 commit d34f52c

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

‎.github/scripts/security-checker.mjs‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ const LABELS = {
99
security: 'security notification',
1010
};
1111

12+
const ALERT_TYPES = {
13+
dependabot: 'dependabot',
14+
codeq: 'codeql',
15+
}
16+
1217
class SecurityChecker {
1318
constructor (github, context, issueRepo) {
1419
this.github = github;
@@ -27,8 +32,8 @@ class SecurityChecker {
2732
this.alertDictionary = this.createAlertDictionary(existedIssues);
2833

2934
await this.closeSpoiledIssues();
30-
this.createDependabotlIssues(dependabotAlerts);
31-
this.createCodeqlIssues(codeqlAlerts);
35+
await this.createDependabotlIssues(dependabotAlerts);
36+
await this.createCodeqlIssues(codeqlAlerts);
3237
}
3338

3439
async getDependabotAlerts () {
@@ -64,15 +69,13 @@ class SecurityChecker {
6469

6570
createAlertDictionary (existedIssues) {
6671
return existedIssues.reduce((res, issue) => {
67-
const [, url, number] = issue.body.match(/Link:\s*(https.*?(\d+)$)/);
72+
const [, repo] = issue.body.match(/Repository:\s*`(.*)`/);
73+
const [, url, type, number] = issue.body.match(/Link:\s*(https:.*\/(dependabot|code-scanning)\/(\d+))/);
6874

69-
if (!url)
75+
if (!url || repo !== this.context.repo)
7076
return res;
7177

72-
res[url] = {
73-
issue, number,
74-
isDependabot: url.includes('dependabot'),
75-
};
78+
res[url] = { issue, number, type };
7679

7780
return res;
7881
}, {});
@@ -82,7 +85,7 @@ class SecurityChecker {
8285
for (const key in this.alertDictionary) {
8386
const alert = this.alertDictionary[key];
8487

85-
if (alert.isDependabot) {
88+
if (alert.type === ALERT_TYPES.dependabot) {
8689
const isAlertOpened = await this.isDependabotAlertOpened(alert.number);
8790

8891
if (isAlertOpened)
@@ -123,38 +126,38 @@ class SecurityChecker {
123126
}
124127

125128
async createDependabotlIssues (dependabotAlerts) {
126-
dependabotAlerts.forEach(alert => {
129+
for (const alert of dependabotAlerts) {
127130
if (!this.needCreateIssue(alert))
128131
return;
129132

130-
this.createIssue({
133+
await this.createIssue({
131134
labels: [LABELS.dependabot, LABELS.security, alert.dependency.scope],
132135
originRepo: this.context.repo,
133136
summary: alert.security_advisory.summary,
134137
description: alert.security_advisory.description,
135138
link: alert.html_url,
136139
issuePackage: alert.dependency.package.name,
137140
});
138-
});
141+
}
139142
}
140143

141144
async createCodeqlIssues (codeqlAlerts) {
142-
codeqlAlerts.forEach(alert => {
145+
for (const alert of codeqlAlerts) {
143146
if (!this.needCreateIssue(alert))
144147
return;
145148

146-
this.createIssue({
149+
await this.createIssue({
147150
labels: [LABELS.codeql, LABELS.security],
148151
originRepo: this.context.repo,
149152
summary: alert.rule.description,
150153
description: alert.most_recent_instance.message.text,
151154
link: alert.html_url,
152155
});
153-
});
156+
}
154157
}
155158

156159
needCreateIssue (alert) {
157-
return !this.alertDictionary[alert.html_url] && Date.now() - new Date(alert.created_at) <= 1000 * 60 * 60 * 24;;
160+
return !this.alertDictionary[alert.html_url] && Date.now() - new Date(alert.created_at) <= 1000 * 60 * 60 * 24;
158161
}
159162

160163
async createIssue ({ labels, originRepo, summary, description, link, issuePackage = '' }) {

0 commit comments

Comments
 (0)