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

Added support for gitlab and github #124

Merged
merged 22 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a5830c7
Merge pull request #110 from atlanhq/ACTIV-1019-project-and-environme…
Jaagrav Aug 16, 2023
c941618
chore: Update dist
Aug 16, 2023
93bc75d
Did some restructuring of code
ArpitShukla12 Sep 26, 2023
74744c9
Restructured the code
ArpitShukla12 Sep 29, 2023
63c7d59
Added logs for debugging
ArpitShukla12 Oct 3, 2023
512a33c
Removed comments
ArpitShukla12 Oct 10, 2023
816b36a
Added few more logs
ArpitShukla12 Oct 11, 2023
efdf3de
Squashed all commits
ArpitShukla12 Nov 7, 2023
9e8a7cf
Merge branch 'feat/integration_support' into PR_staging_integration_s…
ArpitShukla12 Nov 7, 2023
4a63c0c
Changed setResourceOnAsset message
ArpitShukla12 Nov 7, 2023
556c63d
Merge branch 'feat/integration_support' into PR_staging_integration_s…
ArpitShukla12 Nov 7, 2023
32c1386
Added correct documentation link
ArpitShukla12 Nov 7, 2023
4e6deea
Merge branch 'feat/integration_support' into PR_staging_integration_s…
ArpitShukla12 Nov 7, 2023
83b0c07
Testing segments
ArpitShukla12 Nov 8, 2023
24f93a2
Debugging segment
ArpitShukla12 Nov 8, 2023
458e6c1
fixing bug
ArpitShukla12 Nov 8, 2023
e3c0d43
fixing bug1
ArpitShukla12 Nov 8, 2023
38c7ab5
Logging for fix
ArpitShukla12 Nov 8, 2023
31e0aa9
Resolved set resource on asset issue
ArpitShukla12 Nov 8, 2023
8ff1a35
Resolved segment event issue
ArpitShukla12 Nov 8, 2023
23714b9
Merge branch 'feat/integration_support' into PR_staging_integration_s…
ArpitShukla12 Nov 8, 2023
1d5e08b
Merge pull request #119 from ArpitShukla12/PR_staging_integration_sup…
ArpitShukla12 Nov 8, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test Action

on:
pull_request:
types: [ opened, edited, synchronize, reopened, closed ]
types: [opened, edited, synchronize, reopened, closed]

jobs:
get-downstream-assets:
Expand All @@ -28,4 +28,4 @@ jobs:
main: DBT-DEMO-PROD
beta: Wide World Importers PE1
test-action: Wide World Importers PE1
IGNORE_MODEL_ALIAS_MATCHING: true
IGNORE_MODEL_ALIAS_MATCHING: true
64 changes: 64 additions & 0 deletions adapters/api/create-resource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { v4 as uuidv4 } from "uuid";
import fetch from "node-fetch";
import stringify from "json-stringify-safe";
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

export default async function createResource(
guid,
name,
link,
sendSegmentEventOfIntegration
) {
var myHeaders = {
Authorization: `Bearer ${ATLAN_API_TOKEN}`,
"Content-Type": "application/json",
};

var raw = stringify({
entities: [
{
typeName: "Link",
attributes: {
qualifiedName: uuidv4(),
name,
link,
tenantId: "default",
},
relationshipAttributes: {
asset: {
guid,
},
},
},
],
});

var requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
};

var response = await fetch(
`${ATLAN_INSTANCE_URL}/api/meta/entity/bulk`,
requestOptions
)
.then((e) => e.json())
.catch((err) => {
console.log(err);
sendSegmentEventOfIntegration({
action: "dbt_ci_action_failure",
properties: {
reason: "failed_to_create_resource",
asset_name: name, // This should change
msg: err,
},
});
});

if (response?.errorCode) return null;
return response;
}
149 changes: 149 additions & 0 deletions adapters/api/get-asset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import fetch from "node-fetch";
import stringify from "json-stringify-safe";
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({
name,
sendSegmentEventOfIntegration,
environment,
integration,
}) {
var myHeaders = {
Authorization: `Bearer ${ATLAN_API_TOKEN}`,
"Content-Type": "application/json",
};

var raw = stringify({
dsl: {
from: 0,
size: 21,
query: {
bool: {
must: [
{
match: {
__state: "ACTIVE",
},
},
{
match: {
"__typeName.keyword": "DbtModel",
},
},
{
match: {
"name.keyword": name,
},
},
...(environment
? [
{
term: {
"assetDbtEnvironmentName.keyword": environment,
},
},
]
: []),
],
},
},
},
attributes: [
"name",
"description",
"userDescription",
"sourceURL",
"qualifiedName",
"connectorName",
"certificateStatus",
"certificateUpdatedBy",
"certificateUpdatedAt",
"ownerUsers",
"ownerGroups",
"classificationNames",
"meanings",
"dbtModelSqlAssets",
],
relationAttributes: [
"name",
"description",
"assetDbtProjectName",
"assetDbtEnvironmentName",
"connectorName",
"certificateStatus",
],
});

var requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
};

