Skip to content

Commit

Permalink
fix: secrets bug and show message when there is no impacted assets pr…
Browse files Browse the repository at this point in the history
…esent
  • Loading branch information
Jaagrav committed Feb 27, 2023
1 parent ad32c68 commit fc659ac
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 111 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.env
.env.gitlab
.env.github
node_modules/
event.json
.idea
Expand Down
120 changes: 69 additions & 51 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17687,17 +17687,35 @@ function getCertificationImage(certificationStatus) {
},
});

;// CONCATENATED MODULE: ./src/utils/get-environment-variables.js



main.config();

const {IS_DEV, ATLAN_INSTANCE_URL, ATLAN_API_TOKEN} = process.env;

const isDev = () => IS_DEV === "true";
const getInstanceUrl = () => {
if (ATLAN_INSTANCE_URL) return new URL(ATLAN_INSTANCE_URL).origin;
return new URL(core.getInput("ATLAN_INSTANCE_URL")).origin;
};
const getAPIToken = () => {
if (ATLAN_API_TOKEN) return ATLAN_API_TOKEN;
return core.getInput("ATLAN_API_TOKEN");
}
;// CONCATENATED MODULE: ./src/utils/create-comment.js






main.config();

const {IS_DEV} = process.env;
const ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
const create_comment_IS_DEV = isDev();
const create_comment_ATLAN_INSTANCE_URL =
getInstanceUrl();

async function renderDownstreamAssetsComment(
octokit,
Expand All @@ -17715,7 +17733,7 @@ async function renderDownstreamAssetsComment(
return [
guid, displayText, attributes.connectorName, readableTypeName, attributes?.userDescription || attributes?.description || "", attributes?.certificateStatus || "", [...attributes?.ownerUsers, ...attributes?.ownerGroups] || [], meanings.map(
({displayText, termGuid}) =>
`[${displayText}](${ATLAN_INSTANCE_URL}/assets/${termGuid}?utm_source=dbt_github_action)`
`[${displayText}](${create_comment_ATLAN_INSTANCE_URL}/assets/${termGuid}/overview?utm_source=dbt_github_action)`
)
?.join(", ") || " ", attributes?.sourceURL || ""
];
Expand All @@ -17731,34 +17749,45 @@ async function renderDownstreamAssetsComment(
? getCertificationImage(certificateStatus)
: "";

return [`${connectorImage} [${displayText}](${ATLAN_INSTANCE_URL}/assets/${guid}?utm_source=dbt_github_action) ${certificationImage}`,
return [`${connectorImage} [${displayText}](${create_comment_ATLAN_INSTANCE_URL}/assets/${guid}/overview?utm_source=dbt_github_action) ${certificationImage}`,
`\`${typeName}\``,
description,
owners.join(", ") || " ",
meanings,
sourceUrl ? `[Open in ${connectorName}](${sourceUrl})` : " "]
})

const comment = `### ${getConnectorImage(asset.attributes.connectorName)} [${
const assetInfo = `### ${getConnectorImage(asset.attributes.connectorName)} [${
asset.displayText
}](${ATLAN_INSTANCE_URL}/assets/${asset.guid}?utm_source=dbt_github_action) ${
}](${create_comment_ATLAN_INSTANCE_URL}/assets/${asset.guid}/overview?utm_source=dbt_github_action) ${
asset.attributes?.certificateStatus
? getCertificationImage(asset.attributes.certificateStatus)
: ""
}
}`

const downstreamTable = `**${downstreamAssets.length} downstream assets** 👇
Name | Type | Description | Owners | Terms | Source URL
--- | --- | --- | --- | --- | ---
${rows.map((row) => row.map(i => i.replace(/\|/g, "•").replace(/\n/g, "")).join(" | ")).join("\n")}`

const viewAssetButton = `${getImageURL("atlan-logo", 15, 15)} [View asset in Atlan](${create_comment_ATLAN_INSTANCE_URL}/assets/${asset.guid}/overview?utm_source=dbt_github_action)`

if (downstreamAssets.length > 0)
return `${assetInfo}

**${downstreamAssets.length} downstream assets** 👇
Name | Type | Description | Owners | Terms | Source URL
--- | --- | --- | --- | --- | ---
${rows.map((row) => row.map(i => i.replace(/\|/g, "•").replace(/\n/g, "")).join(" | ")).join("\n")}

${getImageURL("atlan-logo", 15, 15)} [View asset in Atlan](${ATLAN_INSTANCE_URL}/assets/${asset.guid}?utm_source=dbt_github_action)`;
${downstreamTable}

${viewAssetButton}`;

return comment
return `${assetInfo}

No downstream assets found.

${viewAssetButton}`
}

