Skip to content

Commit

Permalink
FAI-13967, FAI-8202: Jira source add source name qualifier to write n…
Browse files Browse the repository at this point in the history
…on-uid ids for multiple instances (#1867)
  • Loading branch information
chalenge authored Dec 28, 2024
1 parent 88a362d commit d68303b
Show file tree
Hide file tree
Showing 30 changed files with 1,111 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
"title": "Additional Fields Array Limit",
"description": "Truncates an additional field's array value to the given length.",
"default": 50
},
"source_qualifier": {
"order": 37,
"type": "string",
"title": "Source Qualifier",
"description": "The qualifier to append as a suffix to the Jira source name to ensure uniqueness among entities with similar IDs when syncing multiple Jira instances, while preserving their original IDs, e.g. for Boards and Sprints.",
"examples": [
"Instance2"
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class BoardIssues extends JiraConverter {
): Promise<ReadonlyArray<DestinationRecord>> {
if (!this.useBoardOwnership(ctx)) return [];
const issue = record.record.data;
const source = this.streamName.source;
const source = this.initializeSource(ctx);
const relation = {
task: {uid: issue.key, source},
board: {uid: String(issue.boardId), source},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Boards extends JiraConverter {
if (!this.useBoardOwnership(ctx)) return [];
const board = record.record.data;
const uid = board.id.toString();
const source = this.streamName.source;
const source = this.initializeSource(ctx);
return [
{
model: 'tms_TaskBoard',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ export interface JiraConfig {
exclude_fields?: string[];
use_board_ownership?: boolean;
truncate_limit?: number;
source_qualifier?: string;
}

export abstract class JiraConverter extends Converter {
private qualifiedSourceName = false;
source = 'Jira';

/** All Jira records should have id property */
Expand All @@ -51,6 +53,19 @@ export abstract class JiraConverter extends Converter {
return ctx.config.source_specific_configs?.jira ?? {};
}

/**
* If the source is not qualified, we need to add the qualifier to the source name
*/
protected initializeSource(ctx: StreamContext): string {
if (this.qualifiedSourceName) {
return this.source;
}
const qualifier = this.jiraConfig(ctx).source_qualifier;
this.source = qualifier ? `${this.source}_${qualifier}` : this.source;
this.qualifiedSourceName = true;
return this.source;
}

protected additionalFieldsArrayLimit(ctx: StreamContext): number {
return (
this.jiraConfig(ctx).additional_fields_array_limit ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Epics extends JiraConverter {
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
const epic = record.record.data;
const source = this.streamName.source;
const source = this.initializeSource(ctx);
const status = epic.fields.status ?? {};
let description = null;
if (typeof epic.fields.description === 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class FarosBoardIssues extends JiraConverter {
record: AirbyteRecord,
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
this.initializeSource(ctx);
return this.alias.convert(record, ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class FarosBoards extends JiraConverter {
): Promise<ReadonlyArray<DestinationRecord>> {
const board = record.record.data;
const uid = board.uid;
const source = this.streamName.source;
const source = this.initializeSource(ctx);
const results: DestinationRecord[] = [
{
model: 'tms_TaskBoard',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class FarosIssueAdditionalFields extends JiraConverter {
record: AirbyteRecord,
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
this.initializeSource(ctx);
const issue = record.record.data as IssueCompact;
return [this.convertAdditionalFieldsIssue(issue)];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class FarosIssuePullRequests extends JiraConverter {
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
const pullRequest = record.record.data;
const source = this.streamName.source;
const source = this.initializeSource(ctx);
return [
{
model: 'tms_TaskPullRequestAssociation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class FarosIssues extends JiraConverter {
const issue = record.record.data as Issue;
this.seenIssues.add(issue.key);

const source = this.streamName.source;
const source = this.initializeSource(ctx);
const results: DestinationRecord[] = [];

if (issue.updateAdditionalFields) {
Expand Down Expand Up @@ -142,7 +142,7 @@ export class FarosIssues extends JiraConverter {
'status',
'source',
]),
project: {uid: issue.project, source: this.source},
project: {uid: issue.project, source},
},
});
}
Expand Down Expand Up @@ -217,9 +217,7 @@ export class FarosIssues extends JiraConverter {
return [...results, ...ancestors];
}

async onProcessingComplete(
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
async onProcessingComplete(): Promise<ReadonlyArray<DestinationRecord>> {
return this.convertDependencies();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class FarosProjectVersionIssues extends JiraConverter {
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
const issue = record.record.data;
const source = this.streamName.source;
const source = this.initializeSource(ctx);
return [
{
model: 'tms_TaskReleaseRelationship',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class FarosProjectVersions extends JiraConverter {
record: AirbyteRecord,
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
this.source = this.initializeSource(ctx);
return this.alias.convert(record, ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class FarosProjects extends JiraConverter {
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
const project = record.record.data;
const source = this.streamName.source;
const source = this.initializeSource(ctx);
return [
{
model: 'tms_Project',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class FarosSprintReports extends JiraConverter {
const sprintUid = toString(sprintReport.sprintId);
const boardUid = toString(sprintReport.boardId);
const results: DestinationRecord[] = [];
const source = this.streamName.source;
const source = this.initializeSource(ctx);
for (const issue of sprintReport.issues || []) {
const status = issue.status
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class FarosSprints extends JiraConverter {
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
const sprint = record.record.data;
const source = this.streamName.source;
const source = this.initializeSource(ctx);
const uid = toString(sprint.id);
return [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ export class FarosTeamMemberships extends JiraConverter {
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
const teamMembership = record.record.data;
const source = this.initializeSource(ctx);
return [
{
model: 'tms_TeamMembership',
record: {
team: {uid: teamMembership.teamId, source: this.streamName.source},
team: {uid: teamMembership.teamId, source},
member: {
uid: teamMembership.memberId,
source: this.streamName.source,
source,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class FarosTeams extends JiraConverter {
name: team.displayName,
parentTeam: {uid: allTeamsUid},
teamChain: [team.id, allTeamsUid],
source: this.streamName.source,
source: this.initializeSource(ctx),
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class FarosUsers extends JiraConverter {
record: AirbyteRecord,
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
this.initializeSource(ctx);
return this.alias.convert(record, ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ export class Issues extends JiraConverter {
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
const issue = record.record.data;
const source = this.streamName.source;
const source = this.initializeSource(ctx);
const results: DestinationRecord[] = [];

if (!this.fieldIdsByName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ProjectVersions extends JiraConverter {
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
const projectVersion = record.record.data as ProjectVersion;
const source = this.streamName.source;
const source = this.initializeSource(ctx);
const results: DestinationRecord[] = [
{
model: 'tms_Release',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Projects extends JiraConverter {
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
const project = record.record.data;
const source = this.streamName.source;
const source = this.initializeSource(ctx);
const uid = project.key;
const results: DestinationRecord[] = [];
results.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class Sprints extends JiraConverter {
ctx: StreamContext
): Promise<ReadonlyArray<DestinationRecord>> {
const sprint = record.record.data;
const source = this.initializeSource(ctx);
if (!this.pointsFieldIdsByName) {
this.pointsFieldIdsByName = Sprints.getFieldIdsByName(ctx);
}
Expand All @@ -107,7 +108,7 @@ export class Sprints extends JiraConverter {
completedPoints,
startedAt: Utils.toDate(sprint.startDate),
endedAt: Utils.toDate(sprint.endDate),
source: this.streamName.source,
source,
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Users extends JiraConverter {
uid,
name: user.displayName,
emailAddress: user.emailAddress,
source: this.streamName.source,
source: this.initializeSource(ctx),
inactive: user.active != null && !user.active,
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {AirbyteRecord} from 'faros-airbyte-cdk';
import {Utils} from 'faros-js-client';
import {toNumber} from 'lodash';

import {CategoryDetail} from '../common/common';
import {Vulnerability} from '../common/sec';
import {Converter, DestinationModel, DestinationRecord} from '../converter';
import {GitHubCommon} from '../github/common';
import {toNumber} from 'lodash';
export class Findings extends Converter {
readonly destinationModels: ReadonlyArray<DestinationModel> = [
'cicd_ArtifactVulnerability',
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit d68303b

Please sign in to comment.