• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nikelborm / fetch-github-folder / 12721107228

11 Jan 2025 04:15AM UTC coverage: 56.192% (-0.8%) from 57.003%
12721107228

push

github

nikelborm
save

45 of 56 branches covered (80.36%)

Branch coverage included in aggregate %.

104 of 129 new or added lines in 6 files covered. (80.62%)

10 existing lines in 2 files now uncovered.

318 of 590 relevant lines covered (53.9%)

2.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.15
/src/getPathContents/requestRepoPathContentsFromGitHubAPI.ts
1
import { RequestError } from "@octokit/request-error";
1✔
2
import type { OctokitResponse } from "@octokit/types";
3
import { pipe } from 'effect/Function';
4
import { UnknownException } from 'effect/Cause';
5
import { tryMapPromise } from 'effect/Effect';
6
import {
7
  GitHubApiAuthRatelimited,
8
  GitHubApiBadCredentials,
9
  GitHubApiGeneralServerError,
10
  GitHubApiGeneralUserError,
11
  GitHubApiNoCommitFoundForGitRef,
12
  GitHubApiRatelimited,
13
  GitHubApiRepoIsEmpty,
14
  GitHubApiSomethingDoesNotExistsOrPermissionsInsufficient
15
} from '../errors.js';
16
import { OctokitTag } from '../octokit.js';
17
import { Repo } from '../repo.interface.js';
18

19
export const requestRepoPathContentsFromGitHubAPI = ({
1✔
20
  repo,
14✔
21
  gitRef,
14✔
22
  format,
14✔
23
  path,
14✔
24
  streamBody
14✔
25
}: {
14✔
26
  repo: Repo,
27
  path: string,
28
  format: 'object' | 'raw'
29
  gitRef?: string | undefined,
30
  streamBody?: boolean
31
}) => pipe(
14✔
32
  OctokitTag,
14✔
33
  tryMapPromise({
14✔
34
    try: (octokit, signal) => octokit.request(
14✔
35
      'GET /repos/{owner}/{repo}/contents/{path}',
14✔
36
      {
14✔
37
        owner: repo.owner,
14✔
38
        repo: repo.name,
14✔
39
        path,
14✔
40
        ...(gitRef && { ref: gitRef }),
14✔
41
        request: {
14✔
42
          signal,
14✔
43
          parseSuccessResponseBody: !streamBody
14✔
44
        },
14✔
45
        mediaType: { format },
14✔
46
        headers: {
14✔
47
          'X-GitHub-Api-Version': '2022-11-28'
14✔
48
        },
14✔
49
      }
14✔
50
    ),
14✔
51
    catch: (error) => !(error instanceof RequestError)
14✔
NEW
52
      ? new UnknownException(error, "Failed to request contents at the path inside GitHub repo")
×
53
      : error.status === 404 && (error.response as ResponseWithError)?.data?.message === 'This repository is empty.'
7✔
54
      ? new GitHubApiRepoIsEmpty(error)
1✔
55
      : gitRef && error.status === 404 && (error.response as ResponseWithError)?.data?.message?.startsWith('No commit found for the ref')
6✔
56
      ? new GitHubApiNoCommitFoundForGitRef(error, { gitRef })
1✔
57
      // https://docs.github.com/en/rest/authentication/authenticating-to-the-rest-api?apiVersion=2022-11-28#failed-login-limit
58
      : error.status === 404
5✔
59
      ? new GitHubApiSomethingDoesNotExistsOrPermissionsInsufficient(error)
3✔
60
      : error.status === 401
2✔
61
      ? new GitHubApiBadCredentials(error)
1✔
62
      : error.status === 403
1!
NEW
63
      ? new GitHubApiAuthRatelimited(error)
×
64
      : error.status === 429
1!
NEW
65
      ? new GitHubApiRatelimited(error)
×
66
      : error.status >= 500
1!
NEW
67
      ? new GitHubApiGeneralServerError(error)
×
68
      : error.status >= 400
1✔
69
      ? new GitHubApiGeneralUserError(error)
1!
NEW
70
      : error
×
71
  }),
14✔
72
)
14✔
73

74
type ResponseWithError = OctokitResponse<{ message?: string } | undefined, number>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc