Skip to content

Commit 5b7d58b

Browse files
committed
Clean up interfaces & arguments
1 parent 8dbb0b1 commit 5b7d58b

File tree

6 files changed

+108
-92
lines changed

6 files changed

+108
-92
lines changed

src/core.ts

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,18 @@
1-
import type {
2-
CommitMessage,
3-
FileChanges,
4-
} from "./github/graphql/generated/types.js";
51
import {
62
createCommitOnBranchQuery,
73
createRefMutation,
84
getRepositoryMetadata,
9-
GitHubClient,
105
updateRefMutation,
116
} from "./github/graphql/queries.js";
127
import type {
138
CreateCommitOnBranchMutationVariables,
149
GetRepositoryMetadataQuery,
1510
} from "./github/graphql/generated/operations.js";
16-
import type { Logger } from "./logging.js";
17-
18-
export type CommitFilesResult = {
19-
refId: string | null;
20-
};
21-
22-
export type GitBase =
23-
| {
24-
branch: string;
25-
}
26-
| {
27-
tag: string;
28-
}
29-
| {
30-
commit: string;
31-
};
32-
33-
export type CommitFilesFromBase64Args = {
34-
octokit: GitHubClient;
35-
owner: string;
36-
repository: string;
37-
branch: string;
38-
/**
39-
* The current branch, tag or commit that the new branch should be based on.
40-
*/
41-
base: GitBase;
42-
/**
43-
* Push the commit even if the branch exists and does not match what was
44-
* specified as the base.
45-
*/
46-
force?: boolean;
47-
/**
48-
* The commit message
49-
*/
50-
message: CommitMessage;
51-
fileChanges: FileChanges;
52-
log?: Logger;
53-
};
11+
import {
12+
CommitFilesFromBase64Args,
13+
CommitFilesResult,
14+
GitBase,
15+
} from "./interface.js";
5416

5517
const getBaseRef = (base: GitBase): string => {
5618
if ("branch" in base) {

src/fs.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
import { promises as fs } from "fs";
22
import * as path from "path";
33
import type { FileAddition } from "./github/graphql/generated/types.js";
4-
import { CommitFilesFromBase64Args, CommitFilesResult } from "./core.js";
54
import { commitFilesFromBuffers } from "./node.js";
6-
7-
export type CommitFilesFromDirectoryArgs = Omit<
8-
CommitFilesFromBase64Args,
9-
"fileChanges"
10-
> & {
11-
/**
12-
* The directory to consider the root of the repository when calculating
13-
* file paths
14-
*/
15-
workingDirectory?: string;
16-
fileChanges: {
17-
additions?: string[];
18-
deletions?: string[];
19-
};
20-
};
5+
import {
6+
CommitFilesFromDirectoryArgs,
7+
CommitFilesResult,
8+
} from "./interface.js";
219

2210
export const commitFilesFromDirectory = async ({
2311
workingDirectory = process.cwd(),

src/git.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
import { promises as fs } from "fs";
22
import git from "isomorphic-git";
3-
import { CommitFilesFromBase64Args } from "./core";
4-
import { commitFilesFromBuffers, CommitFilesFromBuffersArgs } from "./node";
5-
6-
export type CommitChangesFromRepoArgs = Omit<
7-
CommitFilesFromBase64Args,
8-
"fileChanges" | "base"
9-
> & {
10-
/**
11-
* The root of the repository.
12-
*
13-
* @default process.cwd()
14-
*/
15-
repoDirectory?: string;
16-
};
3+
import { commitFilesFromBuffers } from "./node";
4+
import {
5+
CommitChangesFromRepoArgs,
6+
CommitFilesFromBuffersArgs,
7+
CommitFilesResult,
8+
} from "./interface";
179

1810
export const commitChangesFromRepo = async ({
1911
repoDirectory = process.cwd(),
2012
log,
2113
...otherArgs
22-
}: CommitChangesFromRepoArgs) => {
14+
}: CommitChangesFromRepoArgs): Promise<CommitFilesResult> => {
2315
const gitLog = await git.log({
2416
fs,
2517
dir: repoDirectory,

src/interface.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import type {
2+
CommitMessage,
3+
FileChanges,
4+
} from "./github/graphql/generated/types.js";
5+
import type { GitHubClient } from "./github/graphql/queries.js";
6+
7+
import type { Logger } from "./logging.js";
8+
9+
export type CommitFilesResult = {
10+
refId: string | null;
11+
};
12+
13+
export type GitBase =
14+
| {
15+
branch: string;
16+
}
17+
| {
18+
tag: string;
19+
}
20+
| {
21+
commit: string;
22+
};
23+
24+
export interface CommitFilesBasedArgs {
25+
octokit: GitHubClient;
26+
owner: string;
27+
repository: string;
28+
branch: string;
29+
/**
30+
* Push the commit even if the branch exists and does not match what was
31+
* specified as the base.
32+
*/
33+
force?: boolean;
34+
/**
35+
* The commit message
36+
*/
37+
message: CommitMessage;
38+
log?: Logger;
39+
}
40+
41+
export interface CommitFilesSharedArgsWithBase extends CommitFilesBasedArgs {
42+
/**
43+
* The current branch, tag or commit that the new branch should be based on.
44+
*/
45+
base: GitBase;
46+
}
47+
48+
export interface CommitFilesFromBase64Args
49+
extends CommitFilesSharedArgsWithBase {
50+
fileChanges: FileChanges;
51+
}
52+
53+
export interface CommitFilesFromBuffersArgs
54+
extends CommitFilesSharedArgsWithBase {
55+
fileChanges: {
56+
additions?: Array<{
57+
path: string;
58+
contents: Buffer;
59+
}>;
60+
deletions?: string[];
61+
};
62+
}
63+
64+
export interface CommitFilesFromDirectoryArgs extends CommitFilesSharedArgsWithBase {
65+
/**
66+
* The directory to consider the root of the repository when calculating
67+
* file paths
68+
*/
69+
workingDirectory?: string;
70+
/**
71+
* The file paths, relative to {@link workingDirectory},
72+
* to add or delete from the branch on GitHub.
73+
*/
74+
fileChanges: {
75+
/** File paths, relative to {@link workingDirectory}, to remove from the repo. */
76+
additions?: string[];
77+
/** File paths, relative to the repository root, to remove from the repo. */
78+
deletions?: string[];
79+
};
80+
}
81+
82+
export interface CommitChangesFromRepoArgs extends CommitFilesBasedArgs {
83+
/**
84+
* The root of the repository.
85+
*
86+
* @default process.cwd()
87+
*/
88+
repoDirectory?: string;
89+
}

src/node.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
import {
2-
commitFilesFromBase64,
3-
CommitFilesFromBase64Args,
4-
CommitFilesResult,
5-
} from "./core.js";
6-
7-
export type CommitFilesFromBuffersArgs = Omit<
8-
CommitFilesFromBase64Args,
9-
"fileChanges"
10-
> & {
11-
fileChanges: {
12-
additions?: Array<{
13-
path: string;
14-
contents: Buffer;
15-
}>;
16-
deletions?: string[];
17-
};
18-
};
1+
import { commitFilesFromBase64 } from "./core.js";
2+
import { CommitFilesFromBuffersArgs, CommitFilesResult } from "./interface.js";
193

204
export const commitFilesFromBuffers = async ({
215
fileChanges,

tsup.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default defineConfig({
66
"src/core.ts",
77
"src/git.ts",
88
"src/fs.ts",
9+
"src/interfaces.ts",
910
"src/node.ts",
1011
],
1112
format: ["cjs", "esm"],

0 commit comments

Comments
 (0)