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

nikelborm / fetch-github-folder / 12804827031

16 Jan 2025 08:22AM UTC coverage: 55.394% (-1.2%) from 56.577%
12804827031

push

github

nikelborm
quick save: Thu Jan 16 11:22:57 MSK 2025

51 of 64 branches covered (79.69%)

Branch coverage included in aggregate %.

178 of 408 new or added lines in 15 files covered. (43.63%)

5 existing lines in 1 file now uncovered.

329 of 622 relevant lines covered (52.89%)

2.32 hits per line

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

83.12
/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
) =>
22
  gen(function* () {
14✔
23
    const octokit = yield* OctokitTag;
14✔
24

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

28
    return yield* tryPromise({
14✔
29
      try: signal =>
14✔
30
        octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
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
      catch: error =>
14✔
45
        !(error instanceof RequestError)
7!
NEW
46
          ? new UnknownException(
×
NEW
47
              error,
×
NEW
48
              'Failed to request contents at the path inside GitHub repo',
×
NEW
49
            )
×
50
          : error.status === 404 &&
7✔
51
              (error.response as ResponseWithError)?.data?.message ===
5✔
52
                'This repository is empty.'
5✔
53
            ? new GitHubApiRepoIsEmpty(error)
1✔
54
            : gitRef &&
6✔
55
                error.status === 404 &&
1✔
56
                (
57
                  error.response as ResponseWithError
1✔
58
                )?.data?.message?.startsWith('No commit found for the ref')
1✔
59
              ? new GitHubApiNoCommitFoundForGitRef(error, { gitRef })
1✔
60
              : // https://docs.github.com/en/rest/authentication/authenticating-to-the-rest-api?apiVersion=2022-11-28#failed-login-limit
61
                error.status === 404
5✔
62
                ? new GitHubApiSomethingDoesNotExistsOrPermissionsInsufficient(
3✔
63
                    error,
3✔
64
                  )
3✔
65
                : error.status === 401
2✔
66
                  ? new GitHubApiBadCredentials(error)
1✔
67
                  : error.status === 403
1!
NEW
68
                    ? new GitHubApiAuthRatelimited(error)
×
69
                    : error.status === 429
1!
NEW
70
                      ? new GitHubApiRatelimited(error)
×
71
                      : error.status >= 500
1!
NEW
72
                        ? new GitHubApiGeneralServerError(error)
×
73
                        : error.status >= 400
1✔
74
                          ? new GitHubApiGeneralUserError(error)
1!
NEW
75
                          : error,
×
76
    });
14✔
77
  });
14✔
78

79
type ResponseWithError = OctokitResponse<
80
  { message?: string } | undefined,
81
  number
82
>;
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