({
entity,
graphApi,
vaultClient,
}: {
entity: HashEntity;
graphApi: GraphApi;
vaultClient: VaultClient;
})
| 36 | ]; |
| 37 | |
| 38 | export const processEntityChange = async ({ |
| 39 | entity, |
| 40 | graphApi, |
| 41 | vaultClient, |
| 42 | }: { |
| 43 | entity: HashEntity; |
| 44 | graphApi: GraphApi; |
| 45 | vaultClient: VaultClient; |
| 46 | }) => { |
| 47 | const { entityTypeIds } = entity.metadata; |
| 48 | |
| 49 | if ( |
| 50 | !entityTypeIds.some( |
| 51 | (entityTypeId) => !supportedLinearTypeIds.includes(entityTypeId), |
| 52 | ) |
| 53 | ) { |
| 54 | throw new Error( |
| 55 | `Entity with entity type(s) ${entityTypeIds.join(", ")} passed to Linear sync back processor – supported types are ${supportedLinearEntityTypeIds.join( |
| 56 | ", ", |
| 57 | )}.`, |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | const linearMachineActorId = await getMachineIdByIdentifier( |
| 62 | { graphApi }, |
| 63 | { actorId: systemAccountId }, |
| 64 | { identifier: "linear" }, |
| 65 | ).then((maybeMachineId) => { |
| 66 | if (!maybeMachineId) { |
| 67 | throw new Error("Failed to get linear bot"); |
| 68 | } |
| 69 | return maybeMachineId; |
| 70 | }); |
| 71 | |
| 72 | if (entity.metadata.provenance.edition.createdById === linearMachineActorId) { |
| 73 | /** |
| 74 | * To prevent update loops where changes from linear are saved in HASH, and |
| 75 | * then propagate back to linear, only consider entity editions that weren't |
| 76 | * created by the Linear machine account's actorId. |
| 77 | */ |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | const graphContext: ImpureGraphContext = { |
| 82 | graphApi, |
| 83 | provenance: { |
| 84 | actorType: "machine", |
| 85 | origin: { |
| 86 | /** |
| 87 | * @todo use correct EntityId for Flow when Linear integration migrated to Flows |
| 88 | */ |
| 89 | id: "linear-integration", |
| 90 | type: "flow", |
| 91 | }, |
| 92 | }, |
| 93 | }; |
| 94 | |
| 95 | const linearEntityToUpdate = entityTypeIds.some( |
nothing calls this directly
no test coverage detected