0

Create Comment

by
Published today

Post a Markdown comment on an issue.

Script linear Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 1 hour ago
1
//native
2

3
/**
4
 * Create Comment
5
 * Post a Markdown comment on an issue. Set parent_id to reply in a comment thread.
6
 */
7
export async function main(
8
  auth: RT.Linear,
9
  issue_id: string,
10
  body: string,
11
  parent_id: string | undefined
12
) {
13
  const response = await fetch("https://api.linear.app/graphql", {
14
    method: "POST",
15
    headers: {
16
      Authorization: auth.apiKey,
17
      "Content-Type": "application/json",
18
      Accept: "application/json",
19
    },
20
    body: JSON.stringify({
21
      query: `mutation ($input: CommentCreateInput!) { commentCreate(input: $input) { success comment { id body url createdAt user { id name } } } }`,
22
      variables: {
23
        input: { issueId: issue_id, body, parentId: parent_id || undefined },
24
      },
25
    }),
26
  })
27

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`)
30
  }
31

32
  const { data, errors } = await response.json()
33
  if (errors) {
34
    throw new Error(JSON.stringify(errors))
35
  }
36

37
  return data.commentCreate
38
}
39