-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
1,086 additions
and
1,155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
connectors/migrations/20241216_backfill_confluence_folders.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { makeScript } from "scripts/helpers"; | ||
|
||
import { makeSpaceInternalId } from "@connectors/connectors/confluence/lib/internal_ids"; | ||
import { dataSourceConfigFromConnector } from "@connectors/lib/api/data_source_config"; | ||
import { concurrentExecutor } from "@connectors/lib/async_utils"; | ||
import { upsertFolderNode } from "@connectors/lib/data_sources"; | ||
import { ConfluenceSpace } from "@connectors/lib/models/confluence"; | ||
import { ConnectorResource } from "@connectors/resources/connector_resource"; | ||
|
||
const FOLDER_CONCURRENCY = 10; | ||
|
||
makeScript({}, async ({ execute }, logger) => { | ||
const connectors = await ConnectorResource.listByType("confluence", {}); | ||
|
||
for (const connector of connectors) { | ||
const confluenceSpaces = await ConfluenceSpace.findAll({ | ||
attributes: ["spaceId", "name"], | ||
where: { connectorId: connector.id }, | ||
}); | ||
const dataSourceConfig = dataSourceConfigFromConnector(connector); | ||
if (execute) { | ||
await concurrentExecutor( | ||
confluenceSpaces, | ||
async (space) => { | ||
await upsertFolderNode({ | ||
dataSourceConfig, | ||
folderId: makeSpaceInternalId(space.spaceId), | ||
parents: [makeSpaceInternalId(space.spaceId)], | ||
title: space.name, | ||
}); | ||
}, | ||
{ concurrency: FOLDER_CONCURRENCY } | ||
); | ||
logger.info( | ||
`Upserted ${confluenceSpaces.length} spaces for connector ${connector.id}` | ||
); | ||
} else { | ||
logger.info( | ||
`Found ${confluenceSpaces.length} spaces for connector ${connector.id}` | ||
); | ||
} | ||
} | ||
}); |
95 changes: 95 additions & 0 deletions
95
connectors/migrations/20241216_backfill_zendesk_folders.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { makeScript } from "scripts/helpers"; | ||
|
||
import { getBrandInternalId } from "@connectors/connectors/zendesk/lib/id_conversions"; | ||
import { dataSourceConfigFromConnector } from "@connectors/lib/api/data_source_config"; | ||
import { concurrentExecutor } from "@connectors/lib/async_utils"; | ||
import { upsertFolderNode } from "@connectors/lib/data_sources"; | ||
import { ConnectorResource } from "@connectors/resources/connector_resource"; | ||
import { | ||
ZendeskBrandResource, | ||
ZendeskCategoryResource, | ||
} from "@connectors/resources/zendesk_resources"; | ||
|
||
const FOLDER_CONCURRENCY = 10; | ||
|
||
makeScript({}, async ({ execute }, logger) => { | ||
const connectors = await ConnectorResource.listByType("zendesk", {}); | ||
|
||
for (const connector of connectors) { | ||
const dataSourceConfig = dataSourceConfigFromConnector(connector); | ||
const connectorId = connector.id; | ||
|
||
const brands = await ZendeskBrandResource.fetchByConnector(connector); | ||
if (execute) { | ||
await concurrentExecutor( | ||
brands, | ||
async (brand) => { | ||
/// same code as in the connector | ||
const brandInternalId = getBrandInternalId({ | ||
connectorId, | ||
brandId: brand.brandId, | ||
}); | ||
await upsertFolderNode({ | ||
dataSourceConfig, | ||
folderId: brandInternalId, | ||
parents: [brandInternalId], | ||
title: brand.name, | ||
}); | ||
|
||
const helpCenterNode = brand.getHelpCenterContentNode(connectorId); | ||
await upsertFolderNode({ | ||
dataSourceConfig, | ||
folderId: helpCenterNode.internalId, | ||
parents: [ | ||
helpCenterNode.internalId, | ||
helpCenterNode.parentInternalId, | ||
], | ||
title: helpCenterNode.title, | ||
}); | ||
|
||
const ticketsNode = brand.getTicketsContentNode(connectorId); | ||
await upsertFolderNode({ | ||
dataSourceConfig, | ||
folderId: ticketsNode.internalId, | ||
parents: [ticketsNode.internalId, ticketsNode.parentInternalId], | ||
title: ticketsNode.title, | ||
}); | ||
}, | ||
{ concurrency: FOLDER_CONCURRENCY } | ||
); | ||
logger.info( | ||
`Upserted ${brands.length} spaces for connector ${connector.id}` | ||
); | ||
} else { | ||
logger.info( | ||
`Found ${brands.length} spaces for connector ${connector.id}` | ||
); | ||
} | ||
|
||
const categories = | ||
await ZendeskCategoryResource.fetchByConnector(connector); | ||
if (execute) { | ||
await concurrentExecutor( | ||
categories, | ||
async (category) => { | ||
/// same code as in the connector | ||
const parents = category.getParentInternalIds(connectorId); | ||
await upsertFolderNode({ | ||
dataSourceConfig: dataSourceConfigFromConnector(connector), | ||
folderId: parents[0], | ||
parents, | ||
title: category.name, | ||
}); | ||
}, | ||
{ concurrency: FOLDER_CONCURRENCY } | ||
); | ||
logger.info( | ||
`Upserted ${brands.length} spaces for connector ${connector.id}` | ||
); | ||
} else { | ||
logger.info( | ||
`Found ${brands.length} spaces for connector ${connector.id}` | ||
); | ||
} | ||
} | ||
}); |
Oops, something went wrong.