Fix suggestions for issues (#32380)

This commit is contained in:
wxiaoguang 2024-10-31 04:06:36 +08:00 committed by GitHub
parent f4d3aaeeb9
commit a4a121c684
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 82 additions and 88 deletions

View file

@ -1,5 +1,5 @@
import {encode, decode} from 'uint8-to-base64';
import type {IssueData} from './types.ts';
import type {IssuePathInfo} from './types.ts';
// transform /path/to/file.ext to file.ext
export function basename(path: string): string {
@ -31,10 +31,16 @@ export function stripTags(text: string): string {
return text.replace(/<[^>]*>?/g, '');
}
export function parseIssueHref(href: string): IssueData {
export function parseIssueHref(href: string): IssuePathInfo {
const path = (href || '').replace(/[#?].*$/, '');
const [_, owner, repo, type, index] = /([^/]+)\/([^/]+)\/(issues|pulls)\/([0-9]+)/.exec(path) || [];
return {owner, repo, type, index};
const [_, ownerName, repoName, pathType, indexString] = /([^/]+)\/([^/]+)\/(issues|pulls)\/([0-9]+)/.exec(path) || [];
return {ownerName, repoName, pathType, indexString};
}
export function parseIssueNewHref(href: string): IssuePathInfo {
const path = (href || '').replace(/[#?].*$/, '');
const [_, ownerName, repoName, pathType, indexString] = /([^/]+)\/([^/]+)\/(issues|pulls)\/new/.exec(path) || [];
return {ownerName, repoName, pathType, indexString};
}
// parse a URL, either relative '/path' or absolute 'https://localhost/path'