var response = await fetch(
`${ATLAN_INSTANCE_URL}/api/meta/search/indexsearch#findAssetByExactName`,
requestOptions
)
.then((e) => e.json())
.catch((err) => {
sendSegmentEventOfIntegration({
action: "dbt_ci_action_failure",
properties: {
reason: "failed_to_get_asset",
asset_name: name,
msg: err,
},
});
});

if (!response?.entities?.length) {
return {
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: getErrorDoesNotMaterialize(
name,
ATLAN_INSTANCE_URL,
response,
integration
),
};

return response.entities[0];
}
37 changes: 37 additions & 0 deletions adapters/api/get-classifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import fetch from "node-fetch";
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

export default async function getClassifications({
sendSegmentEventOfIntegration,
}) {
var myHeaders = {
Authorization: `Bearer ${ATLAN_API_TOKEN}`,
"Content-Type": "application/json",
};

var requestOptions = {
method: "GET",
headers: myHeaders,
redirect: "follow",
};

var response = await fetch(
`${ATLAN_INSTANCE_URL}/api/meta/types/typedefs?type=classification`,
requestOptions
)
.then((e) => e.json())
.catch((err) => {
sendSegmentEventOfIntegration({
action: "dbt_ci_action_failure",
properties: {
reason: "failed_to_get_classifications",
msg: err,
},
});
});

return response?.classificationDefs;
}
127 changes: 127 additions & 0 deletions adapters/api/get-downstream-assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import fetch from "node-fetch";
import {
getConnectorImage,
getCertificationImage,
getImageURL,
} from "../utils/index.js";
import stringify from "json-stringify-safe";
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

const ASSETS_LIMIT = 100;

export default async function getDownstreamAssets(
asset,
guid,
totalModifiedFiles,
sendSegmentEventOfIntegration,
integration
) {
var myHeaders = {
authorization: `Bearer ${ATLAN_API_TOKEN}`,
"content-type": "application/json",
};

var raw = stringify({
guid: guid,
size: Math.max(Math.ceil(ASSETS_LIMIT / totalModifiedFiles), 1),
from: 0,
depth: 21,
direction: "OUTPUT",
entityFilters: {
condition: "AND",
criterion: [
{
attributeName: "__typeName",
operator: "not_contains",
attributeValue: "Process",
},
{
attributeName: "__state",
operator: "eq",
attributeValue: "ACTIVE",
},
],
},
attributes: [
"name",
"description",
"userDescription",
"sourceURL",
"qualifiedName",
"connectorName",
"certificateStatus",
"certificateUpdatedBy",
"certificateUpdatedAt",
"ownerUsers",
"ownerGroups",
"classificationNames",
"meanings",
],
excludeMeanings: false,
excludeClassifications: false,
});

var requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
};

var handleError = (err) => {
const comment = `### ${getConnectorImage(
asset.attributes.connectorName
)} [${asset.displayText}](${ATLAN_INSTANCE_URL}/assets/${
asset.guid
}/overview?utm_source=dbt_${integration}_action) ${
asset.attributes?.certificateStatus
? getCertificationImage(asset.attributes.certificateStatus)
: ""
}

_Failed to fetch impacted assets._

${getImageURL(
"atlan-logo",
15,
15
)} [View lineage in Atlan](${ATLAN_INSTANCE_URL}/assets/${
asset.guid
}/lineage/overview?utm_source=dbt_${integration}_action)`;

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;
};

var response = await fetch(
`${ATLAN_INSTANCE_URL}/api/meta/lineage/list`,
requestOptions
)
.then((e) => {
if (e.status === 200) {
return e.json();
} else {
throw e;
}
})
.catch((err) => {
return {
error: handleError(err),
};
});
if (response.error) return response;

return response;
}
Loading
Loading