MCPcopy Create free account
hub / github.com/garrytan/gstack / makeFakeGh

Function makeFakeGh

test/gstack-artifacts-init.test.ts:35–66  ·  view source on GitHub ↗
(opts: { authStatus?: 'ok' | 'fail'; repoCreate?: 'success' | 'already-exists' | 'fail'; webUrl?: string } = {})

Source from the content-addressed store, hash-verified

33let glabCallLog: string;
34
35function makeFakeGh(opts: { authStatus?: 'ok' | 'fail'; repoCreate?: 'success' | 'already-exists' | 'fail'; webUrl?: string } = {}) {
36 const authStatus = opts.authStatus ?? 'ok';
37 const repoCreate = opts.repoCreate ?? 'success';
38 const webUrl = opts.webUrl ?? `https://github.com/testuser/gstack-artifacts-testuser`;
39 const script = `#!/bin/bash
40echo "gh $@" >> "${ghCallLog}"
41case "$1" in
42 auth) ${authStatus === 'ok' ? 'exit 0' : 'exit 1'} ;;
43 repo)
44 shift
45 case "$1" in
46 create)
47 ${
48 repoCreate === 'success'
49 ? 'exit 0'
50 : repoCreate === 'already-exists'
51 ? 'echo "GraphQL: Name already exists on this account" >&2; exit 1'
52 : 'echo "network error" >&2; exit 1'
53 }
54 ;;
55 view)
56 # gh repo view <name> --json url -q .url
57 echo "${webUrl}"
58 exit 0
59 ;;
60 esac
61 ;;
62esac
63exit 0
64`;
65 fs.writeFileSync(path.join(fakeBinDir, 'gh'), script, { mode: 0o755 });
66}
67
68function makeFakeGlab(opts: { authStatus?: 'ok' | 'fail'; repoCreate?: 'success' | 'fail'; webUrl?: string } = {}) {
69 const authStatus = opts.authStatus ?? 'ok';

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected