Edits history of script submission #23251 for ' Create Project Update (linear)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Project Update
     * Post a status update on a project. body is Markdown. Health: onTrack, atRisk, offTrack.
     */
    export async function main(
      auth: RT.Linear,
      project_id: string,
      body: string,
      health: "onTrack" | "atRisk" | "offTrack" | 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: ProjectUpdateCreateInput!) { projectUpdateCreate(input: $input) { success projectUpdate { id body health url createdAt updatedAt user { id name } project { id name } } } }`,
          variables: {
            input: { projectId: project_id, body, health: health || 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.projectUpdateCreate
    }
    

    Submitted by hugo989 2 hours ago