Skip to content

Commit 2f4c835

Browse files
committed
feat: update announcement link on --pre-release
1 parent 862883d commit 2f4c835

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

lib/security_blog.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
PLACEHOLDERS,
77
checkoutOnSecurityReleaseBranch,
88
validateDate,
9-
SecurityRelease
9+
SecurityRelease,
10+
commitAndPushVulnerabilitiesJSON,
1011
} from './security-release/security-release.js';
1112
import auth from './auth.js';
1213
import Request from './request.js';
@@ -56,16 +57,41 @@ export default class SecurityBlog extends SecurityRelease {
5657
const endDate = new Date(data.annoucementDate);
5758
endDate.setDate(endDate.getDate() + 7);
5859

60+
const link = `https://nodejs.org/en/blog/vulnerability/${fileName}`;
5961
this.updateWebsiteBanner(site, {
6062
startDate: data.annoucementDate,
6163
endDate: endDate.toISOString(),
6264
text: `New security releases to be made available ${data.releaseDate}`,
63-
link: `https://nodejs.org/en/blog/vulnerability/${fileName}`,
65+
link,
6466
type: 'warning'
6567
});
66-
6768
fs.writeFileSync(file, preRelease);
69+
6870
cli.ok(`Announcement file created and banner has been updated. Folder: ${nodejsOrgFolder}`);
71+
await this.updateAnnouncementLink(link);
72+
}
73+
74+
async updateAnnouncementLink(link) {
75+
const vulnerabilitiesJSONPath = this.getVulnerabilitiesJSONPath();
76+
const content = this.readVulnerabilitiesJSON(vulnerabilitiesJSONPath);
77+
let shouldCommit = false;
78+
for (let i = 0; i < content.reports.length; ++i) {
79+
if (content.reports[i].announcement !== link) {
80+
content.reports[i].announcement = link;
81+
shouldCommit = true;
82+
}
83+
};
84+
85+
if (shouldCommit) {
86+
fs.writeFileSync(vulnerabilitiesJSONPath, JSON.stringify(content, null, 2));
87+
const commitMessage = 'chore: add announcement link';
88+
commitAndPushVulnerabilitiesJSON([vulnerabilitiesJSONPath],
89+
commitMessage, { cli: this.cli, repository: this.repository });
90+
91+
this.cli.ok('Updated the announcement link in vulnerabilities.json');
92+
}
93+
94+
return [vulnerabilitiesJSONPath];
6995
}
7096

7197
async createPostRelease(nodejsOrgFolder) {

0 commit comments

Comments
 (0)