@freephoenix888/find-and-replace-in-github-file
Version:
Find and replace text in github file
53 lines (52 loc) • 1.49 kB
TypeScript
import { Octokit } from '@octokit/rest';
/**
* Finds and replaces text in a file hosted on a GitHub repository.
*
* @example
* #### Find and replace text in a file hosted on a GitHub repository
* ```typescript
* const octokit = new Octokit({ auth: "your-github-token" });
* await findAndReplaceInGithubFile({
* octokit,
* owner: "username",
* repo: "repository",
* path: "path/to/file.txt",
* regex: /findMe/g,
* replacement: "replaceWithMe",
* commitMessage: "Replaced 'findMe' with 'replaceWithMe'"
* });
* ```
*
* @throws Will throw an error if any GitHub API request fails (except for 404 errors, which only log a warning).
*/
export declare function findAndReplaceInGithubFile(options: FindAndReplaceInGithubFileOptions): Promise<void>;
export interface FindAndReplaceInGithubFileOptions {
/**
* An instance of the Octokit client.
*/
octokit: Octokit;
/**
* GitHub username or organization that owns the repository.
*/
owner: string;
/**
* The name of the GitHub repository.
*/
repo: string;
/**
* The file path in the repository to find and replace text in.
*/
path: string;
/**
* The regular expression used to find the text to be replaced.
*/
regex: RegExp;
/**
* The text that will replace the text found using the `regex`.
*/
replacement: string;
/**
* The commit message for the changes.
*/
commitMessage: string;
}