Edits history of script submission #23007 for ' List Projects (linear)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Projects
     * List the projects in the workspace, most recently updated first. Paginate with after = pageInfo.endCursor.
     */
    export async function main(
      auth: RT.Linear,
      include_archived: boolean = false,
      first: number = 50,
      after: 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: `query ($includeArchived: Boolean, $first: Int, $after: String) { projects(includeArchived: $includeArchived, first: $first, after: $after, orderBy: updatedAt) { nodes { id name description url progress startDate targetDate status { id name type } lead { id name } teams { nodes { id key } } } pageInfo { hasNextPage endCursor } } }`,
          variables: {
            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.projects
    }
    

    Submitted by hugo989 1 hour ago