* Resolves the top-level parent comment node ID for GitHub Discussion replies. * GitHub Discussions only supports two nesting levels: top-level comments and one level of replies. * If the given comment is itself a reply (has a replyTo parent), the parent's node ID is returned * so that replyToId
(github, commentNodeId)
| 152 | * @returns {Promise<string|null|undefined>} The node ID to use as replyToId (parent if reply, otherwise the original) |
| 153 | */ |
| 154 | async function resolveTopLevelDiscussionCommentId(github, commentNodeId) { |
| 155 | if (!commentNodeId) { |
| 156 | return commentNodeId; |
| 157 | } |
| 158 | try { |
| 159 | const result = await github.graphql( |
| 160 | `query($nodeId: ID!) { |
| 161 | node(id: $nodeId) { |
| 162 | ... on DiscussionComment { |
| 163 | replyTo { |
| 164 | id |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | }`, |
| 169 | { nodeId: commentNodeId } |
| 170 | ); |
| 171 | return result?.node?.replyTo?.id ?? commentNodeId; |
| 172 | } catch (error) { |
| 173 | logGraphQLError(/** @type {Error & { errors?: Array<{ type?: string, message: string, path?: unknown, locations?: unknown }>, request?: unknown, data?: unknown, status?: number }} */ error, "resolving top-level discussion comment"); |
| 174 | return commentNodeId; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | module.exports = { |
| 179 | fetchAllRepoLabels, |
no test coverage detected