Last active
March 17, 2023 12:27
-
-
Save OmkarKirpan/c7ca9618e3fe56846ffd8b153db62485 to your computer and use it in GitHub Desktop.
an automation javacript script that removes the "ban-sensitive-files" module from the dev dependencies of microservices hosted on GitHub Enterprise Server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: ${pr.html_url}`); | |
| } | |
| } | |
| removeSensitiveFiles(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "remove-ban-sensitive-files", | |
| "version": "1.0.0", | |
| "description": "A script that removes the ban-sensitive-files module from the dev dependencies of microservices hosted on GitHub Enterprise Server.", | |
| "main": "index.js", | |
| "scripts": { | |
| "start": "node index.js" | |
| }, | |
| "dependencies": { | |
| "@octokit/rest": "^18.0.5" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment