Skip to content

Commit

Permalink
Merge pull request #117 from atlanhq/staging
Browse files Browse the repository at this point in the history
Main << Staging
  • Loading branch information
Jaagrav authored Nov 2, 2023
2 parents a20ed0c + ec0b41f commit 5a8ae85
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 34 deletions.
84 changes: 68 additions & 16 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
});
Expand Down Expand Up @@ -18147,6 +18147,7 @@ Set your repository action secrets [here](https://github.com/${context.payload.r

return true
}

;// CONCATENATED MODULE: ./src/utils/index.js


Expand Down Expand Up @@ -18486,6 +18487,10 @@ async function createResource(guid, name, link) {

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

if(response?.errorCode) {
return null
}

return response;
}

Expand Down Expand Up @@ -18651,56 +18656,103 @@ ${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({
const aliasName = await getAssetName({
octokit,
context,
fileName,
filePath,
});
const assetName = isIgnoreModelAliasMatching() ? fileName : aliasName;
const asset = await getAsset({ name: assetName });

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)`

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.title,
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
Expand Down
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;
}
79 changes: 64 additions & 15 deletions src/main/set-resource-on-asset.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,107 @@
import { getAsset, createResource } from "../api/index.js";
import { getAsset, createResource, getDownstreamAssets } from "../api/index.js";
import { isIgnoreModelAliasMatching } from "../utils/get-environment-variables.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({
const aliasName = await getAssetName({
octokit,
context,
fileName,
filePath,
});
const assetName = isIgnoreModelAliasMatching() ? fileName : aliasName;
const asset = await getAsset({ name: assetName });

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;

if (modelGuid)
await createResource(
const downstreamAssets = await getDownstreamAssets(
asset,
materialisedView.guid,
totalModifiedFiles
);

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.title,
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;
}
6 changes: 3 additions & 3 deletions src/utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
});
Expand Down Expand Up @@ -52,4 +52,4 @@ Set your repository action secrets [here](https://github.com/${context.payload.r
}

return true
}
}

0 comments on commit 5a8ae85

Please sign in to comment.