Skip to content

Commit 52a9662

Browse files
committed
fix
1 parent 2e42e96 commit 52a9662

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

web_src/js/features/comp/TextExpander.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import {matchEmoji, matchMention, matchIssue} from '../../utils/match.ts';
22
import {emojiString} from '../emoji.ts';
33
import {svg} from '../../svg.ts';
4-
import {parseIssueHref, parseIssueNewHref} from '../../utils.ts';
4+
import {parseIssueHref, parseRepoOwnerPathInfo} from '../../utils.ts';
55
import {createElementFromAttrs, createElementFromHTML} from '../../utils/dom.ts';
66
import {getIssueColor, getIssueIcon} from '../issue.ts';
77
import {debounce} from 'perfect-debounce';
88

99
const debouncedSuggestIssues = debounce((key: string, text: string) => new Promise<{matched:boolean; fragment?: HTMLElement}>(async (resolve) => {
10-
let issuePathInfo = parseIssueHref(window.location.href);
11-
if (!issuePathInfo.ownerName) issuePathInfo = parseIssueNewHref(window.location.href);
10+
const issuePathInfo = parseIssueHref(window.location.pathname);
11+
if (!issuePathInfo.ownerName) {
12+
const repoOwnerPathInfo = parseRepoOwnerPathInfo(window.location.pathname);
13+
issuePathInfo.ownerName = repoOwnerPathInfo.ownerName;
14+
issuePathInfo.repoName = repoOwnerPathInfo.repoName;
15+
// then no issuePathInfo.indexString here, it is only used to exclude the current issue when "matchIssue"
16+
}
1217
if (!issuePathInfo.ownerName) return resolve({matched: false});
1318

1419
const matches = await matchIssue(issuePathInfo.ownerName, issuePathInfo.repoName, issuePathInfo.indexString, text);

web_src/js/types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export type RequestOpts = {
3030
data?: RequestData,
3131
} & RequestInit;
3232

33+
export type RepoOwnerPathInfo = {
34+
ownerName: string,
35+
repoName: string,
36+
}
37+
3338
export type IssuePathInfo = {
3439
ownerName: string,
3540
repoName: string,

web_src/js/utils.test.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
basename, extname, isObject, stripTags, parseIssueHref,
33
parseUrl, translateMonth, translateDay, blobToDataURI,
4-
toAbsoluteUrl, encodeURLEncodedBase64, decodeURLEncodedBase64, isImageFile, isVideoFile, parseIssueNewHref,
4+
toAbsoluteUrl, encodeURLEncodedBase64, decodeURLEncodedBase64, isImageFile, isVideoFile, parseRepoOwnerPathInfo,
55
} from './utils.ts';
66

77
test('basename', () => {
@@ -46,11 +46,12 @@ test('parseIssueHref', () => {
4646
});
4747

4848
test('parseIssueNewHref', () => {
49-
expect(parseIssueNewHref('/owner/repo/issues/new')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'});
50-
expect(parseIssueNewHref('/owner/repo/issues/new?query')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'});
51-
expect(parseIssueNewHref('/sub/owner/repo/issues/new#hash')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'});
52-
expect(parseIssueNewHref('/sub/owner/repo/compare/feature/branch-1...fix/branch-2')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'pulls'});
53-
expect(parseIssueNewHref('/other')).toEqual({});
49+
expect(parseRepoOwnerPathInfo('/owner/repo/issues/new')).toEqual({ownerName: 'owner', repoName: 'repo'});
50+
expect(parseRepoOwnerPathInfo('/owner/repo/issues/new?query')).toEqual({ownerName: 'owner', repoName: 'repo'});
51+
expect(parseRepoOwnerPathInfo('/sub/owner/repo/issues/new#hash')).toEqual({ownerName: 'owner', repoName: 'repo'});
52+
expect(parseRepoOwnerPathInfo('/sub/owner/repo/compare/feature/branch-1...fix/branch-2')).toEqual({ownerName: 'owner', repoName: 'repo'});
53+
expect(parseRepoOwnerPathInfo('/owner/repo/releases')).toEqual({ownerName: 'owner', repoName: 'repo'});
54+
expect(parseRepoOwnerPathInfo('/other')).toEqual({});
5455
});
5556

5657
test('parseUrl', () => {

web_src/js/utils.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {decode, encode} from 'uint8-to-base64';
2-
import type {IssuePageInfo, IssuePathInfo} from './types.ts';
2+
import type {IssuePageInfo, IssuePathInfo, RepoOwnerPathInfo} from './types.ts';
33

44
// transform /path/to/file.ext to file.ext
55
export function basename(path: string): string {
@@ -37,11 +37,10 @@ export function parseIssueHref(href: string): IssuePathInfo {
3737
return {ownerName, repoName, pathType, indexString};
3838
}
3939

40-
export function parseIssueNewHref(href: string): IssuePathInfo {
40+
export function parseRepoOwnerPathInfo(href: string): RepoOwnerPathInfo {
4141
const path = (href || '').replace(/[#?].*$/, '');
42-
const [_, ownerName, repoName, pathTypeField] = /([^/]+)\/([^/]+)\/(issues\/new|compare\/.+\.\.\.)/.exec(path) || [];
43-
const pathType = pathTypeField ? (pathTypeField.startsWith('issues/new') ? 'issues' : 'pulls') : undefined;
44-
return {ownerName, repoName, pathType};
42+
const [_, ownerName, repoName] = /([^/]+)\/([^/]+)/.exec(path) || [];
43+
return {ownerName, repoName};
4544
}
4645

4746
export function parseIssuePageInfo(): IssuePageInfo {

0 commit comments

Comments
 (0)