83bc1c616 days ago14 lines · 507 B| 1 | /** Splits `org:acme user:alice rest of query` into the owner it names and the text left to match. `org:` and `user:` both name the owner in `/owner/repo`; the last one given wins. */ |
| 2 | export function ownerQualifier(query: string) { |
| 3 | let owner: string | null = null; |
| 4 | const rest = query |
| 5 | .split(/\s+/) |
| 6 | .filter((token) => { |
| 7 | const match = /^(?:org|user):(\S+)$/i.exec(token); |
| 8 | if (match) owner = match[1]; |
| 9 | return !match; |
| 10 | }) |
| 11 | .join(' ') |
| 12 | .trim(); |
| 13 | return { owner, rest }; |
| 14 | } |