Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
61 lines (61 loc) · 1.74 KB
/
Copy pathutils.js
File metadata and controls
61 lines (61 loc) · 1.74 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
export function normalizeUser(user) {
// workaround for deleted user
// @see https://github.community/t5/GitHub-API-Development-and/Keep-deleted-issue-author-as-ghost/td-p/15456
if (user === null) {
return {
username: 'ghost',
avatar: 'https://avatars3.githubusercontent.com/u/10137?v=4',
homepage: 'https://github.com/ghost',
};
}
return {
username: user.login,
avatar: user.avatarUrl,
homepage: user.url,
};
}
export function normalizeIssue(issue) {
return {
id: issue.number,
title: issue.title,
content: issue.body,
link: issue.url,
};
}
export function normalizeReactions(reactions) {
return {
like: reactions.find(item => item.content === 'THUMBS_UP').users
.totalCount,
unlike: reactions.find(item => item.content === 'THUMBS_DOWN').users
.totalCount,
heart: reactions.find(item => item.content === 'HEART').users.totalCount,
};
}
export function normalizeComment(comment) {
return {
id: comment.id,
content: comment.bodyHTML,
contentRaw: comment.body,
author: normalizeUser(comment.author),
createdAt: comment.createdAt,
updatedAt: comment.updatedAt,
reactions: normalizeReactions(comment.reactionGroups),
};
}
export function mapReactionName(reaction) {
if (reaction === 'like')
return 'THUMBS_UP';
if (reaction === 'unlike')
return 'THUMBS_DOWN';
if (reaction === 'heart')
return 'HEART';
return reaction;
}
export default {
normalizeUser,
normalizeIssue,
normalizeComment,
normalizeReactions,
mapReactionName,
};
//# sourceMappingURL=utils.js.map