export function parseCIFlowIssue()

in torchci/lib/bot/ciflowBot.ts [14:50]


export function parseCIFlowIssue(rawText: string): Map<string, IUserConfig> {
  const [optIn, optOut] = ["@", "-@"];
  const rows = rawText.replace("\r", "").split("\n");
  const userConfigMap: Map<string, IUserConfig> = new Map();
  rows.forEach((row: string) => {
    const elements = row
      .trim()
      .replace(/^-\s*@/, "-@")
      .split(" ");
    if (
      elements.length < 1 ||
      elements[0].length < 1 ||
      !(elements[0].startsWith(optIn) || elements[0].startsWith(optOut))
    ) {
      return;
    }

    // opt-out users
    if (elements[0].startsWith(optOut)) {
      const login = elements[0].substring(2);
      userConfigMap.set(login, {
        optOut: true,
      });
      return;
    }

    // users with custom labels
    const login = elements[0].substring(1);
    const defaultLabels =
      elements.length === 1 ? DEFAULT_LABELS : elements.slice(1);
    userConfigMap.set(login, {
      optOut: false,
      defaultLabels,
    });
  });
  return userConfigMap;
}