Edits history of script submission #23257 for ' List Initiatives (linear)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Initiatives
     * List initiatives, most recently updated first, optionally filtered by name (contains, case-insensitive) or status. Paginate with after = pageInfo.endCursor.
     */
    export async function main(
      auth: RT.Linear,
      name: string | undefined,
      status:
        "Planned" | "Active" | "Completed" | "Proposed" | "Canceled" | undefined,
      include_archived: boolean = false,
      first: number = 50,
      after: string | undefined
    ) {
      const filter: { [key: string]: any } = {}
      if (name) filter.name = { containsIgnoreCase: name }
      if (status) filter.status = { eq: status }
      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: `query ($filter: InitiativeFilter, $includeArchived: Boolean, $first: Int, $after: String) { initiatives(filter: $filter, includeArchived: $includeArchived, first: $first, after: $after, orderBy: updatedAt) { nodes { id name description url status health targetDate createdAt updatedAt archivedAt owner { id name } projects { nodes { id name } } } pageInfo { hasNextPage endCursor } } }`,
          variables: {
            filter,
            includeArchived: include_archived,
            first,
            after: after || 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.initiatives
    }
    

    Submitted by hugo989 2 hours ago