• 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

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

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

18
// Those values updated automatically. If you edit names of constants or
19
// move them to a different file, update ./scripts/build.sh
20
const PACKAGE_VERSION = "0.1.6";
×
21
const PACKAGE_NAME = "fetch-github-folder";
×
22

23

24

25
const pathToDirectoryInRepo = pipe(
×
26
  text({ name: 'pathToDirectoryInRepo' }),
×
UNCOV
27
  withDescription("Path to directory in repo"),
×
28
  withFallbackConfig(nonEmptyString("PATH_TO_DIRECTORY_IN_REPO"))
×
29
);
×
30

31
const repoOwner = pipe(
×
UNCOV
32
  text({ name: "repoOwner" }),
×
33
  withDescription("Repo owner's username"),
×
34
  withFallbackConfig(nonEmptyString("GITHUB_REPO_OWNER"))
×
35
);
×
36

UNCOV
37
const repoName = pipe(
×
38
  text({ name: "repoName" }),
×
39
  withDescription("Repo's name"),
×
40
  withFallbackConfig(nonEmptyString("GITHUB_REPO_NAME"))
×
41
);
×
42

43

44
export const CleanedPathString = Schema.transformOrFail(
×
45
  Schema.String,
×
46
  Schema.String,
×
47
  {
×
48
    strict: true,
×
49
    decode: (dirtyPathToEntityInRepo, _, ast) => Path.pipe(flatMap((path) => {
×
50
      // dot can be there only when that's all there is. path.join(...)
51
      // removes all './', so '.' will never be just left by themself. If it's
52
      // there, it's very intentional and no other elements in the path exist.
53
      const cleanPathToEntityInRepo = path.join(dirtyPathToEntityInRepo);
×
54

55
      if (cleanPathToEntityInRepo.startsWith('..'))
×
56
        return ParseResult.fail(
×
57
          new ParseResult.Type(
×
58
            ast,
×
59
            dirtyPathToEntityInRepo,
×
60
            "Can\'t request contents that lie higher than the root of the repo"
×
61
          )
×
UNCOV
62
        )
×
UNCOV
63
      return ParseResult.succeed(cleanPathToEntityInRepo)
×
64
    })),
×
UNCOV
65
    encode: ParseResult.succeed
×
66
  }
×
67
)
×
68

UNCOV
69
const localPathAtWhichEntityFromRepoWillBeAvailable = pipe(
×
UNCOV
70
  text({ name: "destinationPath" }),
×
71
  withDescription("Local path at which entity from repo will be available"),
×
72
  withFallbackConfig(nonEmptyString("DESTINATION_PATH")),
×
73
  Args.withSchema(CleanedPathString),
×
74
  withDefault('./destination'),
×
75
);
×
76

77

78

79

80
const gitRef = pipe(
×
81
  text({ name: "gitRef" }),
×
UNCOV
82
  withDescription("Commit sha hash or branch name or tag name"),
×
UNCOV
83
  withFallbackConfig(nonEmptyString("DESTINATION_PATH")),
×
UNCOV
84
  withDefault('HEAD'),
×
UNCOV
85
);
×
86

UNCOV
87
const appCommand = make("fetch-github-folder", {
×
UNCOV
88
  repoOwner,
×
UNCOV
89
  repoName,
×
UNCOV
90
  pathToDirectoryInRepo,
×
UNCOV
91
  localPathAtWhichEntityFromRepoWillBeAvailable,
×
UNCOV
92
  gitRef,
×
UNCOV
93
}, (x) => pipe(
×
UNCOV
94
  downloadEntityFromRepo,
×
UNCOV
95
  provide(createSingleTargetConfigContext({
×
UNCOV
96
    repo: {
×
UNCOV
97
      owner: x.repoOwner,
×
UNCOV
98
      name: x.repoName,
×
UNCOV
99
    },
×
UNCOV
100
    pathToEntityInRepo: x.pathToDirectoryInRepo,
×
UNCOV
101
    gitRef: x.gitRef,
×
UNCOV
102
    localPathAtWhichEntityFromRepoWillBeAvailable:
×
UNCOV
103
      x.localPathAtWhichEntityFromRepoWillBeAvailable,
×
UNCOV
104
  }))
×
UNCOV
105
));
×
106

107

UNCOV
108
const cli = run(appCommand, {
×
109
  // those values will be filled automatically from package.json
UNCOV
110
  name: PACKAGE_NAME,
×
UNCOV
111
  version: PACKAGE_VERSION,
×
UNCOV
112
});
×
113

114

UNCOV
115
pipe(
×
UNCOV
116
  process.argv,
×
UNCOV
117
  cli,
×
UNCOV
118
  provide(NodeFileSystemLayer),
×
UNCOV
119
  provide(NodePathLayer),
×
UNCOV
120
  provide(NodeTerminalLayer),
×
UNCOV
121
  provideService(OctokitTag, new OctokitClient({
×
122
    // auth: getEnvVarOrFail('GITHUB_ACCESS_TOKEN'),
UNCOV
123
  })),
×
UNCOV
124
  runMain
×
UNCOV
125
);
×
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