Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetch template directly from nodejs/node #787

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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