This repository was archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.js
More file actions
48 lines (43 loc) · 1.35 KB
/
filter.js
File metadata and controls
48 lines (43 loc) · 1.35 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
// Copyright 2019 VMware, Inc.
// SPDX-License-Identifier: BSD-2-Clause
const { config } = require('./config')
const minimatch = require('minimatch')
const path = require('path')
/**
* Checks whether a file should be excluded from processing
* @param {String} filePath path of file to check
* @param {String[]} excludes array of exclusion rules to compare to
*/
function isExcluded (filePath, excludes) {
let ok = false
for (let excludeRule of excludes) {
excludeRule = path.normalize(excludeRule)
if (minimatch(filePath, excludeRule, { matchBase: true })) {
ok = true
break
}
}
return ok
}
/**
* Filters the listed files and returns only the files relevant to us
* @param {*} rawData the raw output from list files API call
* @param {String[]} excludes array of exclusion rules in glob format provided by the user
* @return {Promise[]<any>} the filtered GitHub response
*/
function filterData (rawData, excludes) {
return rawData.data
.filter(file =>
config.fileExtensions.reduce(
(acc, ext) => acc || file.filename.endsWith(ext),
false
)
)
.filter(fileJSON => fileJSON.status !== 'removed')
.map(fileInfo => {
return fileInfo.filename
})
.filter(filePath => !isExcluded(filePath, excludes))
}
module.exports.filterData = filterData
module.exports.isExcluded = isExcluded