//native
/**
* Create Comment
* Post a Markdown comment on an issue. Set parent_id to reply in a comment thread.
*/
export async function main(
auth: RT.Linear,
issue_id: string,
body: string,
parent_id: string | undefined
) {
const response = await fetch("https://api.linear.app/graphql", {
method: "POST",
headers: {
Authorization: auth.apiKey,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query: `mutation ($input: CommentCreateInput!) { commentCreate(input: $input) { success comment { id body url createdAt user { id name } } } }`,
variables: {
input: { issueId: issue_id, body, parentId: parent_id || undefined },
},
}),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { data, errors } = await response.json()
if (errors) {
throw new Error(JSON.stringify(errors))
}
return data.commentCreate
}
Submitted by hugo989 1 hour ago