Skip to content

Commit 3cb5255

Browse files
authored
fix(git-node): adjust security --cleanup (#901)
Those bugs I found while doing the last security release. I can confirm this patch fixes it.
1 parent cce9b81 commit 3cb5255

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

lib/prepare_security.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,27 @@ export default class PrepareSecurityRelease extends SecurityRelease {
5252
await this.closeAndRequestDisclosure(vulnerabilityJSON.reports);
5353

5454
this.cli.info('Closing pull requests');
55-
// For now, close the ones with vN.x label
56-
await this.closePRWithLabel(this.getAffectedVersions(vulnerabilityJSON));
55+
// For now, close the ones with Security Release label
56+
await this.closePRWithLabel('Security Release');
5757

58-
const updateFolder = this.cli.prompt(
58+
const updateFolder = await this.cli.prompt(
5959
// eslint-disable-next-line max-len
6060
`Would you like to update the next-security-release folder to ${vulnerabilityJSON.releaseDate}?`,
6161
{ defaultAnswer: true });
6262
if (updateFolder) {
63-
const newFolder = this.updateReleaseFolder(vulnerabilityJSON.releaseDate);
63+
this.updateReleaseFolder(
64+
vulnerabilityJSON.releaseDate.replaceAll('/', '-')
65+
);
66+
const securityReleaseFolder = path.join(process.cwd(), 'security-release');
6467
commitAndPushVulnerabilitiesJSON(
65-
newFolder,
68+
securityReleaseFolder,
6669
'chore: change next-security-release folder',
6770
{ cli: this.cli, repository: this.repository }
6871
);
6972
}
7073
this.cli.info(`Merge pull request with:
7174
- git checkout main
72-
- git merge --squash ${NEXT_SECURITY_RELEASE_BRANCH}
75+
- git merge ${NEXT_SECURITY_RELEASE_BRANCH} --no-ff -m "chore: add latest security release"
7376
- git push origin main`);
7477
this.cli.ok('Done!');
7578
}
@@ -306,16 +309,17 @@ export default class PrepareSecurityRelease extends SecurityRelease {
306309
labels = [labels];
307310
}
308311

309-
const url = 'https://github.com/nodejs-private/node-private/pulls';
312+
const url = 'https://github.com/nodejs-private/node-private/pull';
310313
this.cli.startSpinner('Closing GitHub Pull Requests...');
311314
// At this point, GitHub does not provide filters through their REST API
312-
const prs = this.req.getPullRequest(url);
315+
const prs = await this.req.getPullRequest(url);
313316
for (const pr of prs) {
314-
if (pr.labels.some((l) => labels.includes(l))) {
315-
this.cli.updateSpinner(`Closing Pull Request: ${pr.id}`);
316-
await this.req.closePullRequest(pr.id);
317+
if (pr.labels.some((l) => labels.includes(l.name))) {
318+
this.cli.updateSpinner(`Closing Pull Request: ${pr.number}`);
319+
await this.req.closePullRequest(pr.number,
320+
{ owner: 'nodejs-private', repo: 'node-private' });
317321
}
318322
}
319-
this.cli.startSpinner('Closed GitHub Pull Requests.');
323+
this.cli.stopSpinner('Closed GitHub Pull Requests.');
320324
}
321325
}

lib/request.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,15 @@ export default class Request {
109109
return this.json(url, options);
110110
}
111111

112-
async closePullRequest({ owner, repo }) {
113-
const url = `https://api.github.com/repos/${owner}/${repo}/pulls`;
112+
async closePullRequest(id, { owner, repo }) {
113+
const url = `https://api.github.com/repos/${owner}/${repo}/pulls/${id}`;
114114
const options = {
115115
method: 'POST',
116116
headers: {
117117
Authorization: `Basic ${this.credentials.github}`,
118118
'User-Agent': 'node-core-utils',
119-
Accept: 'application/vnd.github+json'
119+
Accept: 'application/vnd.github+json',
120+
'Content-Type': 'application/json'
120121
},
121122
body: JSON.stringify({
122123
state: 'closed'
@@ -230,7 +231,8 @@ export default class Request {
230231
headers: {
231232
Authorization: `Basic ${this.credentials.h1}`,
232233
'User-Agent': 'node-core-utils',
233-
Accept: 'application/json'
234+
Accept: 'application/json',
235+
'Content-Type': 'application/json'
234236
},
235237
body: JSON.stringify({
236238
data: {
@@ -252,11 +254,13 @@ export default class Request {
252254
headers: {
253255
Authorization: `Basic ${this.credentials.h1}`,
254256
'User-Agent': 'node-core-utils',
255-
Accept: 'application/json'
257+
Accept: 'application/json',
258+
'Content-Type': 'application/json'
256259
},
257260
body: JSON.stringify({
258261
data: {
259262
attributes: {
263+
message: 'Requesting disclosure',
260264
// default to limited version
261265
substate: 'no-content'
262266
}

lib/security-release/security-release.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export class SecurityRelease {
236236
updateReleaseFolder(releaseDate) {
237237
const folder = path.join(process.cwd(),
238238
NEXT_SECURITY_RELEASE_FOLDER);
239-
const newFolder = path.join(process.cwd(), releaseDate);
239+
const newFolder = path.join(process.cwd(), 'security-release', releaseDate);
240240
fs.renameSync(folder, newFolder);
241241
return newFolder;
242242
}

0 commit comments

Comments
 (0)