0

Search Issues

by
Published today

Full-text search over issue titles and descriptions (optionally comments).

Script linear Verified

The script

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

3
/**
4
 * Search Issues
5
 * Full-text search over issue titles and descriptions, optionally including comments. Results from team_id are ranked higher. Paginate with after = pageInfo.endCursor.
6
 */
7
export async function main(
8
  auth: RT.Linear,
9
  term: string,
10
  team_id: string | undefined,
11
  include_comments: boolean = false,
12
  include_archived: boolean = false,
13
  first: number = 25,
14
  after: string | undefined
15
) {
16
  const response = await fetch("https://api.linear.app/graphql", {
17
    method: "POST",
18
    headers: {
19
      Authorization: auth.apiKey,
20
      "Content-Type": "application/json",
21
      Accept: "application/json",
22
    },
23
    body: JSON.stringify({
24
      query: `query ($term: String!, $teamId: String, $includeComments: Boolean, $includeArchived: Boolean, $first: Int, $after: String) { searchIssues(term: $term, teamId: $teamId, includeComments: $includeComments, includeArchived: $includeArchived, first: $first, after: $after) { nodes { id identifier title description url priority priorityLabel estimate dueDate createdAt updatedAt archivedAt state { id name type } assignee { id name email } team { id key name } project { id name } cycle { id number } parent { id identifier } labels { nodes { id name } } } pageInfo { hasNextPage endCursor } totalCount } }`,
25
      variables: {
26
        term,
27
        teamId: team_id || undefined,
28
        includeComments: include_comments,
29
        includeArchived: include_archived,
30
        first,
31
        after: after || undefined,
32
      },
33
    }),
34
  })
35

36
  if (!response.ok) {
37
    throw new Error(`${response.status} ${await response.text()}`)
38
  }
39

40
  const { data, errors } = await response.json()
41
  if (errors) {
42
    throw new Error(JSON.stringify(errors))
43
  }
44

45
  return data.searchIssues
46
}
47