Edits history of script submission #23003 for ' List Comments (linear)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Comments
     * List the comments on an issue, oldest first. Paginate with after = pageInfo.endCursor.
     */
    export async function main(
      auth: RT.Linear,
      issue_id: string,
      first: number = 50,
      after: 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: `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 } } } }`,
          variables: { id: issue_id, first, after: after || 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.issue.comments
    }
    

    Submitted by hugo989 1 hour ago