* Execute the discussion update API call using GraphQL * @param {any} github - GitHub API client * @param {any} context - GitHub Actions context * @param {number} discussionNumber - Discussion number to update * @param {any} updateData - Data to update * @returns {Promise } Updated discussi
(github, context, discussionNumber, updateData)
| 113 | * @returns {Promise<any>} Updated discussion |
| 114 | */ |
| 115 | async function executeDiscussionUpdate(github, context, discussionNumber, updateData) { |
| 116 | // First, fetch the discussion node ID |
| 117 | const getDiscussionQuery = ` |
| 118 | query($owner: String!, $repo: String!, $number: Int!) { |
| 119 | repository(owner: $owner, name: $repo) { |
| 120 | discussion(number: $number) { |
| 121 | id |
| 122 | title |
| 123 | body |
| 124 | url |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | `; |
| 129 | |
| 130 | let queryResult; |
| 131 | try { |
| 132 | queryResult = await github.graphql(getDiscussionQuery, { |
| 133 | owner: context.repo.owner, |
| 134 | repo: context.repo.repo, |
| 135 | number: discussionNumber, |
| 136 | }); |
| 137 | } catch (err) { |
| 138 | // prettier-ignore |
| 139 | const fetchError = /** @type {any} */ (err); |
| 140 | logGraphQLError(fetchError, `fetch discussion #${discussionNumber} from ${context.repo.owner}/${context.repo.repo}`, DISCUSSION_GRAPHQL_HINTS); |
| 141 | throw fetchError; |
| 142 | } |
| 143 | |
| 144 | const discussion = queryResult?.repository?.discussion; |
| 145 | if (!discussion) { |
| 146 | throw new Error(`${ERR_NOT_FOUND}: Discussion #${discussionNumber} not found`); |
| 147 | } |
| 148 | |
| 149 | const hasTitleUpdate = updateData.title !== undefined; |
| 150 | const hasBodyUpdate = updateData.body !== undefined; |
| 151 | const hasLabelsUpdate = updateData.labels !== undefined; |
| 152 | |
| 153 | let updatedDiscussion = discussion; |
| 154 | |
| 155 | // Only call the updateDiscussion mutation when title or body actually needs updating. |
| 156 | // Skipping this when only labels are being changed avoids accidentally modifying |
| 157 | // the discussion body with stale or unexpected content. |
| 158 | if (hasTitleUpdate || hasBodyUpdate) { |
| 159 | const mutation = ` |
| 160 | mutation($discussionId: ID!, $title: String, $body: String) { |
| 161 | updateDiscussion(input: { discussionId: $discussionId, title: $title, body: $body }) { |
| 162 | discussion { |
| 163 | id |
| 164 | title |
| 165 | body |
| 166 | url |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | `; |
| 171 | |
| 172 | const variables = { |
nothing calls this directly
no test coverage detected