//#region src/github/graphql/generated/types.d.ts type Maybe = T | null; type InputMaybe = Maybe; /** All built-in and custom scalars, mapped to their actual values */ type Scalars = { ID: { input: string; output: string; }; String: { input: string; output: string; }; Boolean: { input: boolean; output: boolean; }; Int: { input: number; output: number; }; Float: { input: number; output: number; }; /** A (potentially binary) string encoded using base64. */ Base64String: { input: string; output: string; }; /** * Represents non-fractional signed whole numeric values. Since the value may * exceed the size of a 32-bit integer, it's encoded as a string. */ BigInt: { input: string; output: string; }; /** * A custom property value can be either a string or an array of strings. All * property types support only a single string value, except for the multi-select * type, which supports only a string array. */ CustomPropertyValue: { input: string; output: string; }; /** An ISO-8601 encoded date string. */ Date: { input: string; output: string; }; /** An ISO-8601 encoded UTC date string. */ DateTime: { input: string; output: string; }; /** A Git object ID. */ GitObjectID: { input: string; output: string; }; /** A fully qualified reference name (e.g. `refs/heads/master`). */ GitRefname: { input: string; output: string; }; /** Git SSH string */ GitSSHRemote: { input: string; output: string; }; /** An ISO-8601 encoded date string. Unlike the DateTime type, GitTimestamp is not converted in UTC. */ GitTimestamp: { input: string; output: string; }; /** A string containing HTML code. */ HTML: { input: string; output: string; }; /** An ISO-8601 encoded UTC date string with millisecond precision. */ PreciseDateTime: { input: string; output: string; }; /** An RFC 3986, RFC 3987, and RFC 6570 (level 4) compliant URI string. */ URI: { input: string; output: string; }; /** A valid x509 certificate string */ X509Certificate: { input: string; output: string; }; }; /** A message to include with a new commit */ type CommitMessage = { /** The body of the message. */body?: InputMaybe; /** The headline of the message. */ headline: Scalars['String']['input']; }; /** * A command to add a file at the given path with the given contents as part of a * commit. Any existing file at that that path will be replaced. */ type FileAddition = { /** The base64 encoded contents of the file */contents: Scalars['Base64String']['input']; /** The path in the repository where the file will be located */ path: Scalars['String']['input']; }; /** * A description of a set of changes to a file tree to be made as part of * a git commit, modeled as zero or more file `additions` and zero or more * file `deletions`. * * Both fields are optional; omitting both will produce a commit with no * file changes. * * `deletions` and `additions` describe changes to files identified * by their path in the git tree using unix-style path separators, i.e. * `/`. The root of a git tree is an empty string, so paths are not * slash-prefixed. * * `path` values must be unique across all `additions` and `deletions` * provided. Any duplication will result in a validation error. * * ### Encoding * * File contents must be provided in full for each `FileAddition`. * * The `contents` of a `FileAddition` must be encoded using RFC 4648 * compliant base64, i.e. correct padding is required and no characters * outside the standard alphabet may be used. Invalid base64 * encoding will be rejected with a validation error. * * The encoded contents may be binary. * * For text files, no assumptions are made about the character encoding of * the file contents (after base64 decoding). No charset transcoding or * line-ending normalization will be performed; it is the client's * responsibility to manage the character encoding of files they provide. * However, for maximum compatibility we recommend using UTF-8 encoding * and ensuring that all files in a repository use a consistent * line-ending convention (`\n` or `\r\n`), and that all files end * with a newline. * * ### Modeling file changes * * Each of the the five types of conceptual changes that can be made in a * git commit can be described using the `FileChanges` type as follows: * * 1. New file addition: create file `hello world\n` at path `docs/README.txt`: * * { * "additions" [ * { * "path": "docs/README.txt", * "contents": base64encode("hello world\n") * } * ] * } * * 2. Existing file modification: change existing `docs/README.txt` to have new * content `new content here\n`: * * { * "additions" [ * { * "path": "docs/README.txt", * "contents": base64encode("new content here\n") * } * ] * } * * 3. Existing file deletion: remove existing file `docs/README.txt`. * Note that the path is required to exist -- specifying a * path that does not exist on the given branch will abort the * commit and return an error. * * { * "deletions" [ * { * "path": "docs/README.txt" * } * ] * } * * * 4. File rename with no changes: rename `docs/README.txt` with * previous content `hello world\n` to the same content at * `newdocs/README.txt`: * * { * "deletions" [ * { * "path": "docs/README.txt", * } * ], * "additions" [ * { * "path": "newdocs/README.txt", * "contents": base64encode("hello world\n") * } * ] * } * * * 5. File rename with changes: rename `docs/README.txt` with * previous content `hello world\n` to a file at path * `newdocs/README.txt` with content `new contents\n`: * * { * "deletions" [ * { * "path": "docs/README.txt", * } * ], * "additions" [ * { * "path": "newdocs/README.txt", * "contents": base64encode("new contents\n") * } * ] * } */ type FileChanges = { /** File to add or change. */additions?: InputMaybe>; /** Files to delete. */ deletions?: InputMaybe>; }; /** A command to delete the file at the given path as part of a commit. */ type FileDeletion = { /** The path to delete */path: Scalars['String']['input']; }; //#endregion //#region src/github/graphql/queries.d.ts type Octokit = { graphql: (query: string, variables?: Record) => Promise; rest: { git: { createRef: (params: { owner: string; repo: string; ref: string; sha: string; }) => Promise<{ data: { node_id?: string; }; }>; updateRef: (params: { owner: string; repo: string; ref: string; sha: string; force?: boolean; }) => Promise<{ data: { node_id?: string; }; }>; deleteRef: (params: { owner: string; repo: string; ref: string; }) => Promise; getRef?: (params: { owner: string; repo: string; ref: string; }) => Promise; }; }; }; //#endregion //#region src/types.d.ts type GitRef = { branch: string; } | { tag: string; } | { commit: string; }; interface CommitChangesOptions { /** * The Octokit instance to use for making GitHub API requests. Requires APIs * from `@octokit/core`, `@octokit/plugin-rest-endpoint-methods`, and * `@octokit/plugin-paginate-rest`. */ octokit: Octokit; /** * The owner of the repository. */ owner: string; /** * The name of the repository. */ repo: string; /** * The name of the branch to commit to. */ branch: string; /** * The current branch, tag, or commit that the new branch should be based on. * * @example * { branch: "main" } * @example * { tag: "v1.0.0" } * @example * { commit: "abc123..." } */ base: GitRef; /** * The files that are added, modified, or deleted in the commit. Added and * modified files should be in the `additions` array with their content as * base64-encoded strings. Deleted files should be in the `deletions` array * with their file paths. * * @example * { * additions: [{ path: "file.txt", content: "SGVsbG8gd29ybGQ=" }] * deletions: ["old-file.txt"] * } */ fileChanges: FileChanges; /** * The commit message. If a string is passed, the first line will be used as * the headline, and the rest will be used as the body. An object can also be * passed to explicitly specify the headline and body. */ message: string | CommitMessage; /** * If the branch exists but its HEAD does not match the given base, the commit * cannot be created as their histories have diverged. If this is set to true, * the commit will be force pushed to the branch instead, overwriting any * existing commits. */ force?: boolean; } interface CommitChangesResult { /** * The ref id of the created or update branch. */ refId: string; } interface CommitChangesSinceBaseOptions extends Omit { /** * The base branch, tag, or commit to determine the changes since then. The * commit form additionally accepts `HEAD` (and similar ref shorthands) instead * of the full commit SHA. * * The default is `{ commit: "HEAD" }`, which includes all uncommitted changes * since the last commit. If previous commits have been made locally and not * pushed, you need to set to the last commit that is known to be in the * remote repository. * * If you want to base the changes on a different branch, tag, or commit to * the one checked out, make sure that you have pulled those refs from the * remote repository. * * @default { commit: "HEAD" } */ base?: GitRef; /** * The directory to execute git commands in. This can be set if the repository * is in a different directory. * * @default process.cwd() */ cwd?: string; /** * Filter the files to be included in the commit. The file paths are relative * to the repository root, e.g. `"src/index.ts"`. Return `true` to include * the file. * * By default, all files are included. */ filterFiles?: (file: string) => boolean; } //#endregion //#region src/core.d.ts /** * Commit file changes to a branch using the GitHub API. * * Works in Node.js and browsers. */ declare function commitChanges({ octokit, owner, repo, branch, base, force, message, fileChanges }: CommitChangesOptions): Promise; //#endregion export { GitRef as a, CommitChangesSinceBaseOptions as i, CommitChangesOptions as n, CommitMessage as o, CommitChangesResult as r, FileChanges as s, commitChanges as t };