Skip to content

[changed-files.js] Add flat list to result of getChangedFilesStatuses() #39306

@mikeharder

Description

@mikeharder

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

/**
 * 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
No labels

Type

No type

Projects

Status

🐝 Dev

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions