Skip to content

Commit 1354c36

Browse files
authored
Merge pull request #569 from seungineer/#496-seunginner3
fix(view): 커밋 메시지의 PR or Issue number 하이퍼링크 버그
2 parents c2832ec + 8f0ebca commit 1354c36

File tree

8 files changed

+74
-27
lines changed

8 files changed

+74
-27
lines changed

packages/view/src/App.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type IDEPort from "ide/IDEPort";
99
import { useGlobalData } from "hooks";
1010
import { RefreshButton } from "components/RefreshButton";
1111
import type { IDESentEvents } from "types/IDESentEvents";
12+
import type { RemoteGitHubInfo } from "types/RemoteGitHubInfo";
1213

1314
const App = () => {
1415
const initRef = useRef<boolean>(false);
@@ -32,6 +33,18 @@ const App = () => {
3233
}
3334
}, [handleChangeAnalyzedData, handleChangeBranchList, ideAdapter, setLoading]);
3435

36+
const { setOwner, setRepo } = useGlobalData();
37+
useEffect(() => {
38+
const handleMessage = (event: MessageEvent<RemoteGitHubInfo>) => {
39+
const message = event.data;
40+
setOwner(message.data.owner);
41+
setRepo(message.data.repo);
42+
};
43+
44+
window.addEventListener("message", handleMessage);
45+
return () => window.removeEventListener("message", handleMessage);
46+
}, []);
47+
3548
if (loading) {
3649
return (
3750
<BounceLoader

packages/view/src/components/VerticalClusterList/Summary/Content/Content.tsx

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
1-
import React from "react";
1+
import React, { useEffect, useState } from "react";
22
import { IoIosArrowDropdownCircle, IoIosArrowDropupCircle } from "react-icons/io";
33

4+
import { useGlobalData } from "hooks";
5+
46
import type { ContentProps } from "../Summary.type";
57

68
const Content = ({ content, clusterId, selectedClusterId }: ContentProps) => {
7-
const str: string = content.message;
8-
const regex = /^(\(#[0-9]+\)|#[0-9]+)/g;
9-
const tobeStr: string[] = str.split(" ");
9+
const { owner, repo } = useGlobalData();
10+
const [linkedStr, setLinkedStr] = useState<React.ReactNode[]>([]);
11+
12+
useEffect(() => {
13+
const str: string = content.message;
14+
const regex = /^(\(#[0-9]+\)|#[0-9]+)/g;
15+
const tobeStr: string[] = str.split(" ");
1016

11-
const linkedStr = tobeStr.reduce((acc: React.ReactNode[], tokenStr: string) => {
12-
const matches = tokenStr.match(regex); // #num 으로 결과가 나옴 ()가 결과에 포함되지 않음
13-
if (matches) {
14-
const matchedStr = matches[0];
15-
const matchedStrNum: string = matchedStr.substring(1);
16-
const linkIssues = `https://github.com/githru/githru-vscode-ext/issues/${matchedStrNum}`;
17-
acc.push(
18-
<a
19-
href={linkIssues}
20-
key={`issues-${matchedStr}`}
21-
>
22-
{matchedStr}
23-
</a>
24-
);
25-
acc.push(" ");
26-
} else {
27-
acc.push(tokenStr);
28-
acc.push(" ");
29-
}
30-
return acc;
17+
const newLinkedStr = tobeStr.reduce((acc: React.ReactNode[], tokenStr: string) => {
18+
const matches = tokenStr.match(regex); // #num 으로 결과가 나옴 ()가 결과에 포함되지 않음
19+
if (matches) {
20+
const matchedStr = matches[0];
21+
const matchedStrNum: string = matchedStr.substring(1);
22+
const linkIssues = `https://github.com/${owner}/${repo}/issues/${matchedStrNum}`;
23+
acc.push(
24+
<a
25+
href={linkIssues}
26+
key={`issues-${matchedStr}`}
27+
>
28+
{matchedStr}
29+
</a>
30+
);
31+
acc.push(" ");
32+
} else {
33+
acc.push(tokenStr);
34+
acc.push(" ");
35+
}
36+
return acc;
37+
}, []);
38+
setLinkedStr(newLinkedStr);
3139
}, []);
3240

3341
return (

packages/view/src/context/GlobalDataProvider.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export const GlobalDataProvider = ({ children }: PropsWithChildren) => {
1414

1515
const [branchList, setBranchList] = useState<string[]>([]);
1616
const [selectedBranch, setSelectedBranch] = useState<string>(branchList?.[0]);
17+
const [owner, setOwner] = useState<string>("");
18+
const [repo, setRepo] = useState<string>("");
1719

1820
const handleChangeBranchList = (branches: { branchList: string[]; head: string | null }) => {
1921
setSelectedBranch((prev) => (!prev && branches.head ? branches.head : prev));
@@ -44,8 +46,12 @@ export const GlobalDataProvider = ({ children }: PropsWithChildren) => {
4446
setSelectedBranch,
4547
handleChangeAnalyzedData,
4648
handleChangeBranchList,
49+
owner,
50+
setOwner,
51+
repo,
52+
setRepo,
4753
}),
48-
[data, filteredRange, filteredData, selectedData, branchList, selectedBranch, loading]
54+
[data, filteredRange, filteredData, selectedData, branchList, selectedBranch, loading, owner, repo]
4955
);
5056

5157
return <GlobalDataContext.Provider value={value}>{children}</GlobalDataContext.Provider>;

packages/view/src/hooks/useGlobalData.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ type GlobalDataState = {
2424
setBranchList: Dispatch<SetStateAction<string[]>>;
2525
selectedBranch: string;
2626
setSelectedBranch: Dispatch<SetStateAction<string>>;
27+
owner: string;
28+
setOwner: Dispatch<SetStateAction<string>>;
29+
repo: string;
30+
setRepo: Dispatch<SetStateAction<string>>;
2731
} & IDESentEvents;
2832

2933
export const GlobalDataContext = createContext<GlobalDataState | undefined>(undefined);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface RemoteGitHubInfo {
2+
data: {
3+
owner: string;
4+
repo: string;
5+
};
6+
}

packages/vscode/src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export async function activate(context: vscode.ExtensionContext) {
7676
const fetchClusterNodes = async (baseBranchName = initialBaseBranchName) => {
7777
const gitLog = await getGitLog(gitPath, currentWorkspacePath);
7878
const gitConfig = await getGitConfig(gitPath, currentWorkspacePath, "origin");
79-
const { owner, repo } = getRepo(gitConfig);
79+
const { owner, repo: initialRepo } = getRepo(gitConfig);
80+
webLoader.setGlobalOwnerAndRepo(owner, initialRepo);
81+
const repo = initialRepo[0];
8082
const engine = new AnalysisEngine({
8183
isDebugMode: true,
8284
gitLog,

packages/vscode/src/utils/git.util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export async function getGitConfig(
208208

209209
export const getRepo = (gitRemoteConfig: string) => {
210210
const gitRemoteConfigPattern =
211-
/(?:https?|git)(?::\/\/(?:\w+@)?|@)(?:github\.com)(?:\/|:)(?:(?<owner>.+?)\/(?<repo>.+?))(?:\.git|\/)?(\S*)$/m;
211+
/(?:https?|git)(?::\/\/(?:\w+@)?|@)(?:github\.com)(?:\/|:)(?:(?<owner>[^/]+?)\/(?<repo>[^/.]+))(?:\.git|\/)?(\S*)$/m;
212212
const gitRemote = gitRemoteConfig.match(gitRemoteConfigPattern)?.groups;
213213
if (!gitRemote) {
214214
throw new Error("git remote config should be: [https?://|git@]${domain}/${owner}/${repo}.git");

packages/vscode/src/webview-loader.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ export default class WebviewLoader implements vscode.Disposable {
111111
`;
112112
return returnString;
113113
}
114+
public setGlobalOwnerAndRepo(owner: string, repo: string) {
115+
if (this._panel) {
116+
this._panel.webview.postMessage({
117+
command: "setGlobalOwnerAndRepo",
118+
data: { owner, repo },
119+
});
120+
}
121+
}
114122
}
115123

116124
type GithruFetcher<D = unknown, P extends unknown[] = []> = (...params: P) => Promise<D>;

0 commit comments

Comments
 (0)