-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from atlanhq/ACTIV-1019-project-and-environme…
…nt-name-showing-up-as-undefined fix: project name and environment name showing as undefined
- Loading branch information
Showing
4 changed files
with
147 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,105 @@ | ||
import { | ||
getAsset, getClassifications, | ||
getDownstreamAssets, | ||
sendSegmentEvent, | ||
getAsset, | ||
getClassifications, | ||
getDownstreamAssets, | ||
sendSegmentEvent, | ||
} from "../api/index.js"; | ||
import { | ||
renderDownstreamAssetsComment, | ||
getChangedFiles, | ||
getAssetName, createIssueComment, checkCommentExists, deleteComment, getImageURL, getConnectorImage | ||
renderDownstreamAssetsComment, | ||
getChangedFiles, | ||
getAssetName, | ||
createIssueComment, | ||
checkCommentExists, | ||
deleteComment, | ||
getImageURL, | ||
getConnectorImage, | ||
} from "../utils/index.js"; | ||
import {isIgnoreModelAliasMatching} from "../utils/get-environment-variables.js"; | ||
|
||
export default async function printDownstreamAssets({octokit, context}) { | ||
const changedFiles = await getChangedFiles(octokit, context); | ||
let comments = ``; | ||
let totalChangedFiles = 0; | ||
|
||
for (const {fileName, filePath, status} of changedFiles) { | ||
const aliasName = await getAssetName({octokit, context, fileName, filePath}); | ||
const assetName = isIgnoreModelAliasMatching() ? fileName : aliasName; | ||
const asset = await getAsset({name: assetName}); | ||
|
||
if (totalChangedFiles !== 0) | ||
comments += '\n\n---\n\n'; | ||
|
||
if (status === "added") { | ||
comments += `### ${getConnectorImage('dbt')} <b>${fileName}</b> 🆕 | ||
Its a new model and not present in Atlan yet, you'll see the downstream impact for it after its present in Atlan.` | ||
totalChangedFiles++ | ||
continue; | ||
} | ||
|
||
if (asset.error) { | ||
comments += asset.error; | ||
totalChangedFiles++ | ||
continue; | ||
} | ||
|
||
const materialisedAsset = asset.attributes.dbtModelSqlAssets[0]; | ||
const timeStart = Date.now(); | ||
const totalModifiedFiles = changedFiles.filter(i => i.status === "modified").length | ||
const downstreamAssets = await getDownstreamAssets(asset, materialisedAsset.guid, totalModifiedFiles); | ||
|
||
if (downstreamAssets.error) { | ||
comments += downstreamAssets.error; | ||
totalChangedFiles++ | ||
continue; | ||
} | ||
|
||
sendSegmentEvent("dbt_ci_action_downstream_unfurl", { | ||
asset_guid: asset.guid, | ||
asset_type: asset.typeName, | ||
downstream_count: downstreamAssets.entities.length, | ||
total_fetch_time: Date.now() - timeStart, | ||
}); | ||
|
||
const classifications = await getClassifications(); | ||
|
||
const comment = await renderDownstreamAssetsComment( | ||
octokit, | ||
context, | ||
asset, | ||
materialisedAsset, | ||
downstreamAssets, | ||
classifications | ||
) | ||
|
||
comments += comment; | ||
|
||
totalChangedFiles++ | ||
import { isIgnoreModelAliasMatching } from "../utils/get-environment-variables.js"; | ||
|
||
export default async function printDownstreamAssets({ octokit, context }) { | ||
const changedFiles = await getChangedFiles(octokit, context); | ||
let comments = ``; | ||
let totalChangedFiles = 0; | ||
|
||
for (const { fileName, filePath, status } of changedFiles) { | ||
const aliasName = await getAssetName({ | ||
octokit, | ||
context, | ||
fileName, | ||
filePath, | ||
}); | ||
const assetName = isIgnoreModelAliasMatching() ? fileName : aliasName; | ||
const asset = await getAsset({ name: assetName }); | ||
|
||
if (totalChangedFiles !== 0) comments += "\n\n---\n\n"; | ||
|
||
if (status === "added") { | ||
comments += `### ${getConnectorImage("dbt")} <b>${fileName}</b> 🆕 | ||
Its a new model and not present in Atlan yet, you'll see the downstream impact for it after its present in Atlan.`; | ||
totalChangedFiles++; | ||
continue; | ||
} | ||
|
||
comments = `### ${getImageURL("atlan-logo", 15, 15)} Atlan impact analysis | ||
Here is your downstream impact analysis for **${totalChangedFiles} ${totalChangedFiles > 1 ? "models" : "model"}** you have edited. | ||
if (asset.error) { | ||
comments += asset.error; | ||
totalChangedFiles++; | ||
continue; | ||
} | ||
|
||
const materialisedAsset = asset.attributes.dbtModelSqlAssets[0]; | ||
const timeStart = Date.now(); | ||
const totalModifiedFiles = changedFiles.filter( | ||
(i) => i.status === "modified" | ||
).length; | ||
const downstreamAssets = await getDownstreamAssets( | ||
asset, | ||
materialisedAsset.guid, | ||
totalModifiedFiles | ||
); | ||
|
||
if (downstreamAssets.error) { | ||
comments += downstreamAssets.error; | ||
totalChangedFiles++; | ||
continue; | ||
} | ||
|
||
sendSegmentEvent("dbt_ci_action_downstream_unfurl", { | ||
asset_guid: asset.guid, | ||
asset_type: asset.typeName, | ||
downstream_count: downstreamAssets.entities.length, | ||
total_fetch_time: Date.now() - timeStart, | ||
}); | ||
|
||
const classifications = await getClassifications(); | ||
|
||
const comment = await renderDownstreamAssetsComment( | ||
octokit, | ||
context, | ||
asset, | ||
materialisedAsset, | ||
downstreamAssets, | ||
classifications | ||
); | ||
|
||
comments += comment; | ||
|
||
totalChangedFiles++; | ||
} | ||
|
||
comments = `### ${getImageURL("atlan-logo", 15, 15)} Atlan impact analysis | ||
Here is your downstream impact analysis for **${totalChangedFiles} ${ | ||
totalChangedFiles > 1 ? "models" : "model" | ||
}** you have edited. | ||
${comments}` | ||
${comments}`; | ||
|
||
const existingComment = await checkCommentExists(octokit, context); | ||
const existingComment = await checkCommentExists(octokit, context); | ||
|
||
if (totalChangedFiles > 0) | ||
await createIssueComment(octokit, context, comments, existingComment?.id) | ||
if (totalChangedFiles > 0) | ||
await createIssueComment(octokit, context, comments, existingComment?.id); | ||
|
||
if (totalChangedFiles === 0 && existingComment) | ||
await deleteComment(octokit, context, existingComment.id) | ||
if (totalChangedFiles === 0 && existingComment) | ||
await deleteComment(octokit, context, existingComment.id); | ||
|
||
return totalChangedFiles; | ||
return totalChangedFiles; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,58 @@ | ||
import {getAsset, createResource} from "../api/index.js"; | ||
import { getAsset, createResource } from "../api/index.js"; | ||
import { | ||
createIssueComment, | ||
getChangedFiles, | ||
getAssetName, | ||
createIssueComment, | ||
getChangedFiles, | ||
getAssetName, | ||
} from "../utils/index.js"; | ||
|
||
export default async function setResourceOnAsset({octokit, context}) { | ||
const changedFiles = await getChangedFiles(octokit, context); | ||
const {pull_request} = context.payload; | ||
var totalChangedFiles = 0 | ||
|
||
if (changedFiles.length === 0) return; | ||
|
||
for (const {fileName, filePath} of changedFiles) { | ||
const assetName = await getAssetName({octokit, context, fileName, filePath}); | ||
const asset = await getAsset({name: assetName}); | ||
|
||
if (!asset) continue; | ||
|
||
const {guid: modelGuid} = asset; | ||
const {guid: tableAssetGuid} = asset.attributes.dbtModelSqlAssets[0]; | ||
|
||
await createResource( | ||
modelGuid, | ||
"Pull Request on GitHub", | ||
pull_request.html_url | ||
); | ||
await createResource( | ||
tableAssetGuid, | ||
"Pull Request on GitHub", | ||
pull_request.html_url | ||
); | ||
|
||
totalChangedFiles++ | ||
} | ||
|
||
const comment = await createIssueComment( | ||
octokit, | ||
context, | ||
`🎊 Congrats on the merge! | ||
export default async function setResourceOnAsset({ octokit, context }) { | ||
const changedFiles = await getChangedFiles(octokit, context); | ||
const { pull_request } = context.payload; | ||
var totalChangedFiles = 0; | ||
|
||
if (changedFiles.length === 0) return; | ||
|
||
for (const { fileName, filePath } of changedFiles) { | ||
const assetName = await getAssetName({ | ||
octokit, | ||
context, | ||
fileName, | ||
filePath, | ||
}); | ||
const asset = await getAsset({ name: assetName }); | ||
|
||
if (asset.error) continue; | ||
|
||
const { guid: modelGuid } = asset; | ||
const { guid: tableAssetGuid } = asset?.attributes?.dbtModelSqlAssets?.[0]; | ||
|
||
if (modelGuid) | ||
await createResource( | ||
modelGuid, | ||
"Pull Request on GitHub", | ||
pull_request.html_url | ||
); | ||
|
||
if (tableAssetGuid) | ||
await createResource( | ||
tableAssetGuid, | ||
"Pull Request on GitHub", | ||
pull_request.html_url | ||
); | ||
|
||
totalChangedFiles++; | ||
} | ||
|
||
const comment = await createIssueComment( | ||
octokit, | ||
context, | ||
`🎊 Congrats on the merge! | ||
This pull request has been added as a resource to all the assets modified. ✅ | ||
`, | ||
null, | ||
true | ||
); | ||
null, | ||
true | ||
); | ||
|
||
return totalChangedFiles | ||
return totalChangedFiles; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters