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

nikelborm / fetch-github-folder / 12812486284

16 Jan 2025 03:45PM UTC coverage: 53.547% (+0.8%) from 52.778%
12812486284

push

github

nikelborm
quick save: Thu Jan 16 18:45:47 MSK 2025

50 of 60 branches covered (83.33%)

Branch coverage included in aggregate %.

28 of 33 new or added lines in 2 files covered. (84.85%)

335 of 659 relevant lines covered (50.83%)

2.25 hits per line

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

93.55
/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
  GitHubApiNoCommitFoundForGitRef,
8
  GitHubApiRepoIsEmpty,
9
  GitHubApiSomethingDoesNotExistsOrPermissionsInsufficient,
10
  parseCommonGitHubApiErrors,
11
} from '../errors.js';
12
import { OctokitTag } from '../octokit.js';
13

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

21
    const { gitRef, pathToEntityInRepo } = yield* InputConfigTag;
14✔
22
    const repo = yield* RepoConfigTag;
14✔
23

24
    return yield* tryPromise({
14✔
25
      try: signal =>
14✔
26
        octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
14✔
27
          owner: repo.owner,
14✔
28
          repo: repo.name,
14✔
29
          path: pathToEntityInRepo,
14✔
30
          ...(gitRef && { ref: gitRef }),
14✔
31
          request: {
14✔
32
            signal,
14✔
33
            parseSuccessResponseBody: !streamBody,
14✔
34
          },
14✔
35
          mediaType: { format },
14✔
36
          headers: {
14✔
37
            'X-GitHub-Api-Version': '2022-11-28',
14✔
38
          },
14✔
39
        }),
14✔
40
      catch: error => {
14✔
41
        if (!(error instanceof RequestError))
7✔
42
          return new UnknownException(
7!
NEW
43
            error,
×
NEW
44
            'Failed to request contents at the path inside GitHub repo',
×
NEW
45
          );
×
46

47
        if (error.status === 404)
7✔
48
          return parseNotFoundErrors(error, gitRef);
7✔
49

50
        return parseCommonGitHubApiErrors(error);
2✔
51
      },
7✔
52
    });
14✔
53
  });
14✔
54

55
const parseNotFoundErrors = (error: RequestError, gitRef: string) => {
1✔
56
  if (
5✔
57
    (error.response as ResponseWithError)?.data?.message ===
5✔
58
    'This repository is empty.'
5✔
59
  )
60
    return new GitHubApiRepoIsEmpty(error);
5✔
61

62
  if (
4✔
63
    gitRef &&
4✔
64
    (error.response as ResponseWithError)?.data?.message?.startsWith(
1✔
65
      'No commit found for the ref',
1✔
66
    )
1✔
67
  )
68
    return new GitHubApiNoCommitFoundForGitRef(error, { gitRef });
5✔
69

70
  return new GitHubApiSomethingDoesNotExistsOrPermissionsInsufficient(
3✔
71
    error,
3✔
72
  );
3✔
73
};
3✔
74

75
type ResponseWithError = OctokitResponse<
76
  { message?: string } | undefined,
77
  number
78
>;
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