0

Get Issue Picker Suggestions

by
Published Nov 2, 2023

Suggest issues matching a text query, as Jira's own issue picker does: matches from the user's history and from `current_jql`. Useful to resolve a fragment of a title or key to an issue.

Script jira Verified

The script

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

3
/**
4
 * Get Issue Picker Suggestions
5
 * Suggest issues matching a text query, as Jira's own issue picker does: matches from the user's history and from `current_jql`. Useful to resolve a fragment of a title or key to an issue.
6
 */
7
export async function main(
8
  auth: RT.Jira,
9
  query: string | undefined,
10
  current_jql: string | undefined,
11
  current_issue_key: string | undefined,
12
  current_project_id: string | undefined
13
) {
14
  const url = new URL(
15
    `https://${auth.domain}.atlassian.net/rest/api/3/issue/picker`
16
  )
17
  if (query != null && query !== "") {
18
    url.searchParams.append("query", query)
19
  }
20
  if (current_jql != null && current_jql !== "") {
21
    url.searchParams.append("currentJQL", current_jql)
22
  }
23
  if (current_issue_key != null && current_issue_key !== "") {
24
    url.searchParams.append("currentIssueKey", current_issue_key)
25
  }
26
  if (current_project_id != null && current_project_id !== "") {
27
    url.searchParams.append("currentProjectId", current_project_id)
28
  }
29

30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
34
      Accept: "application/json",
35
    },
36
  })
37

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

42
  return await response.json()
43
}
44

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 532 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Get issue picker suggestions
    8
     * Returns lists of issues matching a query string.
    9
     */
    10
    export async function main(
    11
      auth: Jira,
    12
      query: string | undefined,
    13
      currentJQL: string | undefined,
    14
      currentIssueKey: string | undefined,
    15
      currentProjectId: string | undefined,
    16
      showSubTasks: string | undefined,
    17
      showSubTaskParent: string | undefined
    18
    ) {
    19
      const url = new URL(
    20
        `https://${auth.domain}.atlassian.net/rest/api/2/issue/picker`
    21
      );
    22
      for (const [k, v] of [
    23
        ["query", query],
    24
        ["currentJQL", currentJQL],
    25
        ["currentIssueKey", currentIssueKey],
    26
        ["currentProjectId", currentProjectId],
    27
        ["showSubTasks", showSubTasks],
    28
        ["showSubTaskParent", showSubTaskParent],
    29
      ]) {
    30
        if (v !== undefined && v !== "") {
    31
          url.searchParams.append(k, v);
    32
        }
    33
      }
    34
      const response = await fetch(url, {
    35
        method: "GET",
    36
        headers: {
    37
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    38
        },
    39
        body: undefined,
    40
      });
    41
      if (!response.ok) {
    42
        const text = await response.text();
    43
        throw new Error(`${response.status} ${text}`);
    44
      }
    45
      return await response.json();
    46
    }
    47