Skip to content

Commit

Permalink
feat(action): add support data contract action
Browse files Browse the repository at this point in the history
changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes

changes
  • Loading branch information
rittikdasgupta committed Sep 19, 2024
1 parent 5dc164b commit 4e3d955
Show file tree
Hide file tree
Showing 15 changed files with 6,755 additions and 816 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ jobs:
beta: Wide World Importers PE1
test-action: Wide World Importers PE1
IGNORE_MODEL_ALIAS_MATCHING: true
ATLAN_CONFIG: .atlan/config.yaml
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
node_modules/
event.json
.idea
.DS_Store
.DS_Store
.vscode/
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ inputs:
description: "Ignore model alias matching"
required: false
default: false
ATLAN_CONFIG:
description: "Atlan CLI config file location"
required: false
runs:
using: "node16"
main: "dist/index.js"
Expand Down
33 changes: 33 additions & 0 deletions adapters/api/get-asset-classifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
ATLAN_API_TOKEN,
ATLAN_INSTANCE_URL,
} from "../utils/get-environment-variables.js";

import fetch from "node-fetch";

export default async function getAssetClassifications() {
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) => {
return {
error: err
}
});
if (response.error) return response

return response?.classificationDefs;
}
7 changes: 4 additions & 3 deletions adapters/api/get-classifications.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import fetch from "node-fetch";
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
ATLAN_INSTANCE_URL,
} from "../utils/get-environment-variables.js";

import fetch from "node-fetch";

export default async function getClassifications({
sendSegmentEventOfIntegration,
}) {
Expand Down Expand Up @@ -34,4 +35,4 @@ export default async function getClassifications({
});

return response?.classificationDefs;
}
}
55 changes: 55 additions & 0 deletions adapters/api/get-contract-asset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
ATLAN_API_TOKEN,
ATLAN_INSTANCE_URL,
} from "../utils/get-environment-variables.js";

import fetch from "node-fetch";
import {
getErrorAssetNotFound,
} from "../templates/atlan.js";
import stringify from "json-stringify-safe";

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

var raw = stringify(
{
"atlanConfig": atlanConfig,
"contractSpec": contractSpec
}
);

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

var response = await fetch(
`${ATLAN_INSTANCE_URL}/api/service/contracts/asset`,
requestOptions
)
.then((e) => e.json())
.catch((err) => {
return {
error: err,
comment: getErrorAssetNotFound(name)
}
});

if (!response?.entities?.length) {
return {
error: "asset not found",
comment: getErrorAssetNotFound(name),
};
}

return response.entities[0];
}
162 changes: 137 additions & 25 deletions adapters/api/get-downstream-assets.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import fetch from "node-fetch";
import {
getConnectorImage,
ATLAN_API_TOKEN,
ATLAN_INSTANCE_URL,
} from "../utils/get-environment-variables.js";
import {
getCertificationImage,
getConnectorImage,
getImageURL,
} from "../utils/index.js";

import fetch from "node-fetch";
import stringify from "json-stringify-safe";
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

const ASSETS_LIMIT = 100;

Expand Down Expand Up @@ -71,25 +72,26 @@ export default async function getDownstreamAssets(
};

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)`;
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",
Expand Down Expand Up @@ -125,3 +127,113 @@ ${getImageURL(

return response;
}

function contructCommentForDownstreamLineageFetchError({
asset,
utmSource
}){
const comment = `
### ${getConnectorImage(asset.attributes.connectorName
)} [${asset.displayText}](${ATLAN_INSTANCE_URL}/assets/${
asset.guid
}/overview?utm_source=${utmSource}) ${
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=${utmSource})
`;

return comment;
}

export async function getDownstreamLineageForAssets({
asset,
guid,
totalModifiedFiles,
utmSource
}) {
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 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: err,
comment: contructCommentForDownstreamLineageFetchError({asset, utmSource}),
};
});
if (response.error) return {
error: err,
comment: contructCommentForDownstreamLineageFetchError({asset, utmSource}),
};

return response;
}
13 changes: 8 additions & 5 deletions adapters/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// main.js
import { runAction } from "./gateway.js";
import GitHubIntegration from "./integrations/github-integration.js";
import GitLabIntegration from "./integrations/gitlab-integration.js";
import {
GITLAB_TOKEN,
GITHUB_TOKEN,
GITLAB_TOKEN,
} from "./utils/get-environment-variables.js";

import ContractIntegration from "./integrations/atlan-contract-impact-analysis-github.js";
import GitHubIntegration from "./integrations/github-integration.js";
import GitLabIntegration from "./integrations/gitlab-integration.js";
// main.js
import { runAction } from "./gateway.js";

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

0 comments on commit 4e3d955

Please sign in to comment.