From 47fa3fabac0fcb3d1034e7a1e248a2b68028e1a9 Mon Sep 17 00:00:00 2001 From: Rittik Dasgupta Date: Wed, 23 Oct 2024 15:24:09 +0530 Subject: [PATCH] enhancement(analytics): add properties to segment events --- .../atlan-contract-impact-analysis-github.js | 4 +- adapters/integrations/github-integration.js | 40 ++-- adapters/integrations/gitlab-integration.js | 63 ++--- dist/index.js | 223 +++++++++--------- 4 files changed, 174 insertions(+), 156 deletions(-) diff --git a/adapters/integrations/atlan-contract-impact-analysis-github.js b/adapters/integrations/atlan-contract-impact-analysis-github.js index b69e906..5920e3f 100644 --- a/adapters/integrations/atlan-contract-impact-analysis-github.js +++ b/adapters/integrations/atlan-contract-impact-analysis-github.js @@ -34,7 +34,7 @@ import yaml from 'js-yaml'; var headSHA; const integrationName = "GITHUB_CONTRACT_IMPACT_ANALYSIS"; -const actionName = "contract_ci_action" +const actionName = "dbt_ci_action" const utmSource = "dbt_github_action" export default class ContractIntegration extends IntegrationInterface { @@ -468,6 +468,8 @@ export default class ContractIntegration extends IntegrationInterface { ...properties, github_action_id: `https://github.com/${context?.payload?.repository?.full_name}/actions/runs/${context?.runId}`, domain, + base_asset_type: "atlanContract", + action_repo_name: "atlan-action" }, }); diff --git a/adapters/integrations/github-integration.js b/adapters/integrations/github-integration.js index e7729e5..9c69ec2 100644 --- a/adapters/integrations/github-integration.js +++ b/adapters/integrations/github-integration.js @@ -1,39 +1,41 @@ -// githubIntegration.js -import IntegrationInterface from "./contract/contract.js"; -import github from "@actions/github"; -import stringify from "json-stringify-safe"; import { + ATLAN_INSTANCE_URL, + IGNORE_MODEL_ALIAS_MATCHING, + IS_DEV, +} from "../utils/get-environment-variables.js"; +import { + auth, getCertificationImage, getConnectorImage, getEnvironments, - auth, truncate, } from "../utils/index.js"; import { + createResource, getAsset, + getClassifications, getDownstreamAssets, sendSegmentEvent, - createResource, - getClassifications, } from "../api/index.js"; import { - getSetResourceOnAssetComment, - getErrorResponseStatus401, - getErrorResponseStatusUndefined, getAssetInfo, getDownstreamTable, - getViewAssetButton, - getMDCommentForModel, + getErrorResponseStatus401, + getErrorResponseStatusUndefined, getMDCommentForMaterialisedView, + getMDCommentForModel, + getSetResourceOnAssetComment, getTableMD, + getViewAssetButton, } from "../templates/github-integration.js"; -import { getNewModelAddedComment, getBaseComment } from "../templates/atlan.js"; -import { - IS_DEV, - ATLAN_INSTANCE_URL, - IGNORE_MODEL_ALIAS_MATCHING, -} from "../utils/get-environment-variables.js"; +import { getBaseComment, getNewModelAddedComment } from "../templates/atlan.js"; + +// githubIntegration.js +import IntegrationInterface from "./contract/contract.js"; +import github from "@actions/github"; import logger from "../logger/logger.js"; +import stringify from "json-stringify-safe"; + var headSHA; const integrationName = "github"; export default class GitHubIntegration extends IntegrationInterface { @@ -575,6 +577,8 @@ export default class GitHubIntegration extends IntegrationInterface { ...properties, github_action_id: `https://github.com/${context?.payload?.repository?.full_name}/actions/runs/${context?.runId}`, domain, + base_asset_type: "dbtModel", + action_repo_name: "atlan-action" }, }); diff --git a/adapters/integrations/gitlab-integration.js b/adapters/integrations/gitlab-integration.js index 8a7478b..2ecc26e 100644 --- a/adapters/integrations/gitlab-integration.js +++ b/adapters/integrations/gitlab-integration.js @@ -1,47 +1,48 @@ -// gitlabIntegration.js -import IntegrationInterface from "./contract/contract.js"; -import { Gitlab } from "@gitbeaker/rest"; import { - createResource, - getAsset, - getDownstreamAssets, - sendSegmentEvent, - getClassifications, -} from "../api/index.js"; + ATLAN_INSTANCE_URL, + CI_COMMIT_MESSAGE, + CI_COMMIT_SHA, + CI_JOB_URL, + CI_PROJECT_ID, + CI_PROJECT_NAME, + CI_PROJECT_NAMESPACE, + CI_PROJECT_PATH, + IGNORE_MODEL_ALIAS_MATCHING, + IS_DEV, + getCIMergeRequestIID, +} from "../utils/get-environment-variables.js"; import { auth, - getConnectorImage, getCertificationImage, + getConnectorImage, getGitLabEnvironments, truncate, } from "../utils/index.js"; -import stringify from "json-stringify-safe"; import { - getSetResourceOnAssetComment, - getErrorResponseStatus401, - getErrorResponseStatusUndefined, + createResource, + getAsset, + getClassifications, + getDownstreamAssets, + sendSegmentEvent, +} from "../api/index.js"; +import { getAssetInfo, getDownstreamTable, - getViewAssetButton, - getMDCommentForModel, + getErrorResponseStatus401, + getErrorResponseStatusUndefined, getMDCommentForMaterialisedView, + getMDCommentForModel, + getSetResourceOnAssetComment, getTableMD, + getViewAssetButton, } from "../templates/gitlab-integration.js"; -import { getNewModelAddedComment, getBaseComment } from "../templates/atlan.js"; -import { - IS_DEV, - ATLAN_INSTANCE_URL, - CI_PROJECT_PATH, - CI_PROJECT_ID, - CI_JOB_URL, - IGNORE_MODEL_ALIAS_MATCHING, - CI_COMMIT_MESSAGE, - CI_PROJECT_NAME, - CI_COMMIT_SHA, - getCIMergeRequestIID, - CI_PROJECT_NAMESPACE, -} from "../utils/get-environment-variables.js"; +import { getBaseComment, getNewModelAddedComment } from "../templates/atlan.js"; + +import { Gitlab } from "@gitbeaker/rest"; +// gitlabIntegration.js +import IntegrationInterface from "./contract/contract.js"; import logger from "../logger/logger.js"; +import stringify from "json-stringify-safe"; const integrationName = "gitlab"; var CI_MERGE_REQUEST_IID; @@ -647,6 +648,8 @@ ${content}`; ...properties, gitlab_job_id: CI_JOB_URL, domain, + base_asset_type: "dbtModel", + action_repo_name: "atlan-action" }, }); diff --git a/dist/index.js b/dist/index.js index ba514bc..c63786d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29790,7 +29790,7 @@ var jsYaml = { var headSHA; const integrationName = "GITHUB_CONTRACT_IMPACT_ANALYSIS"; -const actionName = "contract_ci_action" +const actionName = "dbt_ci_action" const utmSource = "dbt_github_action" class ContractIntegration extends IntegrationInterface { @@ -30224,6 +30224,8 @@ class ContractIntegration extends IntegrationInterface { ...properties, github_action_id: `https://github.com/${context?.payload?.repository?.full_name}/actions/runs/${context?.runId}`, domain, + base_asset_type: "atlanContract", + action_repo_name: "atlan-action" }, }); @@ -30629,13 +30631,15 @@ ${viewAssetButton}`; } ;// CONCATENATED MODULE: ./adapters/integrations/github-integration.js -// githubIntegration.js +// githubIntegration.js + + @@ -31180,6 +31184,8 @@ class GitHubIntegration extends IntegrationInterface { ...properties, github_action_id: `https://github.com/${context?.payload?.repository?.full_name}/actions/runs/${context?.runId}`, domain, + base_asset_type: "dbtModel", + action_repo_name: "atlan-action" }, }); @@ -31647,6 +31653,111 @@ ${viewAssetButton}`; } } +;// CONCATENATED MODULE: ./adapters/templates/gitlab-integration.js + + +function gitlab_integration_getErrorResponseStatus401 (ATLAN_INSTANCE_URL, CI_PROJECT_NAME, CI_PROJECT_NAMESPACE) { + return `We couldn't connect to your Atlan Instance, please make sure to set the valid Atlan Bearer Token as \`ATLAN_API_TOKEN\` as this repository's CI/CD variable. + +Atlan Instance URL: ${ATLAN_INSTANCE_URL} + +Set your CI/CD variables [here](https://gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/-/settings/ci_cd). For more information on how to setup the Atlan Action, please read the [setup documentation here](https://ask.atlan.com/hc/en-us/articles/8284983222415).` +} + +function gitlab_integration_getErrorResponseStatusUndefined(ATLAN_INSTANCE_URL, CI_PROJECT_NAME, CI_PROJECT_NAMESPACE) { + return `We couldn't connect to your Atlan Instance, please make sure to set the valid Atlan Instance URL as \`ATLAN_INSTANCE_URL\` as this repository's CI/CD variable. + +Atlan Instance URL: ${ATLAN_INSTANCE_URL} + +Make sure your Atlan Instance URL is set in the following format. +\`https://tenant.atlan.com\` + +Set your CI/CD variables [here](https://gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/-/settings/ci_cd). For more information on how to setup the Atlan Action, please read the [setup documentation here](https://ask.atlan.com/hc/en-us/articles/8284983222415).` +} + +function gitlab_integration_getSetResourceOnAssetComment(tableMd, setResourceFailed) { + return `## 🎊 Congrats on the merge! + + This pull request has been added as a resource to the following assets: + + ${setResourceFailed ? '> ⚠️ Seems like we were unable to set the resources for some of the assets due to insufficient permissions. To ensure that the pull request is linked as a resource, you will need to assign the right persona with requisite permissions to the API token.' : ''} + + Name | Resource set successfully + --- | --- + ${tableMd} + ` +} + +function gitlab_integration_getAssetInfo(ATLAN_INSTANCE_URL, asset, materialisedAsset, environmentName, projectName) { + return `### ${get_image_url_getConnectorImage( + asset.attributes.connectorName + )} [${asset.displayText}](${ATLAN_INSTANCE_URL}/assets/${ + asset.guid + }/overview?utm_source=dbt_gitlab_action) ${ + asset.attributes?.certificateStatus + ? get_image_url_getCertificationImage(asset.attributes.certificateStatus) + : "" + } +Materialised asset: ${get_image_url_getConnectorImage( + materialisedAsset.attributes.connectorName + )} [${materialisedAsset.attributes.name}](${ATLAN_INSTANCE_URL}/assets/${ + materialisedAsset.guid + }/overview?utm_source=dbt_gitlab_action) ${ + materialisedAsset.attributes?.certificateStatus + ? get_image_url_getCertificationImage(materialisedAsset.attributes.certificateStatus) + : "" + }${environmentName ? ` | Environment Name: \`${environmentName}\`` : ""}${ + projectName ? ` | Project Name: \`${projectName}\`` : "" + }` +} + +function gitlab_integration_getDownstreamTable(ATLAN_INSTANCE_URL, downstreamAssets, rows, materialisedAsset) { + return `
${ + downstreamAssets.entityCount + } downstream assets 👇
+ +Name | Type | Description | Owners | Terms | Classifications | Source URL +--- | --- | --- | --- | --- | --- | --- +${rows + .map((row) => + row.map((i) => i.replace(/\|/g, "•").replace(/\n/g, "")).join(" | ") + ) + .join("\n")} + +${ + downstreamAssets.hasMore + ? `[See more downstream assets at Atlan](${ATLAN_INSTANCE_URL}/assets/${materialisedAsset.guid}/lineage?utm_source=dbt_gitlab_action)` + : "" +} + +
` +} + +function gitlab_integration_getViewAssetButton(ATLAN_INSTANCE_URL, asset) { + return `${get_image_url_getImageURL( + "atlan-logo", + 15, + 15 + )} [View asset in Atlan](${ATLAN_INSTANCE_URL}/assets/${ + asset.guid + }/overview?utm_source=dbt_gitlab_action)` +} + +function gitlab_integration_getMDCommentForModel(ATLAN_INSTANCE_URL, model) { + return `${get_image_url_getConnectorImage(model?.attributes?.connectorName)} [${ + model?.displayText + }](${ATLAN_INSTANCE_URL}/assets/${model?.guid}/overview?utm_source=dbt_gitlab_action)` +} + +function gitlab_integration_getMDCommentForMaterialisedView(ATLAN_INSTANCE_URL, materialisedView) { + return `${get_image_url_getConnectorImage(materialisedView?.attributes?.connectorName)} [${ + materialisedView?.attributes?.name + }](${ATLAN_INSTANCE_URL}/assets/${materialisedView?.guid}/overview?utm_source=dbt_gitlab_action)` +} + +function gitlab_integration_getTableMD(md, resp) { + return `${md} | ${resp ? '✅' : '❌'} \n` +} // EXTERNAL MODULE: ./node_modules/qs/lib/index.js var lib = __nccwpck_require__(240); // EXTERNAL MODULE: ./node_modules/xcase/es5/index.js @@ -39059,122 +39170,18 @@ var { -;// CONCATENATED MODULE: ./adapters/templates/gitlab-integration.js - - -function gitlab_integration_getErrorResponseStatus401 (ATLAN_INSTANCE_URL, CI_PROJECT_NAME, CI_PROJECT_NAMESPACE) { - return `We couldn't connect to your Atlan Instance, please make sure to set the valid Atlan Bearer Token as \`ATLAN_API_TOKEN\` as this repository's CI/CD variable. - -Atlan Instance URL: ${ATLAN_INSTANCE_URL} - -Set your CI/CD variables [here](https://gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/-/settings/ci_cd). For more information on how to setup the Atlan Action, please read the [setup documentation here](https://ask.atlan.com/hc/en-us/articles/8284983222415).` -} - -function gitlab_integration_getErrorResponseStatusUndefined(ATLAN_INSTANCE_URL, CI_PROJECT_NAME, CI_PROJECT_NAMESPACE) { - return `We couldn't connect to your Atlan Instance, please make sure to set the valid Atlan Instance URL as \`ATLAN_INSTANCE_URL\` as this repository's CI/CD variable. - -Atlan Instance URL: ${ATLAN_INSTANCE_URL} - -Make sure your Atlan Instance URL is set in the following format. -\`https://tenant.atlan.com\` - -Set your CI/CD variables [here](https://gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/-/settings/ci_cd). For more information on how to setup the Atlan Action, please read the [setup documentation here](https://ask.atlan.com/hc/en-us/articles/8284983222415).` -} - -function gitlab_integration_getSetResourceOnAssetComment(tableMd, setResourceFailed) { - return `## 🎊 Congrats on the merge! - - This pull request has been added as a resource to the following assets: - - ${setResourceFailed ? '> ⚠️ Seems like we were unable to set the resources for some of the assets due to insufficient permissions. To ensure that the pull request is linked as a resource, you will need to assign the right persona with requisite permissions to the API token.' : ''} - - Name | Resource set successfully - --- | --- - ${tableMd} - ` -} - -function gitlab_integration_getAssetInfo(ATLAN_INSTANCE_URL, asset, materialisedAsset, environmentName, projectName) { - return `### ${get_image_url_getConnectorImage( - asset.attributes.connectorName - )} [${asset.displayText}](${ATLAN_INSTANCE_URL}/assets/${ - asset.guid - }/overview?utm_source=dbt_gitlab_action) ${ - asset.attributes?.certificateStatus - ? get_image_url_getCertificationImage(asset.attributes.certificateStatus) - : "" - } -Materialised asset: ${get_image_url_getConnectorImage( - materialisedAsset.attributes.connectorName - )} [${materialisedAsset.attributes.name}](${ATLAN_INSTANCE_URL}/assets/${ - materialisedAsset.guid - }/overview?utm_source=dbt_gitlab_action) ${ - materialisedAsset.attributes?.certificateStatus - ? get_image_url_getCertificationImage(materialisedAsset.attributes.certificateStatus) - : "" - }${environmentName ? ` | Environment Name: \`${environmentName}\`` : ""}${ - projectName ? ` | Project Name: \`${projectName}\`` : "" - }` -} +;// CONCATENATED MODULE: ./adapters/integrations/gitlab-integration.js -function gitlab_integration_getDownstreamTable(ATLAN_INSTANCE_URL, downstreamAssets, rows, materialisedAsset) { - return `
${ - downstreamAssets.entityCount - } downstream assets 👇
-Name | Type | Description | Owners | Terms | Classifications | Source URL ---- | --- | --- | --- | --- | --- | --- -${rows - .map((row) => - row.map((i) => i.replace(/\|/g, "•").replace(/\n/g, "")).join(" | ") - ) - .join("\n")} -${ - downstreamAssets.hasMore - ? `[See more downstream assets at Atlan](${ATLAN_INSTANCE_URL}/assets/${materialisedAsset.guid}/lineage?utm_source=dbt_gitlab_action)` - : "" -} -
` -} -function gitlab_integration_getViewAssetButton(ATLAN_INSTANCE_URL, asset) { - return `${get_image_url_getImageURL( - "atlan-logo", - 15, - 15 - )} [View asset in Atlan](${ATLAN_INSTANCE_URL}/assets/${ - asset.guid - }/overview?utm_source=dbt_gitlab_action)` -} -function gitlab_integration_getMDCommentForModel(ATLAN_INSTANCE_URL, model) { - return `${get_image_url_getConnectorImage(model?.attributes?.connectorName)} [${ - model?.displayText - }](${ATLAN_INSTANCE_URL}/assets/${model?.guid}/overview?utm_source=dbt_gitlab_action)` -} - -function gitlab_integration_getMDCommentForMaterialisedView(ATLAN_INSTANCE_URL, materialisedView) { - return `${get_image_url_getConnectorImage(materialisedView?.attributes?.connectorName)} [${ - materialisedView?.attributes?.name - }](${ATLAN_INSTANCE_URL}/assets/${materialisedView?.guid}/overview?utm_source=dbt_gitlab_action)` -} -function gitlab_integration_getTableMD(md, resp) { - return `${md} | ${resp ? '✅' : '❌'} \n` -} -;// CONCATENATED MODULE: ./adapters/integrations/gitlab-integration.js // gitlabIntegration.js - - - - - - const gitlab_integration_integrationName = "gitlab"; var CI_MERGE_REQUEST_IID; @@ -39780,6 +39787,8 @@ ${content}`; ...properties, gitlab_job_id: CI_JOB_URL, domain, + base_asset_type: "dbtModel", + action_repo_name: "atlan-action" }, });