diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-10-31 04:06:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-30 20:06:36 +0000 |
commit | a4a121c684fdbbad19971ff658166fd47932b192 (patch) | |
tree | c44c7ea6ad5f41251f06b69cff1d69786e48d3d1 /web_src/js/utils.ts | |
parent | f4d3aaeeb9e1b11c5495e4608a3f52f316c35758 (diff) | |
download | gitea-a4a121c684fdbbad19971ff658166fd47932b192.tar.gz gitea-a4a121c684fdbbad19971ff658166fd47932b192.zip |
Fix suggestions for issues (#32380)
Diffstat (limited to 'web_src/js/utils.ts')
-rw-r--r-- | web_src/js/utils.ts | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/web_src/js/utils.ts b/web_src/js/utils.ts index c52bf500d4..066a7c7b54 100644 --- a/web_src/js/utils.ts +++ b/web_src/js/utils.ts @@ -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' |