@freephoenix888/find-and-replace-in-github-file-in-all-repositories
Version:
Find and replace text in github file in all repositories
37 lines (36 loc) • 1.26 kB
JavaScript
import { findAndReplaceInGithubFile } from '@freephoenix888/find-and-replace-in-github-file';
import debug from 'debug';
import delay from 'delay';
const log = debug('find-and-replace-in-github-file-in-all-repositories');
/**
* Finds and replaces text in a specific file across all repositories of a GitHub user.
*
* @example
* #### Find and replace text in a file in all repositories
```ts
const octokit = new Octokit({ auth: 'YOUR_PERSONAL_ACCESS_TOKEN' });
await findAndReplaceInAllRepositories({
octokit,
owner: 'username',
path: 'path/to/file.txt',
regex: /findMe/g,
replacement: 'replaceWithMe',
commitMessage: "Replaced 'findMe' with 'replaceWithMe'"
})
```
*/
export async function findAndReplaceInAllRepositories(options) {
const { octokit, owner, onError = (error) => { throw error; }, delayInMs = 500 } = options;
log({ options });
for await (const response of octokit.paginate.iterator(octokit.rest.repos.listForUser, {
username: owner,
per_page: 100
})) {
log({ response });
for (const repo of response.data) {
log({ repo });
await findAndReplaceInGithubFile({ ...options, repo: repo.name }).catch(onError);
await delay(delayInMs);
}
}
}