const { execSync } = require('child_process'); const { Octokit } = require('@octokit/rest'); const repos = [ { name: 'repo1', branch: 'main' }, { name: 'repo2', branch: 'develop' }, // add more repositories and branches as needed ]; const octokit = new Octokit({ auth: 'PERSONAL_ACCESS_TOKEN', baseUrl: 'https://github.mycompany.com/api/v3', }); async function removeSensitiveFiles() { for (const { name, branch } of repos) { const localDir = `/tmp/${name}`; // clone the repository to a local directory execSync(`git clone git@github.mycompany.com:${name}.git ${localDir}`); // create a new branch named "feature/remove-ban-sensitive-files" from given branch name execSync(`cd ${localDir} && git checkout ${branch} && git checkout -b feature/remove-ban-sensitive-files`); // remove the "ban-sensitive-files" module from the dev dependencies of the package.json file const packageJsonPath = `${localDir}/package.json`; const packageJson = require(packageJsonPath); delete packageJson.devDependencies['ban-sensitive-files']; require('fs').writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); // rebuild the package-lock.json file execSync(`cd ${localDir} && npm install`); // commit the changes to the new branch and push them to the remote repository execSync(`cd ${localDir} && git add package.json package-lock.json && git commit -m "Remove ban-sensitive-files module from dev dependencies" && git push -u origin feature/remove-ban-sensitive-files`); // create a pull request with the title "Remove ban-sensitive-files module from dev dependencies" and a message detailing the changes made. const { data: pr } = await octokit.pulls.create({ owner: 'mycompany', repo: name, title: 'Remove ban-sensitive-files module from dev dependencies', head: 'feature/remove-ban-sensitive-files', base: branch, body: 'This pull request removes the ban-sensitive-files module from the dev dependencies of the package.json file.', }); console.log(`Pull request created for ${name}: ${pr.html_url}`); } } removeSensitiveFiles().catch((err) => { console.error(err); process.exit(1); });