0

List Comments

by
Published today

List the comments on an issue.

Script linear Verified

The script

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

3
/**
4
 * List Comments
5
 * List the comments on an issue, oldest first. Paginate with after = pageInfo.endCursor.
6
 */
7
export async function main(
8
  auth: RT.Linear,
9
  issue_id: string,
10
  first: number = 50,
11
  after: 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: `query ($id: String!, $first: Int, $after: String) { issue(id: $id) { comments(first: $first, after: $after) { nodes { id body url createdAt updatedAt user { id name email } parent { id } } pageInfo { hasNextPage endCursor } } } }`,
22
      variables: { id: issue_id, first, after: after || undefined },
23
    }),
24
  })
25

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

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

35
  return data.issue.comments
36
}
37