Skip to content

Commit 169b8fa

Browse files
authored
Refactor const to functions (#114)
1 parent d4764fd commit 169b8fa

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

src/core.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ function getBaseRefSha(
2121
return baseRef.target.oid;
2222
}
2323

24-
const isAlreadyExistingRefError = (error: unknown) =>
25-
typeof error === "object" &&
26-
error !== null &&
27-
"status" in error &&
28-
"message" in error &&
29-
typeof error.status === "number" &&
30-
typeof error.message === "string" &&
31-
error.status === 422 &&
32-
error.message.includes("Reference already exists");
33-
34-
const createCommit = async ({
24+
function isAlreadyExistingRefError(error: unknown) {
25+
return (
26+
typeof error === "object" &&
27+
error !== null &&
28+
"status" in error &&
29+
"message" in error &&
30+
typeof error.status === "number" &&
31+
typeof error.message === "string" &&
32+
error.status === 422 &&
33+
error.message.includes("Reference already exists")
34+
);
35+
}
36+
37+
async function createCommit({
3538
octokit,
3639
refId,
3740
baseSha,
@@ -40,7 +43,7 @@ const createCommit = async ({
4043
}: Pick<CommitFilesFromBase64Args, "octokit" | "message" | "fileChanges"> & {
4144
refId: string;
4245
baseSha: string;
43-
}) => {
46+
}) {
4447
// we have to stick to GraphQL here as with REST, each file change would become a separate API call
4548
return createCommitOnBranchQuery(octokit, {
4649
input: {
@@ -52,9 +55,9 @@ const createCommit = async ({
5255
fileChanges,
5356
},
5457
});
55-
};
58+
}
5659

57-
export const commitFilesFromBase64 = async ({
60+
export async function commitFilesFromBase64({
5861
octokit,
5962
owner,
6063
repo,
@@ -63,7 +66,7 @@ export const commitFilesFromBase64 = async ({
6366
force = false,
6467
message,
6568
fileChanges,
66-
}: CommitFilesFromBase64Args): Promise<CommitFilesResult> => {
69+
}: CommitFilesFromBase64Args): Promise<CommitFilesResult> {
6770
const baseRef = resolveGitRef(base);
6871
const targetRef = `refs/heads/${branch}`;
6972

@@ -225,4 +228,4 @@ export const commitFilesFromBase64 = async ({
225228
return {
226229
refId: newCommit.createCommitOnBranch?.ref?.id ?? null,
227230
};
228-
};
231+
}

src/git.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import type {
99
} from "./interface.ts";
1010
import { resolveGitRef } from "./utils.ts";
1111

12-
export const commitChangesFromRepo = async ({
12+
export async function commitChangesFromRepo({
1313
cwd: workingDirectory,
1414
recursivelyFindRoot = true,
1515
filterFiles,
1616
...otherArgs
17-
}: CommitChangesFromRepoArgs): Promise<CommitFilesResult> => {
17+
}: CommitChangesFromRepoArgs): Promise<CommitFilesResult> {
1818
const ref = resolveGitRef(otherArgs.base ?? { commit: "HEAD" });
1919
const cwd = path.resolve(workingDirectory);
2020
const repoRoot = recursivelyFindRoot ? await findGitRoot(cwd) : cwd;
@@ -36,7 +36,7 @@ export const commitChangesFromRepo = async ({
3636
commit: refSha,
3737
},
3838
});
39-
};
39+
}
4040

4141
// Exported for testing only
4242
export async function getFileChanges(

0 commit comments

Comments
 (0)