Skip to content

Commit 5860202

Browse files
committed
fix: occur error when author is null
close gitalk#160
1 parent 05c8287 commit 5860202

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/gitalk.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class GitalkComponent extends Component {
7070

7171
url: location.href,
7272

73+
defaultAuthor: {
74+
avatarUrl: '//avatars1.githubusercontent.com/u/29697133?s=50',
75+
login: 'null',
76+
url: '',
77+
},
78+
7379
updateCountCallback: null
7480
}, props.options)
7581

src/graphql/getComments.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const getQL = (vars, pagerDirection) => {
6666
}
6767

6868
function getComments (issue) {
69-
const { owner, repo, perPage, pagerDirection } = this.options
69+
const { owner, repo, perPage, pagerDirection, defaultAuthor } = this.options
7070
const { cursor, comments } = this.state
7171
return axiosGithub.post(
7272
'/graphql',
@@ -86,20 +86,24 @@ function getComments (issue) {
8686
}
8787
).then(res => {
8888
const data = res.data.data.repository.issue.comments
89-
const items = data.nodes.map(node => ({
90-
id: node.databaseId,
91-
gId: node.id,
92-
user: {
93-
avatar_url: node.author.avatarUrl,
94-
login: node.author.login,
95-
html_url: node.author.url
96-
},
97-
created_at: node.createdAt,
98-
body_html: node.bodyHTML,
99-
body: node.body,
100-
html_url: `https://github.com/${owner}/${repo}/issues/${issue.number}#issuecomment-${node.databaseId}`,
101-
reactions: node.reactions
102-
}))
89+
const items = data.nodes.map(node => {
90+
const author = node.author || defaultAuthor
91+
92+
return {
93+
id: node.databaseId,
94+
gId: node.id,
95+
user: {
96+
avatar_url: author.avatarUrl,
97+
login: author.login,
98+
html_url: author.url
99+
},
100+
created_at: node.createdAt,
101+
body_html: node.bodyHTML,
102+
body: node.body,
103+
html_url: `https://github.com/${owner}/${repo}/issues/${issue.number}#issuecomment-${node.databaseId}`,
104+
reactions: node.reactions
105+
}
106+
})
103107

104108
let cs
105109

0 commit comments

Comments
 (0)