Skip to content

Commit

Permalink
Squashed all commits
Browse files Browse the repository at this point in the history
  • Loading branch information
ArpitShukla12 committed Nov 7, 2023
1 parent 816b36a commit efdf3de
Show file tree
Hide file tree
Showing 60 changed files with 10,369 additions and 4,054 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
ATLAN_INSTANCE_URL: ${{secrets.ATLAN_INSTANCE_URL}}
ATLAN_API_TOKEN: ${{secrets.ATLAN_API_TOKEN}}
# DBT_ENVIRONMENT_BRANCH_MAP: |
# main: DBT-DEMO-PROD
# beta: Wide World Importers PE1
# test-action: Wide World Importers PE1
DBT_ENVIRONMENT_BRANCH_MAP: |
main: DBT-DEMO-PROD
beta: Wide World Importers PE1
test-action: Wide World Importers PE1
IGNORE_MODEL_ALIAS_MATCHING: true
23 changes: 12 additions & 11 deletions src/api/create-resource.js → adapters/api/create-resource.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { v4 as uuidv4 } from "uuid";
import fetch from "node-fetch";
import stringify from "json-stringify-safe";
import { getAPIToken, getInstanceUrl } from "../utils/index.js";
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

const ATLAN_INSTANCE_URL = getInstanceUrl();
const ATLAN_API_TOKEN = getAPIToken();

