| 66 | } |
| 67 | |
| 68 | function getComments (issue) { |
| 69 | const { owner, repo, perPage, pagerDirection, defaultAuthor } = this.options |
| 70 | const { cursor, comments } = this.state |
| 71 | return axiosGithub.post( |
| 72 | '/graphql', |
| 73 | getQL( |
| 74 | { |
| 75 | owner, |
| 76 | repo, |
| 77 | id: issue.number, |
| 78 | pageSize: perPage, |
| 79 | cursor |
| 80 | }, |
| 81 | pagerDirection |
| 82 | ), { |
| 83 | headers: { |
| 84 | Authorization: `bearer ${this.accessToken}` |
| 85 | } |
| 86 | } |
| 87 | ).then(res => { |
| 88 | const data = res.data.data.repository.issue.comments |
| 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 | }) |
| 107 | |
| 108 | let cs |
| 109 | |
| 110 | if (pagerDirection === 'last') { |
| 111 | cs = [...items, ...comments] |
| 112 | } else { |
| 113 | cs = [...comments, ...items] |
| 114 | } |
| 115 | |
| 116 | const isLoadOver = data.pageInfo.hasPreviousPage === false || data.pageInfo.hasNextPage === false |
| 117 | this.setState({ |
| 118 | comments: cs, |
| 119 | isLoadOver, |
| 120 | cursor: data.pageInfo.startCursor || data.pageInfo.endCursor |
| 121 | }) |
| 122 | return cs |
| 123 | }) |
| 124 | } |
| 125 | |