-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.ts
More file actions
56 lines (49 loc) · 1.64 KB
/
Copy pathmain.ts
File metadata and controls
56 lines (49 loc) · 1.64 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
46
47
48
49
50
51
52
53
54
55
56
import path from 'path'
import fs from 'fs'
import * as core from '@actions/core'
import extractCodeOwners from './extract-codeowners'
import extractFileMatches from './extract-filematches'
import {getVersionControlledFiles} from './utils'
const filepath = './codeowner-information.json'
async function extractCodeOwnerInfo(
codeownerPath: string,
fileMatchInfo: boolean,
includeNoOwners: boolean
): Promise<void> {
try {
let results = {}
const filePath: string = path.join(
process.env.GITHUB_WORKSPACE || './',
codeownerPath
)
const codeownerInfo = await extractCodeOwners(filePath)
core.setOutput('codeowners', JSON.stringify(codeownerInfo))
results = {codeownerInfo}
if (fileMatchInfo) {
const versionControlledFiles = await getVersionControlledFiles()
const fileMatches = extractFileMatches(
versionControlledFiles,
codeownerInfo,
includeNoOwners
)
core.setOutput('filematches', JSON.stringify(fileMatches))
results = {codeownerInfo, fileMatches}
}
fs.writeFile(filepath, JSON.stringify(results), err => {
if (err)
core.warning(
`error writing results to file: ${err}. Action output is still available`
)
})
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message)
} else {
core.setFailed(String(error))
}
}
}
const codeownerPath = core.getInput('path') || './CODEOWNERS'
const fileMatchInfo = core.getBooleanInput('file_match_info')
const includeNoOwners = core.getBooleanInput('include_no_owners')
extractCodeOwnerInfo(codeownerPath, fileMatchInfo, includeNoOwners)