Edits history of script submission #23013 for ' Update Issue (linear)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Update Issue
     * Update an issue. Only the fields you set are changed. added_label_ids / removed_label_ids add or remove labels without touching the others. Priority: 0 none, 1 urgent, 2 high, 3 medium, 4 low.
     */
    export async function main(
      auth: RT.Linear,
      issue_id: string,
      title: string | undefined,
      description: string | undefined,
      state_id: string | undefined,
      assignee_id: string | undefined,
      priority: number | undefined,
      due_date: string | undefined,
      project_id: string | undefined,
      cycle_id: string | undefined,
      parent_id: string | undefined,
      added_label_ids: string[] | undefined,
      removed_label_ids: 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 ($id: String!, $input: IssueUpdateInput!) { issueUpdate(id: $id, 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: {
            id: issue_id,
            input: {
              title: title || undefined,
              description: description || undefined,
              stateId: state_id || undefined,
              assigneeId: assignee_id || undefined,
              priority,
              dueDate: due_date || undefined,
              projectId: project_id || undefined,
              cycleId: cycle_id || undefined,
              parentId: parent_id || undefined,
              addedLabelIds: added_label_ids?.length ? added_label_ids : undefined,
              removedLabelIds: removed_label_ids?.length
                ? removed_label_ids
                : 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.issueUpdate
    }
    

    Submitted by hugo989 1 hour ago