MCPcopy Index your code
hub / github.com/nodejs/node / runGitCommand

Function runGitCommand

tools/find-inactive-collaborators.mjs:20–48  ·  view source on GitHub ↗
(cmd, mapFn)

Source from the content-addressed store, hash-verified

18const SINCE = args.positionals[0] || '12 months ago';
19
20async function runGitCommand(cmd, mapFn) {
21 const childProcess = cp.spawn('/bin/sh', ['-c', cmd], {
22 cwd: new URL('..', import.meta.url),
23 encoding: 'utf8',
24 stdio: ['inherit', 'pipe', 'inherit'],
25 });
26 const lines = readline.createInterface({
27 input: childProcess.stdout,
28 });
29 const errorHandler = new Promise(
30 (_, reject) => childProcess.on('error', reject),
31 );
32 let returnValue = mapFn ? new Set() : '';
33 await Promise.race([errorHandler, Promise.resolve()]);
34 // If no mapFn, return the value. If there is a mapFn, use it to make a Set to
35 // return.
36 for await (const line of lines) {
37 await Promise.race([errorHandler, Promise.resolve()]);
38 if (mapFn) {
39 const val = mapFn(line);
40 if (val) {
41 returnValue.add(val);
42 }
43 } else {
44 returnValue += line;
45 }
46 }
47 return Promise.race([errorHandler, Promise.resolve(returnValue)]);
48}
49
50// Get all commit contributors during the time period.
51const contributors = await runGitCommand(

Calls 3

addMethod · 0.65
onMethod · 0.45
resolveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…