diff --git a/scripts/update-codeowners.js b/scripts/update-codeowners.js index a4759a1bd9..e5b1d4d2e0 100644 --- a/scripts/update-codeowners.js +++ b/scripts/update-codeowners.js @@ -7,12 +7,12 @@ const { AllPackages, getDefinitelyTyped, loggerWithErrors, const { writeFile } = require("fs-extra"); async function main() { - const options = { definitelyTypedPath: "..", progress: false, parseInParallel: true }; + const options = { definitelyTypedPath: ".", progress: false, parseInParallel: true }; const log = loggerWithErrors()[0]; clean(); const dt = await getDefinitelyTyped(options, log); - await parseDefinitions(dt, { nProcesses: parseNProcesses(), definitelyTypedPath: ".." }, log); + await parseDefinitions(dt, { nProcesses: parseNProcesses(), definitelyTypedPath: "." }, log); const allPackages = await AllPackages.read(dt); const typings = allPackages.allTypings(); const maxPathLen = Math.max(...typings.map(t => t.subDirectoryPath.length)); @@ -20,12 +20,11 @@ async function main() { await writeFile([options.definitelyTypedPath, ".github", "CODEOWNERS"].join("/"), `${header}\n\n${entries.join("\n")}\n`, { encoding: "utf-8" }); } -const userName = process.env.GH_USERNAME; const token = process.env.GH_TOKEN; const reviewers = ["weswigham", "sandersn", "RyanCavanaugh"] const now = new Date(); const branchName = `codeowner-update-${now.getFullYear()}${padNum(now.getMonth())}${padNum(now.getDay())}`; -const remoteUrl = `https://${process.env.GH_TOKEN}@github.com/${userName}/DefinitelyTyped.git`; +const remoteUrl = `https://${process.env.GH_TOKEN}@github.com/DefinitelyTyped/DefinitelyTyped.git`; runSequence([ ["git", ["checkout", "."]], // reset any changes ]); @@ -43,6 +42,38 @@ runSequence([ ["git", ["push", "--set-upstream", "fork", branchName, "-f"]] // push the branch ]); +const gh = new Octokit(); +gh.authenticate({ + type: "token", + token: process.env.GH_TOKEN, +}); +gh.pulls.create({ + owner: "DefinitelyTyped", + repo: "DefinitelyTyped", + maintainer_can_modify: true, + title: `🤖 CODEOWNERS has changed`, + head: `${userName}:${branchName}`, + base: "master", + body: +`Please review the diff and merge if no changes are unexpected. + +cc ${reviewers.map(r => "@" + r).join(" ")}`, +}).then(r => { + const num = r.data.number; + console.log(`Pull request ${num} created.`); + return gh.pulls.createReviewRequest({ + owner: "DefinitelyTyped", + repo: "DefinitelyTyped", + number: num, + reviewers, + }); +}).then(() => { + console.log(`Reviewers requested, done.`); +}).catch(e => { + console.error(e); + process.exit(1); +}); + /** @param {[string, string[]][]} tasks */ function runSequence(tasks) { for (const task of tasks) { @@ -58,38 +89,6 @@ function padNum(number) { return str.length >= 2 ? str : "0" + str; } -const gh = new Octokit(); -gh.authenticate({ - type: "token", - token: process.env.GH_TOKEN, -}); -gh.pulls.create({ - owner: process.env.TARGET_FORK, - repo: "DefinitelyTyped", - maintainer_can_modify: true, - title: `🤖 Codeowners have changed`, - head: `${userName}:${branchName}`, - base: "master", - body: -`Please review the diff and merge if no changes are unexpected. - -cc ${reviewers.map(r => "@" + r).join(" ")}`, -}).then(r => { - const num = r.data.number; - console.log(`Pull request ${num} created.`); - return gh.pulls.createReviewRequest({ - owner: process.env.TARGET_FORK, - repo: "TypeScript", - number: num, - reviewers, - }); -}).then(() => { - console.log(`Reviewers requested, done.`); -}).catch(e => { - console.error(e); - process.exit(1); -}); - const header = `# This file is generated.