Skip to content

Commit 5a8ae85

Browse files
authored
Merge pull request #117 from atlanhq/staging
Main << Staging
2 parents a20ed0c + ec0b41f commit 5a8ae85

File tree

4 files changed

+139
-34
lines changed

4 files changed

+139
-34
lines changed

dist/index.js

+68-16
Original file line numberDiff line numberDiff line change
@@ -18108,12 +18108,12 @@ async function auth(octokit, context) {
1810818108
};
1810918109

1811018110
var requestOptions = {
18111-
method: "POST",
18111+
method: "GET",
1811218112
headers: myHeaders,
1811318113
};
1811418114

1811518115
var response = await fetch(
18116-
`${auth_ATLAN_INSTANCE_URL}/api/meta`,
18116+
`${auth_ATLAN_INSTANCE_URL}/api/service/whoami`,
1811718117
requestOptions
1811818118
).catch((err) => {
1811918119
});
@@ -18147,6 +18147,7 @@ Set your repository action secrets [here](https://github.com/${context.payload.r
1814718147

1814818148
return true
1814918149
}
18150+
1815018151
;// CONCATENATED MODULE: ./src/utils/index.js
1815118152

1815218153

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

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

18490+
if(response?.errorCode) {
18491+
return null
18492+
}
18493+
1848918494
return response;
1849018495
}
1849118496

@@ -18651,56 +18656,103 @@ ${comments}`;
1865118656

1865218657

1865318658

18659+
18660+
const set_resource_on_asset_ATLAN_INSTANCE_URL =
18661+
getInstanceUrl();
18662+
1865418663
async function setResourceOnAsset({ octokit, context }) {
1865518664
const changedFiles = await getChangedFiles(octokit, context);
1865618665
const { pull_request } = context.payload;
18657-
var totalChangedFiles = 0;
18666+
let tableMd = ``;
18667+
let setResourceFailed = false
1865818668

1865918669
if (changedFiles.length === 0) return;
1866018670

18671+
const totalModifiedFiles = changedFiles.filter(
18672+
(i) => i.status === "modified"
18673+
).length;
18674+
1866118675
for (const { fileName, filePath } of changedFiles) {
18662-
const assetName = await getAssetName({
18676+
const aliasName = await getAssetName({
1866318677
octokit,
1866418678
context,
1866518679
fileName,
1866618680
filePath,
1866718681
});
18682+
const assetName = isIgnoreModelAliasMatching() ? fileName : aliasName;
1866818683
const asset = await getAsset({ name: assetName });
1866918684

1867018685
if (asset.error) continue;
1867118686

18672-
const { guid: modelGuid } = asset;
18673-
const { guid: tableAssetGuid } = asset?.attributes?.dbtModelSqlAssets?.[0];
18687+
const model = asset;
18688+
const materialisedView = asset?.attributes?.dbtModelSqlAssets?.[0];
18689+
18690+
if(!materialisedView) continue;
18691+
18692+
const downstreamAssets = await getDownstreamAssets(
18693+
asset,
18694+
materialisedView.guid,
18695+
totalModifiedFiles
18696+
);
18697+
18698+
if(!downstreamAssets?.entities?.length) continue;
1867418699

18675-
if (modelGuid)
18676-
await createResource(
18700+
if (model) {
18701+
const { guid: modelGuid } = model
18702+
const resp = await createResource(
1867718703
modelGuid,
18678-
"Pull Request on GitHub",
18704+
pull_request.title,
1867918705
pull_request.html_url
1868018706
);
18707+
const md = `${getConnectorImage(model.attributes.connectorName)} [${
18708+
model.displayText
18709+
}](${set_resource_on_asset_ATLAN_INSTANCE_URL}/assets/${model.guid}/overview?utm_source=dbt_github_action)`
18710+
18711+
tableMd += `${md} | ${resp ? '✅' : '❌'} \n`;
1868118712

18682-
if (tableAssetGuid)
18683-
await createResource(
18713+
if(!resp) setResourceFailed = true
18714+
}
18715+
18716+
if (materialisedView) {
18717+
const { guid: tableAssetGuid } = materialisedView
18718+
const resp = await createResource(
1868418719
tableAssetGuid,
18685-
"Pull Request on GitHub",
18720+
pull_request.title,
1868618721
pull_request.html_url
1868718722
);
18723+
const md = `${getConnectorImage(materialisedView.attributes.connectorName)} [${
18724+
materialisedView.attributes.name
18725+
}](${set_resource_on_asset_ATLAN_INSTANCE_URL}/assets/${materialisedView.guid}/overview?utm_source=dbt_github_action)`
1868818726

18689-
totalChangedFiles++;
18727+
tableMd += `${md} | ${resp ? '✅' : '❌'}\n`;
18728+
18729+
if(!resp) setResourceFailed = true
18730+
}
18731+
}
18732+
18733+
if(!tableMd) {
18734+
console.log("No assets have downstream assets.")
18735+
return totalModifiedFiles;
1869018736
}
1869118737

1869218738
const comment = await createIssueComment(
1869318739
octokit,
1869418740
context,
18695-
`🎊 Congrats on the merge!
18741+
`## 🎊 Congrats on the merge!
1869618742

18697-
This pull request has been added as a resource to all the assets modified. ✅
18743+
This pull request has been added as a resource to the following assets:
18744+
18745+
${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.' : ''}
18746+
18747+
Name | Resource set successfully
18748+
--- | ---
18749+
${tableMd}
1869818750
`,
1869918751
null,
1870018752
true
1870118753
);
1870218754

