{"version":3,"file":"remote.mjs","names":[],"sources":["../src/remote.ts"],"sourcesContent":["/**\n * Git remote normalisation, so a `when.remote` pattern compares the same repository whichever way its\n * URL is written.\n */\n\n/**\n * Reduce a git remote to `host/path`, lower case, without scheme, credentials, port, trailing slash\n * or `.git` suffix: `git@github.com:Org/Repo.git` and `https://github.com/org/repo` both become\n * `github.com/org/repo`. A local path keeps its leading slash. Already-normalised input is returned\n * unchanged.\n *\n * Credentials are dropped so a token embedded in a URL never reaches a comparison, a log or a trace.\n */\nexport function normaliseRemote(remote: string): string {\n  let rest = remote.trim();\n\n  const scheme = /^[a-z][a-z0-9+.-]*:\\/\\//i.exec(rest);\n  if (scheme) {\n    rest = rest.slice(scheme[0].length);\n    // scheme://[credentials@]host[:port]/path\n    const slash = rest.indexOf(\"/\");\n    const authority = slash === -1 ? rest : rest.slice(0, slash);\n    const path = slash === -1 ? \"\" : rest.slice(slash);\n    const host = authority.slice(authority.lastIndexOf(\"@\") + 1);\n    rest = host.replace(/:\\d*$/, \"\") + path;\n  } else {\n    // scp-like: [credentials@]host:path, but not a Windows drive such as C:\\repo\n    const scp = /^(?:[^@/:]*@)?([^/:]{2,}):(.+)$/.exec(rest);\n    if (scp?.[1] !== undefined && scp[2] !== undefined) {\n      rest = `${scp[1]}/${scp[2]}`;\n    }\n  }\n\n  return rest\n    .replace(/\\/+$/, \"\")\n    .replace(/\\.git$/, \"\")\n    .toLowerCase();\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,gBAAgB,QAAwB;CACtD,IAAI,OAAO,OAAO,KAAK;CAEvB,MAAM,SAAS,2BAA2B,KAAK,IAAI;CACnD,IAAI,QAAQ;EACV,OAAO,KAAK,MAAM,OAAO,EAAE,CAAC,MAAM;EAElC,MAAM,QAAQ,KAAK,QAAQ,GAAG;EAC9B,MAAM,YAAY,UAAU,KAAK,OAAO,KAAK,MAAM,GAAG,KAAK;EAC3D,MAAM,OAAO,UAAU,KAAK,KAAK,KAAK,MAAM,KAAK;EAEjD,OADa,UAAU,MAAM,UAAU,YAAY,GAAG,IAAI,CAChD,CAAC,CAAC,QAAQ,SAAS,EAAE,IAAI;CACrC,OAAO;EAEL,MAAM,MAAM,kCAAkC,KAAK,IAAI;EACvD,IAAI,MAAM,OAAO,UAAa,IAAI,OAAO,QACvC,OAAO,GAAG,IAAI,GAAG,GAAG,IAAI;CAE5B;CAEA,OAAO,KACJ,QAAQ,QAAQ,EAAE,CAAC,CACnB,QAAQ,UAAU,EAAE,CAAC,CACrB,YAAY;AACjB"}