@theholocron/github-client 1.58.0-alpha.10 → 1.58.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -32,6 +32,11 @@ await client.topics.setTopics("owner/name", ["cli", "nodejs"]);
32
32
  // Git plumbing (blobs, trees, commits, refs, PRs)
33
33
  const ref = await client.git.getRef("owner/name", "main");
34
34
  const blob = await client.git.createBlob("owner/name", "file contents");
35
+
36
+ // List a directory; a 404 is an empty list. `recursive` descends into nested directories
37
+ // (one request each) and returns a flat list of full paths.
38
+ const entries = await client.git.listDirectory("owner/name", ".holocron", { recursive: true });
39
+ // [{ name, path, type: "file" | "dir" | "symlink" | "submodule", size, sha }]
35
40
  ```
36
41
 
37
42
  ## Namespaces
@@ -50,7 +55,7 @@ const blob = await client.git.createBlob("owner/name", "file contents");
50
55
  | `labels` | `listLabels`, `createLabel`, `updateLabel`, `deleteLabel` |
51
56
  | `topics` | `setTopics` |
52
57
  | `properties` | `setProperties` |
53
- | `git` | `getRef`, `getCommit`, `getTree`, `getContents`, `putContents`, `createBlob`, `createTree`, `createCommit`, `createRef`, `updateRef`, `createPull` |
58
+ | `git` | `getRef`, `getCommit`, `getTree`, `getContents`, `listDirectory`, `putContents`, `createBlob`, `createTree`, `createCommit`, `createRef`, `updateRef`, `createPull` |
54
59
  | `checks` | `createCheckRun` |
55
60
 
56
61
  GitHub accepts at most 50 annotations per check-run request. Slice with the
package/dist/index.d.mts CHANGED
@@ -209,6 +209,26 @@ interface GitContents {
209
209
  /** The file's path in the repository. */
210
210
  path: string;
211
211
  }
212
+ /** One entry of a directory listing from the contents API. */
213
+ interface GitDirectoryEntry {
214
+ /** The entry's name, without its directory. */
215
+ name: string;
216
+ /** The entry's path from the repository root, e.g. `.holocron/notifications.ts`. */
217
+ path: string;
218
+ /** What the entry is; `dir` entries are listed, and descended into only when `recursive` is set. */
219
+ type: "file" | "dir" | "symlink" | "submodule";
220
+ /** The size in bytes; GitHub reports `0` for directories and submodules. */
221
+ size: number;
222
+ /** The entry's object SHA. */
223
+ sha: string;
224
+ }
225
+ /** Options for `listDirectory()`. */
226
+ interface ListDirectoryOptions {
227
+ /** A branch, tag or commit SHA; defaults to the repo's default branch. */
228
+ ref?: string;
229
+ /** Also list the contents of every nested directory, as one flat list of full paths. Defaults to `false`. */
230
+ recursive?: boolean;
231
+ }
212
232
  /** What `git.putContents` returns: the file's new blob sha (the `sha` to pass next time) and the commit it made. */
213
233
  interface PutContentsResult {
214
234
  /** The file written: its path and its new blob SHA. */
@@ -848,6 +868,7 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
848
868
  getCommit: (repo: string, sha: string) => Promise<GitCommit>;
849
869
  getTree: (repo: string, sha: string, recursive?: boolean) => Promise<GitTree>;
850
870
  getContents: (repo: string, path: string, ref?: string) => Promise<GitContents>;
871
+ listDirectory: (repo: string, path: string, options?: ListDirectoryOptions) => Promise<GitDirectoryEntry[]>;
851
872
  putContents: (repo: string, path: string, input: PutContentsInput) => Promise<PutContentsResult>;
852
873
  createBlob: (repo: string, content: string, encoding?: string) => Promise<GitBlob>;
853
874
  createTree: (repo: string, tree: Array<{
@@ -964,4 +985,4 @@ export declare function createGitHubClient(opts: GitHubClientOptions): {
964
985
  };
965
986
  /** The client returned by `createGitHubClient()`: one group of methods per GitHub API area. */
966
987
  export type GitHubClient = ReturnType<typeof createGitHubClient>;
967
- export type { CheckRunAnnotation, CheckRunAnnotationLevel, CheckRunConclusion, CheckRunOutput, CheckRunStatus, CodeScanningSetupResult, CreateCheckRunInput, CreatePagesPayload, CreatePullInput, CreateReviewComment, CreateReviewInput, GitBlob, GitCommit, GitContents, GitHubAppCredentials, GitHubCheckRun, GitHubClientOptions, GitHubContents, GitHubEnvironment, GitHubInstallationWebhookPayload, GitHubIssue, GitHubLabel, GitHubMilestone, GitHubPages, GitHubPublicKey, GitHubPullRequest, GitHubPullRequestCommit, GitHubPullRequestFile, GitHubPullRequestReview, GitHubPullRequestWebhookPayload, GitHubPushWebhookPayload, GitHubRepo, GitHubRuleset, GitHubRulesetDetail, GitHubUser, GitHubUserWithExpiry, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, GraphQLClient, InstallationAccessToken, IssueSearchParams, OrgProperty, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, RepoPropertyValue, RepoTeam, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdatePagesPayload, VariableScope, VariableVisibility, WorkflowRunFilter };
988
+ export type { CheckRunAnnotation, CheckRunAnnotationLevel, CheckRunConclusion, CheckRunOutput, CheckRunStatus, CodeScanningSetupResult, CreateCheckRunInput, CreatePagesPayload, CreatePullInput, CreateReviewComment, CreateReviewInput, GitBlob, GitCommit, GitContents, GitDirectoryEntry, GitHubAppCredentials, GitHubCheckRun, GitHubClientOptions, GitHubContents, GitHubEnvironment, GitHubInstallationWebhookPayload, GitHubIssue, GitHubLabel, GitHubMilestone, GitHubPages, GitHubPublicKey, GitHubPullRequest, GitHubPullRequestCommit, GitHubPullRequestFile, GitHubPullRequestReview, GitHubPullRequestWebhookPayload, GitHubPushWebhookPayload, GitHubRepo, GitHubRuleset, GitHubRulesetDetail, GitHubUser, GitHubUserWithExpiry, GitHubVariable, GitHubWebhookHeaders, GitHubWorkflowRun, GitPull, GitRef, GitTree, GitTreeItem, GraphQLClient, InstallationAccessToken, IssueSearchParams, ListDirectoryOptions, OrgProperty, PagesBuildStatus, PagesBuildType, PutContentsInput, PutContentsResult, RepoPropertyValue, RepoTeam, ReviewThread, SecretScope, TeamMember, TeamPermission, UpdateCheckRunInput, UpdatePagesPayload, VariableScope, VariableVisibility, WorkflowRunFilter };
package/dist/index.mjs CHANGED
@@ -150,6 +150,36 @@ function git(rest) {
150
150
  */
151
151
  getContents: (repo, path, ref) => rest.request(`${repoBase(repo)}/contents/${path}`, ref ? { query: { ref } } : void 0),
152
152
  /**
153
+ * Lists the directory at `path` through the contents API (`GET /repos/:repo/contents/:path`, which
154
+ * answers an array for a directory). A 404 (no such directory) is an empty list, not an error; any
155
+ * other failure is the usual `ProviderApiError`. One request lists one level: with
156
+ * `recursive: true` it makes one more request per nested directory and returns a flat list of
157
+ * full paths (directories included). A `path` that is a file, not a directory, throws.
158
+ */
159
+ listDirectory: async (repo, path, options = {}) => {
160
+ const list = async (at) => {
161
+ let body;
162
+ try {
163
+ body = await rest.request(`${repoBase(repo)}/contents/${filePath(at)}`, options.ref ? { query: { ref: options.ref } } : void 0);
164
+ } catch (err) {
165
+ if (err instanceof ProviderApiError && err.status === 404) return [];
166
+ throw err;
167
+ }
168
+ if (!Array.isArray(body)) throw new Error(`${repo}:${at} is a file, not a directory`);
169
+ const entries = body.map(({ name, path: p, type, size, sha }) => ({
170
+ name,
171
+ path: p,
172
+ type,
173
+ size,
174
+ sha
175
+ }));
176
+ if (!options.recursive) return entries;
177
+ const nested = await Promise.all(entries.filter((e) => e.type === "dir").map((e) => list(e.path)));
178
+ return [...entries, ...nested.flat()];
179
+ };
180
+ return list(path.replace(/^\/+|\/+$/g, ""));
181
+ },
182
+ /**
153
183
  * `PUT /repos/:repo/contents/:path` — creates or updates one file in a single commit. Pass `sha` when
154
184
  * updating so a concurrent change is refused (409) and not silently overwritten.
155
185
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/github-client",
3
- "version": "1.58.0-alpha.10",
3
+ "version": "1.58.0-alpha.11",
4
4
  "description": "A TypeScript client for the GitHub REST API",
5
5
  "keywords": [
6
6
  "github",
@@ -32,8 +32,8 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@theholocron/http-client": "^1.58.0-alpha.10",
36
- "@theholocron/observability": "^0.7.0-alpha.1"
35
+ "@theholocron/observability": "^0.7.0-alpha.1",
36
+ "@theholocron/http-client": "^1.58.0-alpha.11"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^26",
@@ -46,9 +46,9 @@
46
46
  "typescript": "^5.9.3",
47
47
  "vitest": "^5.0.5",
48
48
  "@theholocron/tsconfig": "^8.9.0-alpha.8",
49
- "@theholocron/tsdown-config": "^8.9.0-alpha.8",
49
+ "@theholocron/vitest-config": "^8.9.0-alpha.8",
50
50
  "@theholocron/eslint-config": "^8.9.0-alpha.8",
51
- "@theholocron/vitest-config": "^8.9.0-alpha.8"
51
+ "@theholocron/tsdown-config": "^8.9.0-alpha.8"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22.0.0"