Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ function getBaseRefSha(
return baseRef.target.oid;
}

const isAlreadyExistingRefError = (error: unknown) =>
typeof error === "object" &&
error !== null &&
"status" in error &&
"message" in error &&
typeof error.status === "number" &&
typeof error.message === "string" &&
error.status === 422 &&
error.message.includes("Reference already exists");

const createCommit = async ({
function isAlreadyExistingRefError(error: unknown) {
return (
typeof error === "object" &&
error !== null &&
"status" in error &&
"message" in error &&
typeof error.status === "number" &&
typeof error.message === "string" &&
error.status === 422 &&
error.message.includes("Reference already exists")
);
}

async function createCommit({
octokit,
refId,
baseSha,
Expand All @@ -40,7 +43,7 @@ const createCommit = async ({
}: Pick<CommitFilesFromBase64Args, "octokit" | "message" | "fileChanges"> & {
refId: string;
baseSha: string;
}) => {
}) {
// we have to stick to GraphQL here as with REST, each file change would become a separate API call
return createCommitOnBranchQuery(octokit, {
input: {
Expand All @@ -52,9 +55,9 @@ const createCommit = async ({
fileChanges,
},
});
};
}

export const commitFilesFromBase64 = async ({
export async function commitFilesFromBase64({
octokit,
owner,
repo,
Expand All @@ -63,7 +66,7 @@ export const commitFilesFromBase64 = async ({
force = false,
message,
fileChanges,
}: CommitFilesFromBase64Args): Promise<CommitFilesResult> => {
}: CommitFilesFromBase64Args): Promise<CommitFilesResult> {
const baseRef = resolveGitRef(base);
const targetRef = `refs/heads/${branch}`;

Expand Down Expand Up @@ -225,4 +228,4 @@ export const commitFilesFromBase64 = async ({
return {
refId: newCommit.createCommitOnBranch?.ref?.id ?? null,
};
};
}
6 changes: 3 additions & 3 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import type {
} from "./interface.ts";
import { resolveGitRef } from "./utils.ts";

export const commitChangesFromRepo = async ({
export async function commitChangesFromRepo({
cwd: workingDirectory,
recursivelyFindRoot = true,
filterFiles,
...otherArgs
}: CommitChangesFromRepoArgs): Promise<CommitFilesResult> => {
}: CommitChangesFromRepoArgs): Promise<CommitFilesResult> {
const ref = resolveGitRef(otherArgs.base ?? { commit: "HEAD" });
const cwd = path.resolve(workingDirectory);
const repoRoot = recursivelyFindRoot ? await findGitRoot(cwd) : cwd;
Expand All @@ -36,7 +36,7 @@ export const commitChangesFromRepo = async ({
commit: refSha,
},
});
};
}

// Exported for testing only
export async function getFileChanges(
Expand Down