Skip to content

Commit 7bbaf26

Browse files
committed
Remove APIs and group single entrypoint
1 parent 8b5585d commit 7bbaf26

12 files changed

Lines changed: 93 additions & 279 deletions

.changeset/humble-weeks-watch.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@changesets/ghcommit": major
3+
---
4+
5+
Removed the `commitFilesFromBuffers` and `commitFilesFromDirectory` APIs. These APIs were simple wrappers over the core `commitChangesFromBase64` API, which should be used instead. Read the file and pass the base64-encoded content to `commitChangesFromBase64` `fileChanges` directly. For example:
6+
7+
- `Buffer.from("hello world").toString("base64")`
8+
- `await fs.readFile("path/to/file", "base64")`

.changeset/slick-bottles-try.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@changesets/ghcommit": major
3+
---
4+
5+
Removed all subpath exports. All APIs should be imported from root, e.g. `import { commitChangesFromRepo } from "@changesets/ghcommit"`.

README.md

Lines changed: 60 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,14 @@ pnpm install @changesets/ghcommit
4040

4141
### Usage in github actions
4242

43-
All functions in this library that interact with the GitHub API require an octokit client that can execute GraphQL. If you are writing code that is designed to be run from within a GitHub Action, this can be done using the `@actions.github` library:
43+
All functions in this library that interact with the GitHub API require an octokit client that can execute GraphQL. If you are writing code that is designed to be run from within a GitHub Action, this can be done using the `@actions/github` library:
4444

4545
```ts
4646
import { getOctokit } from "@actions/github";
4747

4848
const octokit = getOctokit(process.env.GITHUB_TOKEN);
4949
```
5050

51-
### Importing specific modules
52-
53-
To allow for you to produce smaller bundle sizes, the functionality exposed in this package is grouped into specific modules that only import the packages required for their use. We recommend that you import from the specific modules rather than the root of the package.
54-
5551
## API
5652

5753
All the functions below accept a single object as its argument, and share the following base arguments:
@@ -77,8 +73,66 @@ All the functions below accept a single object as its argument, and share the fo
7773
}
7874
```
7975

76+
### `commitFilesFromBase64`
77+
78+
> Works in Node.js and browsers
79+
80+
This function will add or delete specific files from a repository's branch based on the given `fileChanges` argument.
81+
82+
In addition to `CommitFilesBasedArgs`, this function has the following arguments:
83+
84+
```ts
85+
{
86+
/**
87+
* The current branch, tag or commit that the new branch should be based on.
88+
*/
89+
base: GitBase;
90+
/**
91+
* The file paths, relative to git root, to add or delete from the branch on GitHub.
92+
*/
93+
fileChanges: {
94+
/**
95+
* File paths, relative to git root, to add to the repo. Content is a base64-encoded string.
96+
*/
97+
additions?: { path: string; content: string }[];
98+
/**
99+
* File paths, relative to git root, to remove from the repo.
100+
*/
101+
deletions?: { path: string }[];
102+
};
103+
}
104+
```
105+
106+
Example:
107+
108+
```ts
109+
import fs from "node:fs/promises";
110+
import { context, getOctokit } from "@actions/github";
111+
import { commitFilesFromBase64 } from "@changesets/ghcommit";
112+
113+
const octokit = getOctokit(process.env.GITHUB_TOKEN);
114+
115+
// Commit the changes to README.md based on the main branch
116+
await commitFilesFromBase64({
117+
octokit,
118+
...context.repo,
119+
branch: "new-branch-to-create",
120+
message: "[chore] do something",
121+
base: {
122+
branch: "main",
123+
},
124+
fileChanges: {
125+
additions: [
126+
{ path: "README.md", content: await fs.readFile("README.md", "base64") },
127+
],
128+
},
129+
});
130+
```
131+
80132
### `commitChangesFromRepo`
81133

134+
> Works in Node.js only
135+
82136
This function will take an existing repository on your filesystem (defaulting to the current working directory). This function is good to use if you're usually working within the context of a git repository, such as after running `@actions/checkout` in github actions.
83137

84138
In addition to `CommitFilesBasedArgs`, this function has the following arguments:
@@ -122,7 +176,7 @@ Example:
122176

123177
```ts
124178
import { context, getOctokit } from "@actions/github";
125-
import { commitChangesFromRepo } from "@changesets/ghcommit/git";
179+
import { commitChangesFromRepo } from "@changesets/ghcommit";
126180

127181
const octokit = getOctokit(process.env.GITHUB_TOKEN);
128182

