Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Jenkins converter's url #115

Merged
merged 2 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class JenkinsBuilds extends Converter {
startedAt: Utils.toDate(build.timestamp),
endedAt: Utils.toDate(build.timestamp + build.duration),
status: this.convertBuildStatus(build.result),
url: build.url,
url: jenkinsUrl.url,
pipeline: {
uid: pipeline.record.uid,
organization: orgKey,
Expand Down
23 changes: 13 additions & 10 deletions destinations/faros-destination/src/converters/jenkins/common.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {toLower} from 'lodash';
import {URL} from 'url';

import {DestinationRecord} from '../converter';

interface JenkinsUrl {
hostname: string;
url: string;
baseUrl: string;
}

export interface Job {
Expand All @@ -28,9 +28,9 @@ export class JenkinsCommon {
return {
model: 'cicd_Organization',
record: {
uid: toLower(jenkinsUrl.hostname),
uid: jenkinsUrl.hostname.toLowerCase(),
name: jenkinsUrl.hostname,
url: jenkinsUrl.url,
url: jenkinsUrl.baseUrl,
source,
},
};
Expand All @@ -42,7 +42,7 @@ export class JenkinsCommon {
return {
model: 'cicd_Pipeline',
record: {
uid: toLower(job.fullName),
uid: job.fullName.toLowerCase(),
name: job.name,
url: job.url,
organization,
Expand All @@ -52,12 +52,15 @@ export class JenkinsCommon {

static parseJenkinsUrl(initUrl: string): undefined | JenkinsUrl {
try {
const jenkinsUrl = new URL(initUrl);
jenkinsUrl.pathname = '';
return {
hostname: jenkinsUrl.hostname,
url: jenkinsUrl.toString(),
};
const urlParsed = new URL(initUrl);
const hostname = urlParsed.hostname;
const url = urlParsed.toString();
urlParsed.pathname = '';
const baseUrl = urlParsed.toString();
if (!hostname) {
return undefined;
}
return {hostname, url, baseUrl};
} catch (error) {
return undefined;
}
Expand Down
13 changes: 9 additions & 4 deletions destinations/faros-destination/src/converters/jenkins/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import {AirbyteRecord} from 'faros-airbyte-cdk';

import {Converter, DestinationModel, DestinationRecord, StreamContext} from '../converter';
import {
Converter,
DestinationModel,
DestinationRecord,
StreamContext,
} from '../converter';
import {JenkinsCommon, Job} from './common';

export class JenkinsJobs extends Converter {
readonly destinationModels: ReadonlyArray<DestinationModel> = [
'cicd_Organization',
'cicd_Pipeline',
];

id(record: AirbyteRecord): any {
return record?.record?.data?.fullName;
}
Expand All @@ -19,11 +24,11 @@ export class JenkinsJobs extends Converter {
): ReadonlyArray<DestinationRecord> {
const source = this.streamName.source;
const job = record.record.data as Job;

const jenkinsUrl = JenkinsCommon.parseJenkinsUrl(job.url);
if (!jenkinsUrl) return [];
const organization = JenkinsCommon.cicd_Organization(jenkinsUrl, source);
const orgKey = {uid: organization.record.uid, source}
const orgKey = {uid: organization.record.uid, source};
const pipeline = JenkinsCommon.cicd_Pipeline(job, orgKey);

return [organization, pipeline];
Expand Down