-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Open
Description
Instead of callers needing this code, add this as another property on the return value of getChangedFilesStatuses(). Either copy the values once into another array, keeping the return a POJO. Or return an object with a method to create (or iterate) the flat list on demand.
/**
* Creates a flat, de-duplicated list of changed files from the status results.
* Includes both rename endpoints (`from` and `to`) to ensure path-based filters work as expected.
* @param {{additions: string[], modifications: string[], deletions: string[], renames: {from: string, to: string}[]}} statuses
* @returns {string[]}
*/
function getFlatChangedFilesFromStatuses(statuses) {
/** @type {Set<string>} */
const seen = new Set();
/** @param {string} file */
const add = (file) => {
if (typeof file !== "string" || file.length === 0) return;
seen.add(file);
};
for (const file of statuses.additions) add(file);
for (const file of statuses.modifications) add(file);
for (const file of statuses.deletions) add(file);
for (const rename of statuses.renames) {
add(rename.from);
add(rename.to);
}
return Array.from(seen);
}Also, add typdef for the return object:
| * @returns {Promise<{additions: string[], modifications: string[], deletions: string[], renames: {from: string, to: string}[], total: number}>} |
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
🐝 Dev