MCPcopy Create free account
hub / github.com/dyoshikawa/rulesync / getFileInfo

Method getFileInfo

src/lib/github-client.ts:175–215  ·  view source on GitHub ↗

* Check if a file exists and is within size limits

(
    owner: string,
    repo: string,
    path: string,
    ref?: string,
  )

Source from the content-addressed store, hash-verified

173 * Check if a file exists and is within size limits
174 */
175 async getFileInfo(
176 owner: string,
177 repo: string,
178 path: string,
179 ref?: string,
180 ): Promise<GitHubFileEntry | null> {
181 try {
182 const { data } = await this.octokit.repos.getContent({
183 owner,
184 repo,
185 path,
186 ref,
187 });
188
189 // Ensure it's a file, not a directory
190 if (Array.isArray(data)) {
191 return null; // It's a directory
192 }
193
194 const parsed = GitHubFileEntrySchema.safeParse(data);
195 if (!parsed.success) {
196 return null;
197 }
198
199 if (parsed.data.size > MAX_FILE_SIZE) {
200 throw new GitHubClientError(
201 `File "${path}" exceeds maximum size limit of ${MAX_FILE_SIZE / 1024 / 1024}MB`,
202 );
203 }
204
205 return parsed.data;
206 } catch (error: unknown) {
207 if (error instanceof RequestError && error.status === 404) {
208 return null;
209 }
210 if (error instanceof GitHubClientError && error.statusCode === 404) {
211 return null;
212 }
213 throw this.handleError(error);
214 }
215 }
216
217 /**
218 * Validate that a repository exists and is accessible

Callers 1

Calls 1

handleErrorMethod · 0.95

Tested by

no test coverage detected