//native
export type DynSelect_team_id = string
// Dropdown of the workspace's teams.
export async function team_id(auth: RT.Linear) {
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: "{ teams(first: 250) { nodes { id key name } } }",
}),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { data } = (await response.json()) as {
data: { teams: { nodes: { id: string; key: string; name: string }[] } }
}
return data.teams.nodes.map((t) => ({
value: t.id,
label: `${t.name} (${t.key})`,
}))
}
/**
* Create Issue
* Create an issue in a team. Set parent_id to create it as a sub-issue. Priority: 0 none, 1 urgent, 2 high, 3 medium, 4 low. Description is Markdown.
*/
export async function main(
auth: RT.Linear,
team_id: DynSelect_team_id,
title: string,
description: string | undefined,
assignee_id: string | undefined,
state_id: string | undefined,
priority: number | undefined,
due_date: string | undefined,
label_ids: string[] | undefined,
project_id: string | undefined,
cycle_id: string | undefined,
parent_id: 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: `mutation ($input: IssueCreateInput!) { issueCreate(input: $input) { success issue { 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 } } } } }`,
variables: {
input: {
teamId: team_id,
title,
description: description || undefined,
assigneeId: assignee_id || undefined,
stateId: state_id || undefined,
priority,
dueDate: due_date || undefined,
labelIds: label_ids?.length ? label_ids : undefined,
projectId: project_id || undefined,
cycleId: cycle_id || undefined,
parentId: parent_id || 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.issueCreate
}
Submitted by hugo989 1 hour ago