-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommit.tsx
More file actions
85 lines (80 loc) · 2.22 KB
/
commit.tsx
File metadata and controls
85 lines (80 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { PullRequestOutlined } from '@ant-design/icons';
import { Button, Popover } from 'antd';
import dayjs from 'dayjs';
import gitUrlParse from 'git-url-parse';
export const Commit = ({ commit }: { commit?: Commit }) => {
if (!commit) {
return (
<Popover
className="ant-typography-edit"
content={
<div>
<div className="text-center my-1 mx-auto">
<div className="font-bold">最近的提交:</div>
<div className="text-gray-500">
需要使用 cli v1.42.0+ 版本上传,且使用 git
管理代码才能查看提交记录
</div>
</div>
</div>
}
>
<Button type="link" icon={<PullRequestOutlined />} onClick={() => {}} />
</Popover>
);
}
const { origin, hash, message, author } = commit;
let url = '';
if (origin) {
try {
const { owner, name, source } = gitUrlParse(origin);
url = `https://${source}/${owner}/${name}/commit/${hash}`;
} catch (error) {
console.error(error);
}
}
// Validate URL protocol to prevent XSS
if (url) {
try {
const parsed = new URL(url);
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
url = '';
}
} catch {
url = '';
}
}
const time = dayjs(+commit.timestamp * 1000);
return (
<Popover
className="ant-typography-edit"
content={
<div>
<div className="my-1 mx-auto">
<div className="font-bold">最近的提交:</div>
<div>作者:{author}</div>
<div>
时间:{time.fromNow()}({time.format('YYYY-MM-DD HH:mm:ss')})
</div>
<div>摘要:{message}</div>
<hr />
{url ? (
<a
className="text-xs"
href={url}
target="_blank"
rel="noopener noreferrer"
>
{hash}
</a>
) : (
<span className="text-xs">{hash}</span>
)}
</div>
</div>
}
>
<Button type="link" icon={<PullRequestOutlined />} onClick={() => {}} />
</Popover>
);
};