18703-
return totalChangedFiles;
18755+
return totalModifiedFiles;
1870418756
}
1870518757

1870618758
;// CONCATENATED MODULE: ./src/main/index.js

src/api/create-resource.js

+4
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,9 @@ export default async function createResource(guid, name, link) {
5454

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

57+
if(response?.errorCode) {
58+
return null
59+
}
60+
5761
return response;
5862
}

src/main/set-resource-on-asset.js

+64-15
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,107 @@
1-
import { getAsset, createResource } from "../api/index.js";
1+
import { getAsset, createResource, getDownstreamAssets } from "../api/index.js";
2+
import { isIgnoreModelAliasMatching } from "../utils/get-environment-variables.js";
23
import {
34
createIssueComment,
45
getChangedFiles,
56
getAssetName,
7+
getInstanceUrl,
8+
getConnectorImage,
69
} from "../utils/index.js";
710

11+
const ATLAN_INSTANCE_URL =
12+
getInstanceUrl();
13+
814
export default async function setResourceOnAsset({ octokit, context }) {
915
const changedFiles = await getChangedFiles(octokit, context);
1016
const { pull_request } = context.payload;
11-
var totalChangedFiles = 0;
17+
let tableMd = ``;
18+
let setResourceFailed = false
1219

1320
if (changedFiles.length === 0) return;
1421

22+
const totalModifiedFiles = changedFiles.filter(
23+
(i) => i.status === "modified"
24+
).length;
25+
1526
for (const { fileName, filePath } of changedFiles) {
16-
const assetName = await getAssetName({
27+
const aliasName = await getAssetName({
1728
octokit,
1829
context,
1930
fileName,
2031
filePath,
2132
});
33+
const assetName = isIgnoreModelAliasMatching() ? fileName : aliasName;
2234
const asset = await getAsset({ name: assetName });
2335

2436
if (asset.error) continue;
2537

26-
const { guid: modelGuid } = asset;
27-
const { guid: tableAssetGuid } = asset?.attributes?.dbtModelSqlAssets?.[0];
38+
const model = asset;
39+
const materialisedView = asset?.attributes?.dbtModelSqlAssets?.[0];
40+
41+
if(!materialisedView) continue;
2842

29-
if (modelGuid)
30-
await createResource(
43+
const downstreamAssets = await getDownstreamAssets(
44+
asset,
45+
materialisedView.guid,
46+
totalModifiedFiles
47+
);
48+
49+
if(!downstreamAssets?.entities?.length) continue;
50+
51+
if (model) {
52+
const { guid: modelGuid } = model
53+
const resp = await createResource(
3154
modelGuid,
32-
"Pull Request on GitHub",
55+
pull_request.title,
3356
pull_request.html_url
3457
);
58+
const md = `${getConnectorImage(model.attributes.connectorName)} [${
59+
model.displayText
60+
}](${ATLAN_INSTANCE_URL}/assets/${model.guid}/overview?utm_source=dbt_github_action)`
61+
62+
tableMd += `${md} | ${resp ? '✅' : '❌'} \n`;
3563

36-
if (tableAssetGuid)
37-
await createResource(
64+
if(!resp) setResourceFailed = true
65+
}
66+
67+
if (materialisedView) {
68+
const { guid: tableAssetGuid } = materialisedView
69+
const resp = await createResource(
3870
tableAssetGuid,
39-
"Pull Request on GitHub",
71+
pull_request.title,
4072
pull_request.html_url
4173
);
74+
const md = `${getConnectorImage(materialisedView.attributes.connectorName)} [${
75+
materialisedView.attributes.name
76+
}](${ATLAN_INSTANCE_URL}/assets/${materialisedView.guid}/overview?utm_source=dbt_github_action)`
77+
78+
tableMd += `${md} | ${resp ? '✅' : '❌'}\n`;
79+
80+
if(!resp) setResourceFailed = true
81+
}
82+
}
4283

43-
totalChangedFiles++;
84+
if(!tableMd) {
85+
console.log("No assets have downstream assets.")
86+
return totalModifiedFiles;
4487
}
4588

4689
const comment = await createIssueComment(
4790
octokit,
4891
context,
49-
`🎊 Congrats on the merge!
92+
`## 🎊 Congrats on the merge!
5093
51-
This pull request has been added as a resource to all the assets modified. ✅
94+
This pull request has been added as a resource to the following assets:
95+
96+
${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.' : ''}
97+
98+
Name | Resource set successfully
99+
--- | ---
100+
${tableMd}
52101
`,
53102
null,
54103
true
55104
);
56105

57-
return totalChangedFiles;
106+
return totalModifiedFiles;
58107
}

src/utils/auth.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ export default async function auth(octokit, context) {
1414
};
1515

1616
var requestOptions = {
17-
method: "POST",
17+
method: "GET",
1818
headers: myHeaders,
1919
};
2020

2121
var response = await fetch(
22-
`${ATLAN_INSTANCE_URL}/api/meta`,
22+
`${ATLAN_INSTANCE_URL}/api/service/whoami`,
2323
requestOptions
2424
).catch((err) => {
2525
});
@@ -52,4 +52,4 @@ Set your repository action secrets [here](https://github.com/${context.payload.r
5252
}
5353

5454
return true
55-
}
55+
}

0 commit comments

Comments
 (0)