Azure / Azure/azure-rest-api-specs
[changed-files.js] Add flat list to result of getChangedFilesStatuses()
- Dominant language
- TypeSpec
- Stars
- 3.1k
- Forks
- 5.9k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 424
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.
https://github.com/Azure/azure-rest-api-specs/pull/38744/files#diff-06e80859a863af152c2716599bf565ea14624a122c67e4578d2bb333319045fbR315
```js
/**
* 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} */
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:
https://github.com/Azure/azure-rest-api-specs/blob/18609d68cf243ee3ce35d7c005ff3c7dd2cd9477/.github/shared/src/changed-files.js#L59
Contributor guide
Assessment
This issue has not been assessed yet.