//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 Project
* Create a project owned by a team. Dates are YYYY-MM-DD. Priority: 0 none, 1 urgent, 2 high, 3 medium, 4 low.
*/
export async function main(
auth: RT.Linear,
team_id: DynSelect_team_id,
name: string,
description: string | undefined,
lead_id: string | undefined,
member_ids: string[] | undefined,
priority: number | undefined,
start_date: string | undefined,
target_date: 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: ProjectCreateInput!) { projectCreate(input: $input) { success project { id name description url startDate targetDate status { id name type } lead { id name } } } }`,
variables: {
input: {
teamIds: [team_id],
name,
description: description || undefined,
leadId: lead_id || undefined,
memberIds: member_ids?.length ? member_ids : undefined,
priority,
startDate: start_date || undefined,
targetDate: target_date || 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.projectCreate
}
Submitted by hugo989 1 hour ago