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

nikelborm / fetch-github-folder / 12804526304

16 Jan 2025 08:03AM UTC coverage: 56.577% (+0.2%) from 56.366%
12804526304

push

github

nikelborm
quick save: Thu Jan 16 11:03:21 MSK 2025

47 of 59 branches covered (79.66%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

75 existing lines in 8 files now uncovered.

310 of 572 relevant lines covered (54.2%)

2.37 hits per line

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

85.94
/src/getPathContents/requestRepoPathContentsFromGitHubAPI.ts
1
import { RequestError } from "@octokit/request-error";
1✔
2
import type { OctokitResponse } from "@octokit/types";
3
import { UnknownException } from 'effect/Cause';
4
import { gen, tryPromise } from 'effect/Effect';
5
import { InputConfigTag, RepoConfigTag } from '../config.js';
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

18
export const requestRepoPathContentsFromGitHubAPI = (
1✔
19
  format: 'object' | 'raw',
14✔
20
  streamBody?: boolean
14✔
21
) => gen(function * () {
14✔
22
  const octokit = yield* OctokitTag;
14✔
23

24
  const { gitRef, pathToEntityInRepo } = yield* InputConfigTag;
14✔
25
  const repo = yield* RepoConfigTag;
14✔
26

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

68
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