Edits history of script submission #23000 for ' Create Label (linear)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Label
     * Create an issue label. Leave team_id empty for a workspace-wide label. color is a hex string such as #5e6ad2.
     */
    export async function main(
      auth: RT.Linear,
      name: string,
      team_id: string | undefined,
      color: string | undefined,
      description: string | undefined,
      parent_id: 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: IssueLabelCreateInput!) { issueLabelCreate(input: $input) { success issueLabel { id name color description team { id key } } } }`,
          variables: {
            input: {
              name,
              teamId: team_id || undefined,
              color: color || undefined,
              description: description || undefined,
              parentId: parent_id || 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.issueLabelCreate
    }
    

    Submitted by hugo989 1 hour ago