async function checkCommentExists(octokit, context) {
if (IS_DEV) return null;
if (create_comment_IS_DEV) return null;

const {pull_request} = context.payload;

Expand Down Expand Up @@ -17786,7 +17815,7 @@ ${content}`

console.log(content)

if (IS_DEV) return content;
if (create_comment_IS_DEV) return content;

if (comment_id && !forceNewComment) return octokit.rest.issues.updateComment({...commentObj, comment_id});
return octokit.rest.issues.createComment(commentObj);
Expand Down Expand Up @@ -17881,17 +17910,14 @@ async function getAssetName({octokit, context, fileName, filePath}) {




main.config();

const auth_ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
const ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
getInstanceUrl()
const auth_ATLAN_API_TOKEN =
getAPIToken();

async function auth(octokit, context) {
var myHeaders = {
authorization: `Bearer ${ATLAN_API_TOKEN}`,
authorization: `Bearer ${auth_ATLAN_API_TOKEN}`,
"content-type": "application/json",
};

Expand All @@ -17906,13 +17932,17 @@ async function auth(octokit, context) {
).catch((err) => {
});

const existingComment = await checkCommentExists(octokit, context);

console.log("Existing Comment", existingComment)

if (response?.status === 401) {
await
createIssueComment(octokit, context, `We couldn't connect to your Atlan Instance, please make sure to set the valid Atlan Bearer Token as \`ATLAN_API_TOKEN\` as this repository's action secret.

Atlan Instance URL: ${auth_ATLAN_INSTANCE_URL}

Set your repository action secrets [here](https://github.com/${context.payload.repository.full_name}/settings/secrets/actions). For more information on how to setup the Atlan dbt Action, please read the [setup documentation here](https://github.com/atlanhq/dbt-action/blob/main/README.md).`)
Set your repository action secrets [here](https://github.com/${context.payload.repository.full_name}/settings/secrets/actions). For more information on how to setup the Atlan dbt Action, please read the [setup documentation here](https://github.com/atlanhq/dbt-action/blob/main/README.md).`, existingComment?.id)
return false
}

Expand All @@ -17925,7 +17955,7 @@ Atlan Instance URL: ${auth_ATLAN_INSTANCE_URL}
Make sure your Atlan Instance URL is set in the following format.
\`https://tenant.atlan.com\`

Set your repository action secrets [here](https://github.com/${context.payload.repository.full_name}/settings/secrets/actions). For more information on how to setup the Atlan dbt Action, please read the [setup documentation here](https://github.com/atlanhq/dbt-action/blob/main/README.md).`)
Set your repository action secrets [here](https://github.com/${context.payload.repository.full_name}/settings/secrets/actions). For more information on how to setup the Atlan dbt Action, please read the [setup documentation here](https://github.com/atlanhq/dbt-action/blob/main/README.md).`, existingComment?.id)
return false
}

Expand All @@ -17946,14 +17976,10 @@ var stringify = __nccwpck_require__(7073);





main.config();

const get_downstream_assets_ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
getInstanceUrl();
const get_downstream_assets_ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
getAPIToken();

async function getDownstreamAssets(asset, guid, octokit, context) {
var myHeaders = {
Expand Down Expand Up @@ -17998,15 +18024,15 @@ async function getDownstreamAssets(asset, guid, octokit, context) {
var handleError = (err) => {
const comment = `### ${getConnectorImage(asset.attributes.connectorName)} [${
asset.displayText
}](${get_downstream_assets_ATLAN_INSTANCE_URL}/assets/${asset.guid}?utm_source=dbt_github_action) ${
}](${get_downstream_assets_ATLAN_INSTANCE_URL}/assets/${asset.guid}/overview?utm_source=dbt_github_action) ${
asset.attributes?.certificateStatus
? getCertificationImage(asset.attributes.certificateStatus)
: ""
}

_Failed to fetch impacted assets._

${getImageURL("atlan-logo", 15, 15)} [View lineage in Atlan](${get_downstream_assets_ATLAN_INSTANCE_URL}/assets/${asset.guid}/lineage?utm_source=dbt_github_action)`;
${getImageURL("atlan-logo", 15, 15)} [View lineage in Atlan](${get_downstream_assets_ATLAN_INSTANCE_URL}/assets/${asset.guid}/lineage/overview?utm_source=dbt_github_action)`;

sendSegmentEvent("dbt_ci_action_failure", {
reason: 'failed_to_fetch_lineage',
Expand Down Expand Up @@ -18051,13 +18077,10 @@ ${getImageURL("atlan-logo", 15, 15)} [View lineage in Atlan](${get_downstream_as




main.config();

const get_asset_ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
getInstanceUrl();
const get_asset_ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
getAPIToken();

async function getAsset({name}) {
var myHeaders = {
Expand Down Expand Up @@ -18153,13 +18176,10 @@ const parse = uuid_dist/* parse */.Qc;




main.config();

const create_resource_ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
getInstanceUrl();
const create_resource_ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
getAPIToken();

async function createResource(guid, name, link) {
var myHeaders = {
Expand Down Expand Up @@ -18213,15 +18233,11 @@ async function createResource(guid, name, link) {





main.config();

const {IS_DEV: segment_IS_DEV} = process.env;
const segment_IS_DEV = isDev();
const segment_ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
getInstanceUrl();
const segment_ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
getAPIToken();

async function sendSegmentEvent(action, properties) {
var myHeaders = {
Expand Down Expand Up @@ -18277,6 +18293,8 @@ async function sendSegmentEvent(action, properties) {



const print_downstream_assets_ATLAN_INSTANCE_URL = getInstanceUrl()

async function printDownstreamAssets({octokit, context}) {
const changedFiles = await getChangedFiles(octokit, context);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"scripts": {
"build": "ncc build src/index.js -o dist",
"start": "npm run build && act pull_request --container-architecture linux/amd64 --secret-file .env -e event.json",
"start": "npm run build && act pull_request --container-architecture linux/amd64 --secret-file .env -e event.json --insecure-secrets",
"sync": "git pull && git push"
},
"author": "Jaagrav Seal <[email protected]> (https://atlan.com/)",
Expand Down
9 changes: 3 additions & 6 deletions src/api/create-resource.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import {v4 as uuidv4} from "uuid";
import fetch from "node-fetch";
import core from "@actions/core";
import dotenv from "dotenv";
import {sendSegmentEvent} from "./index.js";
import stringify from 'json-stringify-safe';

dotenv.config();
import {getAPIToken, getInstanceUrl} from "../utils/index.js";

const ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
getInstanceUrl();
const ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
getAPIToken();

export default async function createResource(guid, name, link) {
var myHeaders = {
Expand Down
9 changes: 3 additions & 6 deletions src/api/get-asset.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import fetch from "node-fetch";
import core from "@actions/core";
import dotenv from "dotenv";
import {sendSegmentEvent} from "./index.js";
import stringify from 'json-stringify-safe';

dotenv.config();
import {getAPIToken, getInstanceUrl} from "../utils/index.js";

const ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
getInstanceUrl();
const ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
getAPIToken();

export default async function getAsset({name}) {
var myHeaders = {
Expand Down
14 changes: 5 additions & 9 deletions src/api/get-downstream-assets.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import fetch from "node-fetch";
import core from "@actions/core";
import dotenv from "dotenv";
import {sendSegmentEvent} from "./index.js";
import {createIssueComment, getConnectorImage, getCertificationImage, getImageURL} from "../utils/index.js";
import {getAPIToken, getInstanceUrl, getConnectorImage, getCertificationImage, getImageURL} from "../utils/index.js";
import stringify from 'json-stringify-safe';

dotenv.config();

const ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
getInstanceUrl();
const ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
getAPIToken();

export default async function getDownstreamAssets(asset, guid, octokit, context) {
var myHeaders = {
Expand Down Expand Up @@ -55,15 +51,15 @@ export default async function getDownstreamAssets(asset, guid, octokit, context)
var handleError = (err) => {
const comment = `### ${getConnectorImage(asset.attributes.connectorName)} [${
asset.displayText
}](${ATLAN_INSTANCE_URL}/assets/${asset.guid}?utm_source=dbt_github_action) ${
}](${ATLAN_INSTANCE_URL}/assets/${asset.guid}/overview?utm_source=dbt_github_action) ${
asset.attributes?.certificateStatus
? getCertificationImage(asset.attributes.certificateStatus)
: ""
}
_Failed to fetch impacted assets._
${getImageURL("atlan-logo", 15, 15)} [View lineage in Atlan](${ATLAN_INSTANCE_URL}/assets/${asset.guid}/lineage?utm_source=dbt_github_action)`;
${getImageURL("atlan-logo", 15, 15)} [View lineage in Atlan](${ATLAN_INSTANCE_URL}/assets/${asset.guid}/lineage/overview?utm_source=dbt_github_action)`;

sendSegmentEvent("dbt_ci_action_failure", {
reason: 'failed_to_fetch_lineage',
Expand Down
12 changes: 4 additions & 8 deletions src/api/segment.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import fetch from "node-fetch";
import core from "@actions/core";
import dotenv from "dotenv";
import {context} from "@actions/github";
import stringify from 'json-stringify-safe';
import {isDev, getAPIToken, getInstanceUrl} from "../utils/index.js";


dotenv.config();

const {IS_DEV} = process.env;
const IS_DEV = isDev();
const ATLAN_INSTANCE_URL =
core.getInput("ATLAN_INSTANCE_URL") || process.env.ATLAN_INSTANCE_URL;
getInstanceUrl();
const ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
getAPIToken();

export default async function sendSegmentEvent(action, properties) {
var myHeaders = {
Expand Down
4 changes: 3 additions & 1 deletion src/main/print-downstream-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
import {
renderDownstreamAssetsComment,
getChangedFiles,
getAssetName, createIssueComment, checkCommentExists, deleteComment, getImageURL
getAssetName, createIssueComment, checkCommentExists, deleteComment, getImageURL, getInstanceUrl
} from "../utils/index.js";

const ATLAN_INSTANCE_URL = getInstanceUrl()

export default async function printDownstreamAssets({octokit, context}) {
const changedFiles = await getChangedFiles(octokit, context);

Expand Down
Loading

0 comments on commit fc659ac

Please sign in to comment.