• 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

0.0
/fetch-github-folder.ts
1
#!/usr/bin/env node
×
2

3
import { Args } from '@effect/cli';
4
import {
5
  text,
6
  withDefault,
7
  withDescription,
8
  withFallbackConfig,
9
} from '@effect/cli/Args';
10
import { make, run } from '@effect/cli/Command';
11
import { layer as NodeFileSystemLayer } from '@effect/platform-node/NodeFileSystem';
12
import { layer as NodePathLayer } from '@effect/platform-node/NodePath';
13
import { runMain } from '@effect/platform-node/NodeRuntime';
14
import { layer as NodeTerminalLayer } from '@effect/platform-node/NodeTerminal';
15
import { Path } from '@effect/platform/Path';
16
import { Octokit as OctokitClient } from '@octokit/core';
17
import { ParseResult, Schema } from 'effect';
18
import { nonEmptyString } from 'effect/Config';
19
import { flatMap, provide, provideService } from 'effect/Effect';
20
import { pipe } from 'effect/Function';
21
import {
22
  downloadEntityFromRepo,
23
  OctokitTag,
24
  createSingleTargetConfigContext,
25
} from './src/index.js';
26

27
// Those values updated automatically. If you edit names of constants or
28
// move them to a different file, update ./scripts/build.sh
NEW
29
const PACKAGE_VERSION = '0.1.6';
×
NEW
30
const PACKAGE_NAME = 'fetch-github-folder';
×
31

32
const pathToDirectoryInRepo = pipe(
×
33
  text({ name: 'pathToDirectoryInRepo' }),
×
NEW
34
  withDescription('Path to directory in repo'),
×
NEW
35
  withFallbackConfig(nonEmptyString('PATH_TO_DIRECTORY_IN_REPO')),
×
UNCOV
36
);
×
37

38
const repoOwner = pipe(
×
NEW
39
  text({ name: 'repoOwner' }),
×
40
  withDescription("Repo owner's username"),
×
NEW
41
  withFallbackConfig(nonEmptyString('GITHUB_REPO_OWNER')),
×
42
);
×
43

44
const repoName = pipe(
×
NEW
45
  text({ name: 'repoName' }),
×
46
  withDescription("Repo's name"),
×
NEW
47
  withFallbackConfig(nonEmptyString('GITHUB_REPO_NAME')),
×
48
);
×
49

UNCOV
50
export const CleanedPathString = Schema.transformOrFail(
×
51
  Schema.String,
×
52
  Schema.String,
×
53
  {
×
54
    strict: true,
×
NEW
55
    decode: (dirtyPathToEntityInRepo, _, ast) =>
×
NEW
56
      Path.pipe(
×
NEW
57
        flatMap(path => {
×
58
          // dot can be there only when that's all there is. path.join(...)
59
          // removes all './', so '.' will never be just left by themself. If it's
60
          // there, it's very intentional and no other elements in the path exist.
NEW
61
          const cleanPathToEntityInRepo = path.join(
×
62
            dirtyPathToEntityInRepo,
×
NEW
63
          );
×
64

NEW
65
          if (cleanPathToEntityInRepo.startsWith('..'))
×
NEW
66
            return ParseResult.fail(
×
NEW
67
              new ParseResult.Type(
×
NEW
68
                ast,
×
NEW
69
                dirtyPathToEntityInRepo,
×
NEW
70
                "Can\'t request contents that lie higher than the root of the repo",
×
NEW
71
              ),
×
NEW
72
            );
×
NEW
73
          return ParseResult.succeed(cleanPathToEntityInRepo);
×
NEW
74
        }),
×
NEW
75
      ),
×
NEW
76
    encode: ParseResult.succeed,
×
NEW
77
  },
×
NEW
78
);
×
79

80
const localPathAtWhichEntityFromRepoWillBeAvailable = pipe(
×
NEW
81
  text({ name: 'destinationPath' }),
×
NEW
82
  withDescription(
×
NEW
83
    'Local path at which entity from repo will be available',
×
NEW
84
  ),
×
NEW
85
  withFallbackConfig(nonEmptyString('DESTINATION_PATH')),
×
86
  Args.withSchema(CleanedPathString),
×
87
  withDefault('./destination'),
×
88
);
×
89

UNCOV
90
const gitRef = pipe(
×
NEW
91
  text({ name: 'gitRef' }),
×
NEW
92
  withDescription('Commit sha hash or branch name or tag name'),
×
NEW
93
  withFallbackConfig(nonEmptyString('DESTINATION_PATH')),
×
94
  withDefault('HEAD'),
×
95
);
×
96

NEW
97
const appCommand = make(
×
NEW
98
  'fetch-github-folder',
×
NEW
99
  {
×
NEW
100
    repoOwner,
×
NEW
101
    repoName,
×
NEW
102
    pathToDirectoryInRepo,
×
NEW
103
    localPathAtWhichEntityFromRepoWillBeAvailable,
×
NEW
104
    gitRef,
×
NEW
105
  },
×
NEW
106
  x =>
×
NEW
107
    pipe(
×
NEW
108
      downloadEntityFromRepo,
×
NEW
109
      provide(
×
NEW
110
        createSingleTargetConfigContext({
×
NEW
111
          repo: {
×
NEW
112
            owner: x.repoOwner,
×
NEW
113
            name: x.repoName,
×
NEW
114
          },
×
NEW
115
          pathToEntityInRepo: x.pathToDirectoryInRepo,
×
NEW
116
          gitRef: x.gitRef,
×
NEW
117
          localPathAtWhichEntityFromRepoWillBeAvailable:
×
NEW
118
            x.localPathAtWhichEntityFromRepoWillBeAvailable,
×
NEW
119
        }),
×
NEW
120
      ),
×
NEW
121
    ),
×
NEW
122
);
×
123

124
const cli = run(appCommand, {
×
125
  // those values will be filled automatically from package.json
126
  name: PACKAGE_NAME,
×
127
  version: PACKAGE_VERSION,
×
128
});
×
129

UNCOV
130
pipe(
×
131
  process.argv,
×
132
  cli,
×
133
  provide(NodeFileSystemLayer),
×
134
  provide(NodePathLayer),
×
135
  provide(NodeTerminalLayer),
×
NEW
136
  provideService(
×
NEW
137
    OctokitTag,
×
NEW
138
    new OctokitClient({
×
139
      // auth: getEnvVarOrFail('GITHUB_ACCESS_TOKEN'),
NEW
140
    }),
×
NEW
141
  ),
×
NEW
142
  runMain,
×
UNCOV
143
);
×
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