@@ -166,130 +220,6 @@ await commitChangesFromRepo({
166220
});
167221
```
168222

169-
### `commitFilesFromDirectory`
170-
171-
This function will add or delete specific files from a repository's branch based on files found on the local filesystem. This is good to use when there are specific files that need to be updated on a branch, or if many changes may have been made locally, but only some files need to be pushed.
172-
173-
In addition to `CommitFilesBasedArgs`, this function has the following arguments:
174-
175-
```ts
176-
{
177-
/**
178-
* The current branch, tag or commit that the new branch should be based on.
179-
*/
180-
base: GitBase;
181-
/**
182-
* The directory to consider the root of the repository when calculating
183-
* file paths
184-
*/
185-
cwd: string;
186-
/**
187-
* The file paths, relative to {@link workingDirectory},
188-
* to add or delete from the branch on GitHub.
189-
*/
190-
fileChanges: {
191-
/** File paths, relative to {@link workingDirectory}, to remove from the repo. */
192-
additions?: string[];
193-
/** File paths, relative to the repository root, to remove from the repo. */
194-
deletions?: string[];
195-
};
196-
}
197-
```
198-
199-
Example:
200-
201-
```ts
202-
import { context, getOctokit } from "@actions/github";
203-
import { commitFilesFromDirectory } from "@changesets/ghcommit/fs";
204-
205-
const octokit = getOctokit(process.env.GITHUB_TOKEN);
206-
207-
// Commit the changes to package.json and package-lock.json
208-
// based on the main branch
209-
await commitFilesFromDirectory({
210-
octokit,
211-
...context.repo,
212-
branch: "new-branch-to-create",
213-
message: "[chore] do something",
214-
base: {
215-
branch: "main",
216-
},
217-
cwd: "foo/bar",
218-
fileChanges: {
219-
additions: ["package-lock.json", "package.json"],
220-
},
221-
});
222-
223-
// Push just the index.html file to a new branch called docs, based off the tag v1.0.0
224-
await commitFilesFromDirectory({
225-
octokit,
226-
...context.repo,
227-
branch: "docs",
228-
message: "[chore] do something",
229-
force: true, // Overwrite any existing branch
230-
base: {
231-
tag: "v1.0.0",
232-
},
233-
cwd: "some-dir",
234-
fileChanges: {
235-
additions: ["index.html"],
236-
},
237-
});
238-
```
239-
240-
### `commitFilesFromBuffers`
241-
242-
This function will add or delete specific files from a repository's branch based on Node.js `Buffers` that can be any binary data in memory. This is useful for when you want to make changes to a repository / branch without cloning a repo or interacting with a filesystem.
243-
244-
In addition to `CommitFilesBasedArgs`, this function has the following arguments:
245-
246-
```ts
247-
{
248-
/**
249-
* The current branch, tag or commit that the new branch should be based on.
250-
*/
251-
base: GitBase;
252-
/**
253-
* The file changes, relative to the repository root, to make to the specified branch.
254-
*/
255-
fileChanges: {
256-
additions?: Array<{
257-
path: string;
258-
contents: Buffer;
259-
}>;
260-
deletions?: string[];
261-
};
262-
}
263-
```
264-
265-
Example:
266-
267-
```ts
268-
import { context, getOctokit } from "@actions/github";
269-
import { commitFilesFromBuffers } from "@changesets/ghcommit/node";
270-
271-
const octokit = getOctokit(process.env.GITHUB_TOKEN);
272-
273-
// Add a file called hello-world
274-
await commitFilesFromBuffers({
275-
octokit,
276-
...context.repo,
277-
branch: "new-branch-to-create",
278-
message: "[chore] do something",
279-
base: {
280-
branch: "main",
281-
},
282-
fileChanges: {
283-
additions: [
284-
{
285-
path: "hello/world.txt",
286-
contents: Buffer.alloc(1024, "Hello, world!"),
287-
},
288-
],
289-
},
290-
});
291-
```
292-
293223
## Known Limitations
294224

295225
Due to using the GitHub API to make changes to repository contents,

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
"type": "module",
2424
"sideEffects": false,
2525
"exports": {
26-
".": "./dist/index.mjs",
27-
"./core": "./dist/core.mjs",
28-
"./fs": "./dist/fs.mjs",
29-
"./git": "./dist/git.mjs",
30-
"./node": "./dist/node.mjs",
26+
".": {
27+
"types": "./dist/index-node.d.mts",
28+
"workerd": "./dist/index-node.mjs",
29+
"browser": "./dist/index-browser.mjs",
30+
"default": "./dist/index-node.mjs"
31+
},
3132
"./package.json": "./package.json"
3233
},
3334
"publishConfig": {

src/fs.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/index-browser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { commitFilesFromBase64 } from "./core.ts";
2+
3+
export function commitChangesFromRepo() {
4+
throw new Error("commitChangesFromRepo is not supported in the browser");
5+
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export { commitFilesFromBase64 } from "./core.ts";
22
export { commitChangesFromRepo } from "./git.ts";
3-
export { commitFilesFromDirectory } from "./fs.ts";

src/interface.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,6 @@ export interface CommitFilesFromBase64Args extends CommitFilesSharedArgsWithBase
4848
fileChanges: FileChanges;
4949
}
5050

51-
export interface CommitFilesFromBuffersArgs extends CommitFilesSharedArgsWithBase {
52-
/**
53-
* The file changes, relative to the repository root, to make to the specified branch.
54-
*/
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-
cwd: string;
70-
/**
71-
* The file paths, relative to {@link cwd},
72-
* to add or delete from the branch on GitHub.
73-
*/
74-
fileChanges: {
75-
/** File paths, relative to {@link cwd}, 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-
8251
export interface CommitChangesFromRepoArgs extends CommitFilesBasedArgs {
8352
/**
8453
* The directory used to find the repository root,

src/node.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)