Skip to content

Commit

Permalink
fix: show proper error message if setting resource failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaagrav committed Nov 2, 2023
1 parent 1f5fcc0 commit 8f8b50a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/api/create-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ export default async function createResource(guid, name, link) {

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

if(response?.errorCode) {
return null
}

return response;
}
73 changes: 60 additions & 13 deletions src/main/set-resource-on-asset.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
}

0 comments on commit 8f8b50a

Please sign in to comment.