Skip to content

fix: adjust --cleanup #901

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

Merged
merged 1 commit into from
Jan 23, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions lib/prepare_security.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,27 @@ export default class PrepareSecurityRelease extends SecurityRelease {
await this.closeAndRequestDisclosure(vulnerabilityJSON.reports);

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

const updateFolder = this.cli.prompt(
const updateFolder = await this.cli.prompt(
// eslint-disable-next-line max-len
`Would you like to update the next-security-release folder to ${vulnerabilityJSON.releaseDate}?`,
{ defaultAnswer: true });
if (updateFolder) {
const newFolder = this.updateReleaseFolder(vulnerabilityJSON.releaseDate);
this.updateReleaseFolder(
vulnerabilityJSON.releaseDate.replaceAll('/', '-')
);
const securityReleaseFolder = path.join(process.cwd(), 'security-release');
commitAndPushVulnerabilitiesJSON(
newFolder,
securityReleaseFolder,
'chore: change next-security-release folder',
{ cli: this.cli, repository: this.repository }
);
}
this.cli.info(`Merge pull request with:
- git checkout main
- git merge --squash ${NEXT_SECURITY_RELEASE_BRANCH}
- git merge ${NEXT_SECURITY_RELEASE_BRANCH} --no-ff -m "chore: add latest security release"
- git push origin main`);
this.cli.ok('Done!');
}
Expand Down Expand Up @@ -306,16 +309,17 @@ export default class PrepareSecurityRelease extends SecurityRelease {
labels = [labels];
}

const url = 'https://github.com/nodejs-private/node-private/pulls';
const url = 'https://github.com/nodejs-private/node-private/pull';
this.cli.startSpinner('Closing GitHub Pull Requests...');
// At this point, GitHub does not provide filters through their REST API
const prs = this.req.getPullRequest(url);
const prs = await this.req.getPullRequest(url);
for (const pr of prs) {
if (pr.labels.some((l) => labels.includes(l))) {
this.cli.updateSpinner(`Closing Pull Request: ${pr.id}`);
await this.req.closePullRequest(pr.id);
if (pr.labels.some((l) => labels.includes(l.name))) {
this.cli.updateSpinner(`Closing Pull Request: ${pr.number}`);
await this.req.closePullRequest(pr.number,
{ owner: 'nodejs-private', repo: 'node-private' });
}
}
this.cli.startSpinner('Closed GitHub Pull Requests.');
this.cli.stopSpinner('Closed GitHub Pull Requests.');
}
}
14 changes: 9 additions & 5 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,15 @@ export default class Request {
return this.json(url, options);
}

async closePullRequest({ owner, repo }) {
const url = `https://api.github.com/repos/${owner}/${repo}/pulls`;
async closePullRequest(id, { owner, repo }) {
const url = `https://api.github.com/repos/${owner}/${repo}/pulls/${id}`;
const options = {
method: 'POST',
headers: {
Authorization: `Basic ${this.credentials.github}`,
'User-Agent': 'node-core-utils',
Accept: 'application/vnd.github+json'
Accept: 'application/vnd.github+json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
state: 'closed'
Expand Down Expand Up @@ -230,7 +231,8 @@ export default class Request {
headers: {
Authorization: `Basic ${this.credentials.h1}`,
'User-Agent': 'node-core-utils',
Accept: 'application/json'
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
data: {
Expand All @@ -252,11 +254,13 @@ export default class Request {
headers: {
Authorization: `Basic ${this.credentials.h1}`,
'User-Agent': 'node-core-utils',
Accept: 'application/json'
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
data: {
attributes: {
message: 'Requesting disclosure',
// default to limited version
substate: 'no-content'
}
Expand Down
2 changes: 1 addition & 1 deletion lib/security-release/security-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class SecurityRelease {
updateReleaseFolder(releaseDate) {
const folder = path.join(process.cwd(),
NEXT_SECURITY_RELEASE_FOLDER);
const newFolder = path.join(process.cwd(), releaseDate);
const newFolder = path.join(process.cwd(), 'security-release', releaseDate);
fs.renameSync(folder, newFolder);
return newFolder;
}
Expand Down
Loading