diff --git a/destinations/airbyte-faros-destination/src/converters/azurepipeline/common.ts b/destinations/airbyte-faros-destination/src/converters/azurepipeline/common.ts index e510f22cf..f5be13cfd 100644 --- a/destinations/airbyte-faros-destination/src/converters/azurepipeline/common.ts +++ b/destinations/airbyte-faros-destination/src/converters/azurepipeline/common.ts @@ -95,6 +95,7 @@ export abstract class AzurePipelineConverter extends Converter { return { name: toLower(parts[1]), + uid: toLower(parts[1]), organization: { uid: toLower(parts[0]), source: repo.type, diff --git a/destinations/airbyte-faros-destination/src/converters/github/issue_labels.ts b/destinations/airbyte-faros-destination/src/converters/github/issue_labels.ts index 0b48a8fb1..5725116e4 100644 --- a/destinations/airbyte-faros-destination/src/converters/github/issue_labels.ts +++ b/destinations/airbyte-faros-destination/src/converters/github/issue_labels.ts @@ -4,7 +4,10 @@ import {DestinationModel, DestinationRecord} from '../converter'; import {GitHubConverter} from './common'; export class IssueLabels extends GitHubConverter { - readonly destinationModels: ReadonlyArray = ['tms_Label']; + readonly destinationModels: ReadonlyArray = [ + 'tms_Label', + 'vsc_Label', + ]; async convert( record: AirbyteRecord @@ -15,6 +18,10 @@ export class IssueLabels extends GitHubConverter { model: 'tms_Label', record: {name: label.name}, }, + { + model: 'vcs_Label', + record: {name: label.name}, + }, ]; } } diff --git a/destinations/airbyte-faros-destination/src/converters/github/issues.ts b/destinations/airbyte-faros-destination/src/converters/github/issues.ts index d8f4e5f39..a2ac0b6ce 100644 --- a/destinations/airbyte-faros-destination/src/converters/github/issues.ts +++ b/destinations/airbyte-faros-destination/src/converters/github/issues.ts @@ -17,6 +17,7 @@ export class Issues extends GitHubConverter { 'tms_TaskBoardRelationship', 'tms_TaskTag', 'tms_User', + 'vcs_PullRequestLabel', ]; private readonly issueLabelsStream = new StreamName('github', 'issue_labels'); @@ -25,7 +26,7 @@ export class Issues extends GitHubConverter { return [this.issueLabelsStream]; } - async convert( + private async convertIssue( record: AirbyteRecord, ctx: StreamContext ): Promise> { @@ -34,13 +35,6 @@ export class Issues extends GitHubConverter { const res: DestinationRecord[] = []; const uid = `${issue.id}`; - // GitHub's REST API v3 considers every pull request an issue, - // but not every issue is a pull request. Will skip pull requests - // since we pull them separately - if (issue.pull_request) { - return res; - } - const user = GitHubCommon.tms_User(issue?.user, source); if (user) res.push(user); @@ -58,16 +52,7 @@ export class Issues extends GitHubConverter { } }); - const issueLabelsStream = this.issueLabelsStream.asString; - for (const labelNode of issue.labels) { - const label = ctx.get(issueLabelsStream, String(labelNode.id)); - const name = label?.record?.data?.name; - if (!name) continue; - res.push({ - model: 'tms_TaskTag', - record: {task: {uid, source}, label: {name}}, - }); - } + this.convertLabels(record, ctx, res); // Github issues only have state either open or closed const category = issue.state === 'open' ? 'Todo' : 'Done'; @@ -105,4 +90,54 @@ export class Issues extends GitHubConverter { return res; } + + private async convertPullRequest( + record: AirbyteRecord, + ctx: StreamContext + ): Promise> { + const res: DestinationRecord[] = []; + + this.convertLabels(record, ctx, res); + + return res; + } + + private convertLabels( + record: AirbyteRecord, + ctx: StreamContext, + result: DestinationRecord[] + ): void { + const issue = record.record.data; + const source = this.streamName.source; + const issueLabelsStream = this.issueLabelsStream.asString; + + const model = issue.pull_request ? 'vcs_PullRequestLabel' : 'tms_TaskTag'; + const recordKey = issue.pull_request ? 'pullRequest' : 'task'; + const uid = issue.pull_request + ? issue.number.toString() + : issue.id.toString(); + + for (const labelNode of issue.labels) { + const label = ctx.get(issueLabelsStream, String(labelNode.id)); + const name = label?.record?.data?.name; + if (!name) continue; + result.push({ + model, + record: {[recordKey]: {uid, source}, label: {name}}, + }); + } + } + + async convert( + record: AirbyteRecord, + ctx: StreamContext + ): Promise> { + const issue = record.record.data; + + if (issue.pull_reuqest) { + return this.convertPullRequest(record, ctx); + } else { + return this.convertIssue(record, ctx); + } + } } diff --git a/package-lock.json b/package-lock.json index 2902a4f5e..87723fdad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17235,6 +17235,7 @@ "version": "8.1.0", "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "deprecated": "Glob versions prior to v9 are no longer supported", "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -18128,9 +18129,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/sax": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.3.0.tgz", - "integrity": "sha512-0s+oAmw9zLl1V1cS9BtZN7JAd0cW5e0QH4W3LWEK6a4LaLEA2OTpGYWDY+6XasBLtz6wkm3u1xRw95mRuJ59WA==" + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.4.1.tgz", + "integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==" }, "node_modules/secure-json-parse": { "version": "2.7.0", @@ -18952,9 +18953,9 @@ } }, "node_modules/table/node_modules/ajv": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", - "integrity": "sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==", + "version": "8.14.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.14.0.tgz", + "integrity": "sha512-oYs1UUtO97ZO2lJ4bwnWeQW8/zvOIQLGKcvPTsWmvc2SYgBb+upuNS5NxoLaMU4h8Ju3Nbj6Cq8mD2LQoqVKFA==", "dependencies": { "fast-deep-equal": "^3.1.3", "json-schema-traverse": "^1.0.0",