Skip to content

Commit d4bbfab

Browse files
authored
Adding zendesk exclude org option (#75)
Signed-off-by: Denis Jannot <denis.jannot@solo.io>
1 parent 089212f commit d4bbfab

4 files changed

Lines changed: 35 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ Configuration is managed through two files:
218218
* `start_date`: (Optional) Only process tickets/articles updated since this date (e.g., `'2025-01-01'`).
219219
* `ticket_status`: (Optional) Filter tickets by status (defaults to `['new', 'open', 'pending', 'hold', 'solved']`).
220220
* `ticket_priority`: (Optional) Filter tickets by priority (defaults to all priorities).
221+
* `excluded_organizations`: (Optional) An array of Zendesk organization names whose tickets should be skipped. The sync will abort if any name cannot be resolved.
221222

222223
For S3 buckets (`type: 's3'`):
223224
* `bucket`: The S3 bucket name.
@@ -359,6 +360,7 @@ Configuration is managed through two files:
359360
start_date: '2025-01-01'
360361
ticket_status: ['open', 'pending']
361362
ticket_priority: ['high']
363+
excluded_organizations: ['Acme Corp', 'Internal Testing']
362364
max_size: 1048576
363365
database_config:
364366
type: 'sqlite'

doc2vec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,9 @@ export class Doc2Vec {
13261326
// transitioning to closed get updated rather than left stale)
13271327
const statusFilter = new Set(config.ticket_status || ['new', 'open', 'pending', 'hold', 'solved', 'closed']);
13281328

1329+
const excludedOrgNames = new Set((config.excluded_organizations || []).map(n => n.toLowerCase()));
1330+
const excludedOrgIds = new Set<number>();
1331+
13291332
const fetchWithRetry = async (url: string, retries = 3): Promise<any> => {
13301333
for (let attempt = 0; attempt < retries; attempt++) {
13311334
try {
@@ -1409,6 +1412,12 @@ export class Doc2Vec {
14091412
return;
14101413
}
14111414

1415+
// Skip tickets belonging to excluded organizations
1416+
if (ticket.organization_id && excludedOrgIds.has(ticket.organization_id)) {
1417+
logger.debug(`Ticket #${ticketId} belongs to excluded organization ${ticket.organization_id} — skipping`);
1418+
return;
1419+
}
1420+
14121421
// Skip tickets whose status is outside the configured filter
14131422
if (!statusFilter.has(ticket.status)) {
14141423
logger.debug(`Ticket #${ticketId} has status '${ticket.status}' outside configured filter — skipping`);
@@ -1441,6 +1450,28 @@ export class Doc2Vec {
14411450
await this.processChunksForUrl(chunks, url, dbConnection, logger);
14421451
};
14431452

1453+
if (excludedOrgNames.size > 0) {
1454+
logger.info(`Resolving ${excludedOrgNames.size} excluded organization name(s) to IDs`);
1455+
const resolvedNames = new Set<string>();
1456+
let orgsUrl: string | null = `${baseUrl}/organizations.json?page[size]=100`;
1457+
while (orgsUrl) {
1458+
const orgsData: any = await fetchWithRetry(orgsUrl);
1459+
for (const org of orgsData?.organizations || []) {
1460+
const orgName = (org.name || '').toLowerCase();
1461+
if (excludedOrgNames.has(orgName)) {
1462+
excludedOrgIds.add(org.id);
1463+
resolvedNames.add(orgName);
1464+
}
1465+
}
1466+
orgsUrl = orgsData?.meta?.has_more ? orgsData?.links?.next : null;
1467+
}
1468+
logger.info(`Excluding tickets from ${excludedOrgIds.size} organization(s): ${[...excludedOrgIds].join(', ')}`);
1469+
const unresolved = [...excludedOrgNames].filter(name => !resolvedNames.has(name));
1470+
if (unresolved.length > 0) {
1471+
throw new Error(`Cannot resolve excluded organization(s): ${unresolved.join(', ')}. Aborting to avoid syncing data for them.`);
1472+
}
1473+
}
1474+
14441475
logger.info(`Fetching Zendesk tickets updated since ${lastRunDate}`);
14451476

14461477
// Build query parameters — use the status filter for the search query

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "doc2vec",
3-
"version": "2.9.2",
3+
"version": "2.10.0",
44
"type": "commonjs",
55
"description": "",
66
"main": "dist/doc2vec.js",

types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface ZendeskSourceConfig extends BaseSourceConfig {
4444
start_date?: string; // For incremental updates (default: start of current year)
4545
ticket_status?: string[]; // Filter tickets by status (default: ['new', 'open', 'pending', 'hold', 'solved'])
4646
ticket_priority?: string[]; // Filter tickets by priority (default: all)
47+
excluded_organizations?: string[]; // Organization names whose tickets should be skipped
4748
}
4849

4950
// Configuration specific to code sources (local directory or GitHub repo)

0 commit comments

Comments
 (0)