forked from SvanBoxel/codeowners-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
45 lines (38 loc) · 1.15 KB
/
Copy pathutils.ts
File metadata and controls
45 lines (38 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import {spawn} from 'child_process'
import fs from 'fs'
export async function getVersionControlledFiles(): Promise<string[]> {
return new Promise((resolve, reject) => {
const listVersionControlledFilesCommand = spawn('git', [
'ls-tree',
'HEAD',
'-r',
'--name-only'
])
let stdout = ''
let stderr = ''
listVersionControlledFilesCommand.stdout.on('data', (data: Buffer) => {
stdout += data.toString()
})
listVersionControlledFilesCommand.stderr.on('data', (data: Buffer) => {
stderr += data.toString()
})
listVersionControlledFilesCommand.on('error', (error: Error) => {
reject(error)
})
listVersionControlledFilesCommand.on('close', (code: number) => {
if (code !== 0) {
reject(new Error(`Command failed with exit code ${code}: ${stderr}`))
} else {
resolve(stdout.split(/\r?\n/).filter(Boolean))
}
})
})
}
export async function getFileContents(file: string): Promise<string> {
return new Promise((resolve, reject) => {
fs.readFile(file, {encoding: 'utf-8'}, (err, data) => {
if (err) reject(err)
resolve(data)
})
})
}