From 1f5fcc0eb72869234c2595710a8098f2e83ab077 Mon Sep 17 00:00:00 2001 From: Jaagrav Date: Thu, 19 Oct 2023 20:10:55 +0530 Subject: [PATCH 1/5] fix: use whoami to confirm successful auth --- src/utils/auth.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/auth.js b/src/utils/auth.js index 5964c22..455ff35 100644 --- a/src/utils/auth.js +++ b/src/utils/auth.js @@ -14,12 +14,12 @@ export default async function auth(octokit, context) { }; var requestOptions = { - method: "POST", + method: "GET", headers: myHeaders, }; var response = await fetch( - `${ATLAN_INSTANCE_URL}/api/meta`, + `${ATLAN_INSTANCE_URL}/api/service/whoami`, requestOptions ).catch((err) => { }); @@ -52,4 +52,4 @@ Set your repository action secrets [here](https://github.com/${context.payload.r } return true -} \ No newline at end of file +} From 8f8b50a892be0ca6f22e1d689b2c3f72e0c7e358 Mon Sep 17 00:00:00 2001 From: Jaagrav Date: Fri, 3 Nov 2023 01:37:08 +0530 Subject: [PATCH 2/5] fix: show proper error message if setting resource failed --- src/api/create-resource.js | 4 ++ src/main/set-resource-on-asset.js | 73 +++++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/src/api/create-resource.js b/src/api/create-resource.js index 7a6c2a2..193eaf3 100644 --- a/src/api/create-resource.js +++ b/src/api/create-resource.js @@ -54,5 +54,9 @@ export default async function createResource(guid, name, link) { console.log("Created Resource:", response) + if(response?.errorCode) { + return null + } + return response; } diff --git a/src/main/set-resource-on-asset.js b/src/main/set-resource-on-asset.js index db493bc..3316189 100644 --- a/src/main/set-resource-on-asset.js +++ b/src/main/set-resource-on-asset.js @@ -1,17 +1,27 @@ -import { getAsset, createResource } from "../api/index.js"; +import { getAsset, createResource, getDownstreamAssets } from "../api/index.js"; import { createIssueComment, getChangedFiles, getAssetName, + getInstanceUrl, + getConnectorImage, } from "../utils/index.js"; +const ATLAN_INSTANCE_URL = + getInstanceUrl(); + export default async function setResourceOnAsset({ octokit, context }) { const changedFiles = await getChangedFiles(octokit, context); const { pull_request } = context.payload; - var totalChangedFiles = 0; + let tableMd = ``; + let setResourceFailed = false if (changedFiles.length === 0) return; + const totalModifiedFiles = changedFiles.filter( + (i) => i.status === "modified" + ).length; + for (const { fileName, filePath } of changedFiles) { const assetName = await getAssetName({ octokit, @@ -23,36 +33,73 @@ export default async function setResourceOnAsset({ octokit, context }) { if (asset.error) continue; - const { guid: modelGuid } = asset; - const { guid: tableAssetGuid } = asset?.attributes?.dbtModelSqlAssets?.[0]; + const model = asset; + const materialisedView = asset?.attributes?.dbtModelSqlAssets?.[0]; + + if(!materialisedView) continue; + + const downstreamAssets = await getDownstreamAssets( + asset, + materialisedView.guid, + totalModifiedFiles + ); - if (modelGuid) - await createResource( + if(!downstreamAssets?.entities?.length) continue; + + if (model) { + const { guid: modelGuid } = model + const resp = await createResource( modelGuid, - "Pull Request on GitHub", + pull_request.title, pull_request.html_url ); + const md = `${getConnectorImage(model.attributes.connectorName)} [${ + model.displayText + }](${ATLAN_INSTANCE_URL}/assets/${model.guid}/overview?utm_source=dbt_github_action)` + + tableMd += `${md} | ${resp ? '✅' : '❌'} \n`; - if (tableAssetGuid) - await createResource( + if(!resp) setResourceFailed = true + } + + if (materialisedView) { + const { guid: tableAssetGuid } = materialisedView + const resp = await createResource( tableAssetGuid, "Pull Request on GitHub", pull_request.html_url ); + const md = `${getConnectorImage(materialisedView.attributes.connectorName)} [${ + materialisedView.attributes.name + }](${ATLAN_INSTANCE_URL}/assets/${materialisedView.guid}/overview?utm_source=dbt_github_action)` + + tableMd += `${md} | ${resp ? '✅' : '❌'}\n`; + + if(!resp) setResourceFailed = true + } + } - totalChangedFiles++; + if(!tableMd) { + console.log("No assets have downstream assets.") + return totalModifiedFiles; } const comment = await createIssueComment( octokit, context, - `🎊 Congrats on the merge! + `## 🎊 Congrats on the merge! -This pull request has been added as a resource to all the assets modified. ✅ +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} `, null, true ); - return totalChangedFiles; + return totalModifiedFiles; } From d0a495a39f7213b50a7b992a375a0356f36a7a00 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 2 Nov 2023 20:08:12 +0000 Subject: [PATCH 3/5] chore: Update dist --- dist/index.js | 78 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 14 deletions(-) diff --git a/dist/index.js b/dist/index.js index eb6b9b3..13e262f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -18108,12 +18108,12 @@ async function auth(octokit, context) { }; var requestOptions = { - method: "POST", + method: "GET", headers: myHeaders, }; var response = await fetch( - `${auth_ATLAN_INSTANCE_URL}/api/meta`, + `${auth_ATLAN_INSTANCE_URL}/api/service/whoami`, requestOptions ).catch((err) => { }); @@ -18147,6 +18147,7 @@ Set your repository action secrets [here](https://github.com/${context.payload.r return true } + ;// CONCATENATED MODULE: ./src/utils/index.js @@ -18486,6 +18487,10 @@ async function createResource(guid, name, link) { console.log("Created Resource:", response) + if(response?.errorCode) { + return null + } + return response; } @@ -18651,13 +18656,21 @@ ${comments}`; +const set_resource_on_asset_ATLAN_INSTANCE_URL = + getInstanceUrl(); + async function setResourceOnAsset({ octokit, context }) { const changedFiles = await getChangedFiles(octokit, context); const { pull_request } = context.payload; - var totalChangedFiles = 0; + let tableMd = ``; + let setResourceFailed = false if (changedFiles.length === 0) return; + const totalModifiedFiles = changedFiles.filter( + (i) => i.status === "modified" + ).length; + for (const { fileName, filePath } of changedFiles) { const assetName = await getAssetName({ octokit, @@ -18669,38 +18682,75 @@ async function setResourceOnAsset({ octokit, context }) { if (asset.error) continue; - const { guid: modelGuid } = asset; - const { guid: tableAssetGuid } = asset?.attributes?.dbtModelSqlAssets?.[0]; + const model = asset; + const materialisedView = asset?.attributes?.dbtModelSqlAssets?.[0]; + + if(!materialisedView) continue; + + const downstreamAssets = await getDownstreamAssets( + asset, + materialisedView.guid, + totalModifiedFiles + ); + + if(!downstreamAssets?.entities?.length) continue; - if (modelGuid) - await createResource( + if (model) { + const { guid: modelGuid } = model + const resp = await createResource( modelGuid, - "Pull Request on GitHub", + pull_request.title, pull_request.html_url ); + const md = `${getConnectorImage(model.attributes.connectorName)} [${ + model.displayText + }](${set_resource_on_asset_ATLAN_INSTANCE_URL}/assets/${model.guid}/overview?utm_source=dbt_github_action)` - if (tableAssetGuid) - await createResource( + tableMd += `${md} | ${resp ? '✅' : '❌'} \n`; + + if(!resp) setResourceFailed = true + } + + if (materialisedView) { + const { guid: tableAssetGuid } = materialisedView + const resp = await createResource( tableAssetGuid, "Pull Request on GitHub", pull_request.html_url ); + const md = `${getConnectorImage(materialisedView.attributes.connectorName)} [${ + materialisedView.attributes.name + }](${set_resource_on_asset_ATLAN_INSTANCE_URL}/assets/${materialisedView.guid}/overview?utm_source=dbt_github_action)` - totalChangedFiles++; + tableMd += `${md} | ${resp ? '✅' : '❌'}\n`; + + if(!resp) setResourceFailed = true + } + } + + if(!tableMd) { + console.log("No assets have downstream assets.") + return totalModifiedFiles; } const comment = await createIssueComment( octokit, context, - `🎊 Congrats on the merge! + `## 🎊 Congrats on the merge! -This pull request has been added as a resource to all the assets modified. ✅ +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} `, null, true ); - return totalChangedFiles; + return totalModifiedFiles; } ;// CONCATENATED MODULE: ./src/main/index.js From 08f6613a4bcc7084a07820bd8a9f75dd89acbe8a Mon Sep 17 00:00:00 2001 From: Jaagrav Date: Fri, 3 Nov 2023 02:25:44 +0530 Subject: [PATCH 4/5] fix: add ignore alias to add resource --- src/main/set-resource-on-asset.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/set-resource-on-asset.js b/src/main/set-resource-on-asset.js index 3316189..58819cc 100644 --- a/src/main/set-resource-on-asset.js +++ b/src/main/set-resource-on-asset.js @@ -1,4 +1,5 @@ import { getAsset, createResource, getDownstreamAssets } from "../api/index.js"; +import { isIgnoreModelAliasMatching } from "../utils/get-environment-variables.js"; import { createIssueComment, getChangedFiles, @@ -23,12 +24,13 @@ export default async function setResourceOnAsset({ octokit, context }) { ).length; for (const { fileName, filePath } of changedFiles) { - const assetName = await getAssetName({ + const aliasName = await getAssetName({ octokit, context, fileName, filePath, }); + const assetName = isIgnoreModelAliasMatching() ? fileName : aliasName; const asset = await getAsset({ name: assetName }); if (asset.error) continue; @@ -66,7 +68,7 @@ export default async function setResourceOnAsset({ octokit, context }) { const { guid: tableAssetGuid } = materialisedView const resp = await createResource( tableAssetGuid, - "Pull Request on GitHub", + pull_request.title, pull_request.html_url ); const md = `${getConnectorImage(materialisedView.attributes.connectorName)} [${ From ec0b41f70ff42a8898cf6b222e2a30556c36d127 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 2 Nov 2023 20:56:57 +0000 Subject: [PATCH 5/5] chore: Update dist --- dist/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 13e262f..7fd5337 100644 --- a/dist/index.js +++ b/dist/index.js @@ -18656,6 +18656,7 @@ ${comments}`; + const set_resource_on_asset_ATLAN_INSTANCE_URL = getInstanceUrl(); @@ -18672,12 +18673,13 @@ async function setResourceOnAsset({ octokit, context }) { ).length; for (const { fileName, filePath } of changedFiles) { - const assetName = await getAssetName({ + const aliasName = await getAssetName({ octokit, context, fileName, filePath, }); + const assetName = isIgnoreModelAliasMatching() ? fileName : aliasName; const asset = await getAsset({ name: assetName }); if (asset.error) continue; @@ -18715,7 +18717,7 @@ async function setResourceOnAsset({ octokit, context }) { const { guid: tableAssetGuid } = materialisedView const resp = await createResource( tableAssetGuid, - "Pull Request on GitHub", + pull_request.title, pull_request.html_url ); const md = `${getConnectorImage(materialisedView.attributes.connectorName)} [${