Skip to content

Commit

Permalink
feat: fetch template directly from nodejs/node (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Mar 25, 2024
1 parent b70e636 commit fbdd466
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 113 deletions.
98 changes: 0 additions & 98 deletions lib/github/templates/next-security-release.md

This file was deleted.

38 changes: 23 additions & 15 deletions lib/prepare_security.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
PLACEHOLDERS,
checkoutOnSecurityReleaseBranch,
commitAndPushVulnerabilitiesJSON,
getSummary
getSummary,
validateDate
} from './security-release/security-release.js';

export default class SecurityReleaseSteward {
Expand All @@ -29,7 +30,7 @@ export default class SecurityReleaseSteward {
const req = new Request(credentials);
const release = new PrepareSecurityRelease(req);
const releaseDate = await release.promptReleaseDate(cli);

validateDate(releaseDate);
const createVulnerabilitiesJSON = await release.promptVulnerabilitiesJSON(cli);

let securityReleasePRUrl;
Expand All @@ -40,7 +41,7 @@ export default class SecurityReleaseSteward {
const createIssue = await release.promptCreateRelaseIssue(cli);

if (createIssue) {
const { content } = release.buildIssue(releaseDate, securityReleasePRUrl);
const content = await release.buildIssue(releaseDate, securityReleasePRUrl);
await release.createIssue(content, { cli });
};

Expand Down Expand Up @@ -99,18 +100,25 @@ class PrepareSecurityRelease {
{ defaultAnswer: true });
}

getSecurityIssueTemplate() {
return fs.readFileSync(
new URL(
'./github/templates/next-security-release.md',
import.meta.url
),
'utf-8'
);
async getSecurityIssueTemplate() {
const url = 'https://raw.githubusercontent.com/nodejs/node/main/doc/contributing/security-release-process.md';
try {
// fetch document from nodejs/node main so we dont need to keep a copy
const response = await fetch(url);
const body = await response.text();
// remove everything before the Planning section
const index = body.indexOf('## Planning');
if (index !== -1) {
return body.substring(index);
}
return body;
} catch (error) {
this.cli.error(`Could not retrieve the security issue template from ${url}`);
}
}

async promptReleaseDate(cli) {
return cli.prompt('Enter target release date in YYYY-MM-DD format:', {
return cli.prompt('Enter target release date in YYYY/MM/DD format:', {
questionType: 'input',
defaultAnswer: 'TBD'
});
Expand All @@ -134,11 +142,11 @@ class PrepareSecurityRelease {
{ defaultAnswer: true });
}

buildIssue(releaseDate, securityReleasePRUrl = PLACEHOLDERS.vulnerabilitiesPRURL) {
const template = this.getSecurityIssueTemplate();
async buildIssue(releaseDate, securityReleasePRUrl = PLACEHOLDERS.vulnerabilitiesPRURL) {
const template = await this.getSecurityIssueTemplate();
const content = template.replace(PLACEHOLDERS.releaseDate, releaseDate)
.replace(PLACEHOLDERS.vulnerabilitiesPRURL, securityReleasePRUrl);
return { releaseDate, content, securityReleasePRUrl };
return content;
}

async createIssue(content, { cli }) {
Expand Down

0 comments on commit fbdd466

Please sign in to comment.