export default async function createResource( //Done
export default async function createResource(
guid,
name,
link,
Expand Down Expand Up @@ -49,14 +49,15 @@ export default async function createResource( //Done
.then((e) => e.json())
.catch((err) => {
console.log(err);
sendSegmentEventOfIntegration("dbt_ci_action_failure", {
reason: "failed_to_create_resource",
asset_name: name,
msg: err,
sendSegmentEventOfIntegration({
action: "dbt_ci_action_failure",
properties: {
reason: "failed_to_create_resource",
asset_name: name, // This should change
msg: err,
},
});
});

console.log("Created Resource:", response);

return response;
}
64 changes: 46 additions & 18 deletions src/api/get-asset.js → adapters/api/get-asset.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import fetch from "node-fetch";
import core from "@actions/core";
import dotenv from "dotenv";
import stringify from "json-stringify-safe";

dotenv.config();

const ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
const ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
import {
getErrorModelNotFound,
getErrorDoesNotMaterialize,
} from "../templates/atlan.js";
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

export default async function getAsset({
//Done
name,
sendSegmentEventOfIntegration,
environment,
Expand All @@ -21,7 +19,7 @@ export default async function getAsset({
Authorization: `Bearer ${ATLAN_API_TOKEN}`,
"Content-Type": "application/json",
};
console.log("At line 24 inside getAsset function");

var raw = stringify({
dsl: {
from: 0,
Expand Down Expand Up @@ -88,8 +86,7 @@ export default async function getAsset({
headers: myHeaders,
body: raw,
};
console.log("Before SendSegmentEventOfIntegration");
console.log("At line 92 inside getAsset");

var response = await fetch(
`${ATLAN_INSTANCE_URL}/api/meta/search/indexsearch#findAssetByExactName`,
requestOptions
Expand All @@ -105,16 +102,47 @@ export default async function getAsset({
},
});
});
console.log("<><><><><><><><><><><><><>");
console.log(response);
if (!response?.entities?.length)

if (!response?.entities?.length) {
return {
error: `❌ Model with name **${name}** could not be found or is deleted <br><br>`,
error: getErrorModelNotFound(name),
};
}

if (Array.isArray(response.entities)) {
response.entities.sort((entityA, entityB) => {
const hasDbtModelSqlAssetsA =
entityA.attributes.dbtModelSqlAssets &&
entityA.attributes.dbtModelSqlAssets.length > 0;
const hasDbtModelSqlAssetsB =
entityB.attributes.dbtModelSqlAssets &&
entityB.attributes.dbtModelSqlAssets.length > 0;

if (hasDbtModelSqlAssetsA && !hasDbtModelSqlAssetsB) {
return -1; // entityA comes before entityB
} else if (!hasDbtModelSqlAssetsA && hasDbtModelSqlAssetsB) {
return 1; // entityB comes before entityA
}

// Primary sorting criterion: Latest createTime comes first
if (entityA.createTime > entityB.createTime) {
return -1;
} else if (entityA.createTime < entityB.createTime) {
return 1;
}

return 0; // No difference in sorting for these two entities
});
}

if (!response?.entities[0]?.attributes?.dbtModelSqlAssets?.length > 0)
return {
error: `❌ Model with name [${name}](${ATLAN_INSTANCE_URL}/assets/${response.entities[0].guid}/overview?utm_source=dbt_${integration}_action) does not materialise any asset <br><br>`,
error: getErrorDoesNotMaterialize(
name,
ATLAN_INSTANCE_URL,
response,
integration
),
};

return response.entities[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import fetch from "node-fetch";
import { sendSegmentEvent } from "./index.js";
import stringify from "json-stringify-safe";
import { getAPIToken, getInstanceUrl } from "../utils/index.js";

const ATLAN_INSTANCE_URL = getInstanceUrl();
const ATLAN_API_TOKEN = getAPIToken();
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

export default async function getClassifications({
sendSegmentEventOfIntegration,
Expand All @@ -26,9 +24,12 @@ export default async function getClassifications({
)
.then((e) => e.json())
.catch((err) => {
sendSegmentEventOfIntegration("dbt_ci_action_failure", {
reason: "failed_to_get_classifications",
msg: err,
sendSegmentEventOfIntegration({
action: "dbt_ci_action_failure",
properties: {
reason: "failed_to_get_classifications",
msg: err,
},
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import fetch from "node-fetch";
import core from "@actions/core";
import dotenv from "dotenv";
import {
getConnectorImage,
getCertificationImage,
getImageURL,
} from "../utils/index.js";
import stringify from "json-stringify-safe";

dotenv.config();

const ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
const ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

const ASSETS_LIMIT = 100;

export default async function getDownstreamAssets( //Done
export default async function getDownstreamAssets(
asset,
guid,
totalModifiedFiles,
Expand All @@ -28,7 +23,7 @@ export default async function getDownstreamAssets( //Done
authorization: `Bearer ${ATLAN_API_TOKEN}`,
"content-type": "application/json",
};
console.log("At line 31 inside getDownstreamAssets function");

var raw = stringify({
guid: guid,
size: Math.max(Math.ceil(ASSETS_LIMIT / totalModifiedFiles), 1),
Expand Down Expand Up @@ -96,12 +91,15 @@ ${getImageURL(
asset.guid
}/lineage/overview?utm_source=dbt_${integration}_action)`;

sendSegmentEventOfIntegration("dbt_ci_action_failure", {
reason: "failed_to_fetch_lineage",
asset_guid: asset.guid,
asset_name: asset.name,
asset_typeName: asset.typeName,
msg: err,
sendSegmentEventOfIntegration({
action: "dbt_ci_action_failure",
properties: {
reason: "failed_to_fetch_lineage",
asset_guid: asset.guid,
asset_name: asset.name,
asset_typeName: asset.typeName,
msg: err,
},
});

return comment;
Expand All @@ -123,7 +121,6 @@ ${getImageURL(
error: handleError(err),
};
});
console.log("At line 126 inside getDownstreamAssets function", response);
if (response.error) return response;

return response;
Expand Down
File renamed without changes.
19 changes: 7 additions & 12 deletions src/api/segment.js → adapters/api/segment.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import fetch from "node-fetch";
import core from "@actions/core";
import dotenv from "dotenv";

dotenv.config();

const { IS_DEV } = process.env;
const ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
const ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
import {
IS_DEV,
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

export async function sendSegmentEvent(action, body) {
const myHeaders = {
authorization: `Bearer ${ATLAN_API_TOKEN}`,
"content-type": "application/json",
};
console.log("At line 18 inide sendSegmentEvent");

const requestOptions = {
method: "POST",
headers: myHeaders,
Expand All @@ -37,6 +32,6 @@ export async function sendSegmentEvent(action, body) {
} else {
console.log("send segment event", action, body);
}
console.log("At line 40 inside sendSegmentEvent");

return response;
}
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
5 changes: 3 additions & 2 deletions adapters/gateway.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Common Gateway for all integrations
import logger from "./logger/logger.js";
export async function runAction(token, integrationModule) {
if (token === undefined) {
console.log("Token not provided.");
logger.logInfo("Token not provided.", "runAction");
return;
}
const integration = new integrationModule(token);
await integration.run(); // Add error part
await integration.run();
}
12 changes: 4 additions & 8 deletions adapters/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
// main.js
import dotenv from "dotenv";
import { runAction } from "./gateway.js";
import GitHubIntegration from "./integrations/github-integration.js";
import GitLabIntegration from "./integrations/gitlab-integration.js";
import core from "@actions/core";

dotenv.config();

const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN") || process.env.GITHUB_TOKEN;
const GITLAB_TOKEN = process.env.GITLAB_TOKEN;
import {
GITLAB_TOKEN,
GITHUB_TOKEN,
} from "./utils/get-environment-variables.js";

async function run() {
//Add new integrations over here
console.log("oii");
await runAction(GITHUB_TOKEN, GitHubIntegration);
await runAction(GITLAB_TOKEN, GitLabIntegration);
}
Expand Down
Loading

0 comments on commit efdf3de

Please sign in to comment.