Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for gitlab and github #123

Merged
merged 16 commits into from
Nov 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Squashed all commits
ArpitShukla12 committed Nov 7, 2023
commit efdf3debcf2eea476428cd6d22f09ed093b25c4a
8 changes: 4 additions & 4 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ jobs:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
ATLAN_INSTANCE_URL: ${{secrets.ATLAN_INSTANCE_URL}}
ATLAN_API_TOKEN: ${{secrets.ATLAN_API_TOKEN}}
# DBT_ENVIRONMENT_BRANCH_MAP: |
# main: DBT-DEMO-PROD
# beta: Wide World Importers PE1
# test-action: Wide World Importers PE1
DBT_ENVIRONMENT_BRANCH_MAP: |
main: DBT-DEMO-PROD
beta: Wide World Importers PE1
test-action: Wide World Importers PE1
IGNORE_MODEL_ALIAS_MATCHING: true
23 changes: 12 additions & 11 deletions src/api/create-resource.js → adapters/api/create-resource.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { v4 as uuidv4 } from "uuid";
import fetch from "node-fetch";
import stringify from "json-stringify-safe";
import { getAPIToken, getInstanceUrl } from "../utils/index.js";
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

const ATLAN_INSTANCE_URL = getInstanceUrl();
const ATLAN_API_TOKEN = getAPIToken();

export default async function createResource( //Done
export default async function createResource(
guid,
name,
link,
@@ -49,14 +49,15 @@ export default async function createResource( //Done
.then((e) => e.json())
.catch((err) => {
console.log(err);
sendSegmentEventOfIntegration("dbt_ci_action_failure", {
reason: "failed_to_create_resource",
asset_name: name,
msg: err,
sendSegmentEventOfIntegration({
action: "dbt_ci_action_failure",
properties: {
reason: "failed_to_create_resource",
asset_name: name, // This should change
msg: err,
},
});
});

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

return response;
}
64 changes: 46 additions & 18 deletions src/api/get-asset.js → adapters/api/get-asset.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import fetch from "node-fetch";
import core from "@actions/core";
import dotenv from "dotenv";
import stringify from "json-stringify-safe";

dotenv.config();

const 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;
import {
getErrorModelNotFound,
getErrorDoesNotMaterialize,
} from "../templates/atlan.js";
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

export default async function getAsset({
//Done
name,
sendSegmentEventOfIntegration,
environment,
@@ -21,7 +19,7 @@ export default async function getAsset({
Authorization: `Bearer ${ATLAN_API_TOKEN}`,
"Content-Type": "application/json",
};
console.log("At line 24 inside getAsset function");

var raw = stringify({
dsl: {
from: 0,
@@ -88,8 +86,7 @@ export default async function getAsset({
headers: myHeaders,
body: raw,
};
console.log("Before SendSegmentEventOfIntegration");
console.log("At line 92 inside getAsset");

var response = await fetch(
`${ATLAN_INSTANCE_URL}/api/meta/search/indexsearch#findAssetByExactName`,
requestOptions
@@ -105,16 +102,47 @@ export default async function getAsset({
},
});
});
console.log("<><><><><><><><><><><><><>");
console.log(response);
if (!response?.entities?.length)

if (!response?.entities?.length) {
return {
error: `❌ Model with name **${name}** could not be found or is deleted <br><br>`,
error: getErrorModelNotFound(name),
};
}

if (Array.isArray(response.entities)) {
response.entities.sort((entityA, entityB) => {
const hasDbtModelSqlAssetsA =
entityA.attributes.dbtModelSqlAssets &&
entityA.attributes.dbtModelSqlAssets.length > 0;
const hasDbtModelSqlAssetsB =
entityB.attributes.dbtModelSqlAssets &&
entityB.attributes.dbtModelSqlAssets.length > 0;

if (hasDbtModelSqlAssetsA && !hasDbtModelSqlAssetsB) {
return -1; // entityA comes before entityB
} else if (!hasDbtModelSqlAssetsA && hasDbtModelSqlAssetsB) {
return 1; // entityB comes before entityA
}

// Primary sorting criterion: Latest createTime comes first
if (entityA.createTime > entityB.createTime) {
return -1;
} else if (entityA.createTime < entityB.createTime) {
return 1;
}

return 0; // No difference in sorting for these two entities
});
}

if (!response?.entities[0]?.attributes?.dbtModelSqlAssets?.length > 0)
return {
error: `❌ Model with name [${name}](${ATLAN_INSTANCE_URL}/assets/${response.entities[0].guid}/overview?utm_source=dbt_${integration}_action) does not materialise any asset <br><br>`,
error: getErrorDoesNotMaterialize(
name,
ATLAN_INSTANCE_URL,
response,
integration
),
};

return response.entities[0];
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import fetch from "node-fetch";
import { sendSegmentEvent } from "./index.js";
import stringify from "json-stringify-safe";
import { getAPIToken, getInstanceUrl } from "../utils/index.js";

const ATLAN_INSTANCE_URL = getInstanceUrl();
const ATLAN_API_TOKEN = getAPIToken();
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

export default async function getClassifications({
sendSegmentEventOfIntegration,
@@ -26,9 +24,12 @@ export default async function getClassifications({
)
.then((e) => e.json())
.catch((err) => {
sendSegmentEventOfIntegration("dbt_ci_action_failure", {
reason: "failed_to_get_classifications",
msg: err,
sendSegmentEventOfIntegration({
action: "dbt_ci_action_failure",
properties: {
reason: "failed_to_get_classifications",
msg: err,
},
});
});

Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import fetch from "node-fetch";
import core from "@actions/core";
import dotenv from "dotenv";
import {
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;
const ATLAN_API_TOKEN =
core.getInput("ATLAN_API_TOKEN") || process.env.ATLAN_API_TOKEN;
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

const ASSETS_LIMIT = 100;

export default async function getDownstreamAssets( //Done
export default async function getDownstreamAssets(
asset,
guid,
totalModifiedFiles,
@@ -28,7 +23,7 @@ export default async function getDownstreamAssets( //Done
authorization: `Bearer ${ATLAN_API_TOKEN}`,
"content-type": "application/json",
};
console.log("At line 31 inside getDownstreamAssets function");

var raw = stringify({
guid: guid,
size: Math.max(Math.ceil(ASSETS_LIMIT / totalModifiedFiles), 1),
@@ -96,12 +91,15 @@ ${getImageURL(
asset.guid
}/lineage/overview?utm_source=dbt_${integration}_action)`;

sendSegmentEventOfIntegration("dbt_ci_action_failure", {
reason: "failed_to_fetch_lineage",
asset_guid: asset.guid,
asset_name: asset.name,
asset_typeName: asset.typeName,
msg: err,
sendSegmentEventOfIntegration({
action: "dbt_ci_action_failure",
properties: {
reason: "failed_to_fetch_lineage",
asset_guid: asset.guid,
asset_name: asset.name,
asset_typeName: asset.typeName,
msg: err,
},
});

return comment;
@@ -123,7 +121,6 @@ ${getImageURL(
error: handleError(err),
};
});
console.log("At line 126 inside getDownstreamAssets function", response);
if (response.error) return response;

return response;
File renamed without changes.
19 changes: 7 additions & 12 deletions src/api/segment.js → adapters/api/segment.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import fetch from "node-fetch";
import core from "@actions/core";
import dotenv from "dotenv";

dotenv.config();

const { IS_DEV } = process.env;
const 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;
import {
IS_DEV,
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "../utils/get-environment-variables.js";

export async function sendSegmentEvent(action, body) {
const myHeaders = {
authorization: `Bearer ${ATLAN_API_TOKEN}`,
"content-type": "application/json",
};
console.log("At line 18 inide sendSegmentEvent");

const requestOptions = {
method: "POST",
headers: myHeaders,
@@ -37,6 +32,6 @@ export async function sendSegmentEvent(action, body) {
} else {
console.log("send segment event", action, body);
}
console.log("At line 40 inside sendSegmentEvent");

return response;
}
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
5 changes: 3 additions & 2 deletions adapters/gateway.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Common Gateway for all integrations
import logger from "./logger/logger.js";
export async function runAction(token, integrationModule) {
if (token === undefined) {
console.log("Token not provided.");
logger.logInfo("Token not provided.", "runAction");
return;
}
const integration = new integrationModule(token);
await integration.run(); // Add error part
await integration.run();
}
12 changes: 4 additions & 8 deletions adapters/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
// main.js
import dotenv from "dotenv";
import { runAction } from "./gateway.js";
import GitHubIntegration from "./integrations/github-integration.js";
import GitLabIntegration from "./integrations/gitlab-integration.js";
import core from "@actions/core";

dotenv.config();

const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN") || process.env.GITHUB_TOKEN;
const GITLAB_TOKEN = process.env.GITLAB_TOKEN;
import {
GITLAB_TOKEN,
GITHUB_TOKEN,
} from "./utils/get-environment-variables.js";

async function run() {
//Add new integrations over here
console.log("oii");
await runAction(GITHUB_TOKEN, GitHubIntegration);
await runAction(GITLAB_TOKEN, GitLabIntegration);
}
1,400 changes: 875 additions & 525 deletions adapters/integrations/github-integration.js

Large diffs are not rendered by default.

1,380 changes: 937 additions & 443 deletions adapters/integrations/gitlab-integration.js

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions adapters/logger/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// logger.js

function getCurrentTimestamp() {
const now = new Date();
return now.toISOString();
}

function logInfo(message, method) {
const timestamp = getCurrentTimestamp();
const logEntry = {
level: "ERROR",
timestamp,
method,
message,
};
console.error(logEntry);
}

function withInfo(message, vcs, sha, method) {
const timestamp = getCurrentTimestamp();
const logEntry = {
level: "INFO",
timestamp,
vcs,
sha,
method,
message,
};
console.log(logEntry);
}

function withError(message, vcs, sha, method) {
const timestamp = getCurrentTimestamp();
const logEntry = {
level: "ERROR",
timestamp,
vcs,
sha,
method,
message,
};
console.error(logEntry);
}

function debug(message, vcs, sha, method) {
const timestamp = getCurrentTimestamp();
const logEntry = {
level: "DEBUG",
timestamp,
vcs,
sha,
method,
message,
};
console.debug(logEntry);
}

const logger = {
withInfo,
withError,
debug,
logInfo,
};

export default logger;
32 changes: 32 additions & 0 deletions adapters/templates/atlan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {getConnectorImage, getImageURL} from "../utils/index.js"

export function getErrorModelNotFound(name) {
return `
<br>❌ Model with name **${name}** could not be found or is deleted <br><br>
`;
}

export function getErrorDoesNotMaterialize(
name,
ATLAN_INSTANCE_URL,
response,
integration
) {

return `
<br>❌ Model with name [${name}](${ATLAN_INSTANCE_URL}/assets/${response.entities[0].guid}/overview?utm_source=dbt_${integration}_action) does not materialise any asset <br><br>`;
}

export function getNewModelAddedComment(fileName) {
return `### ${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.`
}

export function getBaseComment(totalChangedFiles, comments) {
return `### ${getImageURL("atlan-logo", 15, 15)} Atlan impact analysis
Here is your downstream impact analysis for **${totalChangedFiles} ${
totalChangedFiles > 1 ? "models" : "model"
}** you have edited.
${comments}`
}
102 changes: 102 additions & 0 deletions adapters/templates/github-integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { getImageURL, getConnectorImage, getCertificationImage } from "../utils/index.js";

export function getErrorResponseStatus401 (ATLAN_INSTANCE_URL, context) {
return `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: ${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).`
}

export function getErrorResponseStatusUndefined(ATLAN_INSTANCE_URL, context) {
return `We couldn't connect to your Atlan Instance, please make sure to set the valid Atlan Instance URL as \`ATLAN_INSTANCE_URL\` as this repository's action secret.
Atlan Instance URL: ${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).`
}

export function getSetResourceOnAssetComment(tableMd, setResourceFailed) {
return `## 🎊 Congrats on the merge!
This pull request has been added as a resource to the following assets:
Name | Resource set successfully
--- | ---
${tableMd}
${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.' : ''}
`
}

export function getAssetInfo(ATLAN_INSTANCE_URL, asset, materialisedAsset, environmentName, projectName) {
return `### ${getConnectorImage(
asset.attributes.connectorName
)} [${asset.displayText}](${ATLAN_INSTANCE_URL}/assets/${
asset.guid
}/overview?utm_source=dbt_github_action) ${
asset.attributes?.certificateStatus
? getCertificationImage(asset.attributes.certificateStatus)
: ""
}
Materialised asset: ${getConnectorImage(
materialisedAsset.attributes.connectorName
)} [${materialisedAsset.attributes.name}](${ATLAN_INSTANCE_URL}/assets/${
materialisedAsset.guid
}/overview?utm_source=dbt_github_action) ${
materialisedAsset.attributes?.certificateStatus
? getCertificationImage(materialisedAsset.attributes.certificateStatus)
: ""
}${environmentName ? ` | Environment Name: \`${environmentName}\`` : ""}${
projectName ? ` | Project Name: \`${projectName}\`` : ""
}`
}

export function getDownstreamTable(ATLAN_INSTANCE_URL, downstreamAssets, rows, materialisedAsset) {
return `<details><summary><b>${
downstreamAssets.entityCount
} downstream assets 👇</b></summary><br/>
Name | Type | Description | Owners | Terms | Classifications | Source URL
--- | --- | --- | --- | --- | --- | ---
${rows
.map((row) =>
row.map((i) => i.replace(/\|/g, "•").replace(/\n/g, "")).join(" | ")
)
.join("\n")}
${
downstreamAssets.hasMore
? `[See more downstream assets at Atlan](${ATLAN_INSTANCE_URL}/assets/${materialisedAsset.guid}/lineage?utm_source=dbt_github_action)`
: ""
}
</details>`
}

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

export function getMDCommentForModel(ATLAN_INSTANCE_URL, model) {
return `${getConnectorImage(model?.attributes?.connectorName)} [${
model?.displayText
}](${ATLAN_INSTANCE_URL}/assets/${model?.guid}/overview?utm_source=dbt_github_action)`
}

export function getMDCommentForMaterialisedView(ATLAN_INSTANCE_URL, materialisedView) {
return `${getConnectorImage(materialisedView?.attributes?.connectorName)} [${
materialisedView?.attributes?.name
}](${ATLAN_INSTANCE_URL}/assets/${materialisedView?.guid}/overview?utm_source=dbt_github_action)`
}

export function getTableMD(md, resp) {
return `${md} | ${resp ? '✅' : '❌'} \n`
}
102 changes: 102 additions & 0 deletions adapters/templates/gitlab-integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { getImageURL, getConnectorImage, getCertificationImage } from "../utils/index.js";

export function getErrorResponseStatus401 (ATLAN_INSTANCE_URL, CI_PROJECT_NAME, CI_PROJECT_NAMESPACE) {
return `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 CI/CD variable.
Atlan Instance URL: ${ATLAN_INSTANCE_URL}
Set your CI/CD variables [here](https://gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/-/settings/ci_cd). 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).`
}

export function getErrorResponseStatusUndefined(ATLAN_INSTANCE_URL, CI_PROJECT_NAME, CI_PROJECT_NAMESPACE) {
return `We couldn't connect to your Atlan Instance, please make sure to set the valid Atlan Instance URL as \`ATLAN_INSTANCE_URL\` as this repository's CI/CD variable.
Atlan Instance URL: ${ATLAN_INSTANCE_URL}
Make sure your Atlan Instance URL is set in the following format.
\`https://tenant.atlan.com\`
Set your CI/CD variables [here](https://gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/-/settings/ci_cd). 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).`
}

export function getSetResourceOnAssetComment(tableMd, setResourceFailed) {
return `## 🎊 Congrats on the merge!
This pull request has been added as a resource to the following assets:
Name | Resource set successfully
--- | ---
${tableMd}
${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.' : ''}
`
}

export function getAssetInfo(ATLAN_INSTANCE_URL, asset, materialisedAsset, environmentName, projectName) {
return `### ${getConnectorImage(
asset.attributes.connectorName
)} [${asset.displayText}](${ATLAN_INSTANCE_URL}/assets/${
asset.guid
}/overview?utm_source=dbt_gitlab_action) ${
asset.attributes?.certificateStatus
? getCertificationImage(asset.attributes.certificateStatus)
: ""
}
Materialised asset: ${getConnectorImage(
materialisedAsset.attributes.connectorName
)} [${materialisedAsset.attributes.name}](${ATLAN_INSTANCE_URL}/assets/${
materialisedAsset.guid
}/overview?utm_source=dbt_gitlab_action) ${
materialisedAsset.attributes?.certificateStatus
? getCertificationImage(materialisedAsset.attributes.certificateStatus)
: ""
}${environmentName ? ` | Environment Name: \`${environmentName}\`` : ""}${
projectName ? ` | Project Name: \`${projectName}\`` : ""
}`
}

export function getDownstreamTable(ATLAN_INSTANCE_URL, downstreamAssets, rows, materialisedAsset) {
return `<details><summary><b>${
downstreamAssets.entityCount
} downstream assets 👇</b></summary><br/>
Name | Type | Description | Owners | Terms | Classifications | Source URL
--- | --- | --- | --- | --- | --- | ---
${rows
.map((row) =>
row.map((i) => i.replace(/\|/g, "•").replace(/\n/g, "")).join(" | ")
)
.join("\n")}
${
downstreamAssets.hasMore
? `[See more downstream assets at Atlan](${ATLAN_INSTANCE_URL}/assets/${materialisedAsset.guid}/lineage?utm_source=dbt_gitlab_action)`
: ""
}
</details>`
}

export function getViewAssetButton(ATLAN_INSTANCE_URL, asset) {
return `${getImageURL(
"atlan-logo",
15,
15
)} [View asset in Atlan](${ATLAN_INSTANCE_URL}/assets/${
asset.guid
}/overview?utm_source=dbt_gitlab_action)`
}

export function getMDCommentForModel(ATLAN_INSTANCE_URL, model) {
return `${getConnectorImage(model?.attributes?.connectorName)} [${
model?.displayText
}](${ATLAN_INSTANCE_URL}/assets/${model?.guid}/overview?utm_source=dbt_gitlab_action)`
}

export function getMDCommentForMaterialisedView(ATLAN_INSTANCE_URL, materialisedView) {
return `${getConnectorImage(materialisedView?.attributes?.connectorName)} [${
materialisedView?.attributes?.name
}](${ATLAN_INSTANCE_URL}/assets/${materialisedView?.guid}/overview?utm_source=dbt_gitlab_action)`
}

export function getTableMD(md, resp) {
return `${md} | ${resp ? '✅' : '❌'} \n`
}
17 changes: 5 additions & 12 deletions src/utils/auth.js → adapters/utils/auth.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import fetch from "node-fetch";
import dotenv from "dotenv";
import core from "@actions/core";

dotenv.config();

const 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;
import {
ATLAN_INSTANCE_URL,
ATLAN_API_TOKEN,
} from "./get-environment-variables.js";

export async function auth() {
//Done
console.log("Inside auth in utils.js");
var myHeaders = {
authorization: `Bearer ${ATLAN_API_TOKEN}`,
"content-type": "application/json",
@@ -26,6 +19,6 @@ export async function auth() {
`${ATLAN_INSTANCE_URL}/api/meta`,
requestOptions
).catch((err) => {});
console.log("Completed auth in utils.js");

return response;
}
9 changes: 9 additions & 0 deletions adapters/utils/create-comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function truncate(value) {
if (typeof value === "string")
return value.length > 100 ? value.substring(0, 100) + "..." : value;
if (Array.isArray(value))
return value.length > 10
? value.slice(0, 10).join(", ") + "..."
: value.join(", ");
return "";
}
84 changes: 84 additions & 0 deletions adapters/utils/get-environment-variables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import dotenv from "dotenv";
import core from "@actions/core";
dotenv.config();

//Common env variables
export const ATLAN_INSTANCE_URL = new URL(
process.env.ATLAN_INSTANCE_URL || core.getInput("ATLAN_INSTANCE_URL")
).origin;

export const ATLAN_API_TOKEN =
process.env.ATLAN_API_TOKEN || core.getInput("ATLAN_API_TOKEN");

export const IS_DEV = process.env.IS_DEV;

export const IGNORE_MODEL_ALIAS_MATCHING =
(process.env.IGNORE_MODEL_ALIAS_MATCHING ||
core.getInput("IGNORE_MODEL_ALIAS_MATCHING")) == "true";

//GITLAB SPECIFIC ENV VARIABLES
export async function getCIMergeRequestIID(
gitlab,
CI_PROJECT_ID,
CI_COMMIT_SHA
) {
if (!process.env.CI_MERGE_REQUEST_IID) {
const mergeRequestCommit = await gitlab.Commits.allMergeRequests(
CI_PROJECT_ID,
CI_COMMIT_SHA
);

const firstMergeRequest = mergeRequestCommit[0];
if (firstMergeRequest) {
return firstMergeRequest.iid;
}
}

return process.env.CI_MERGE_REQUEST_IID;
}

export const {
CI_PROJECT_PATH,
CI_PROJECT_ID,
CI_JOB_URL,
GITLAB_TOKEN,
CI_COMMIT_MESSAGE,
GITLAB_USER_LOGIN,
CI_PROJECT_NAME,
CI_COMMIT_SHA,
CI_PROJECT_NAMESPACE,
} = process.env;

export function getGitLabEnvironments() {
const { DBT_ENVIRONMENT_BRANCH_MAP } = process.env;

if (DBT_ENVIRONMENT_BRANCH_MAP) {
const environmentLines = DBT_ENVIRONMENT_BRANCH_MAP.split("\n");
const environmentMap = {};

environmentLines.forEach((line) => {
const [environment, branch] = line.split(":").map((item) => item.trim());
if (environment && branch) {
environmentMap[environment] = branch;
}
});

return environmentMap;
} else {
return {};
}
}

//GITHUB SPECIFIC ENV VARIABLES
export const GITHUB_TOKEN =
core.getInput("GITHUB_TOKEN") || process.env.GITHUB_TOKEN;

export const getEnvironments = () => {
return (
core
.getInput("DBT_ENVIRONMENT_BRANCH_MAP")
?.trim()
?.split("\n")
?.map((i) => i.split(":").map((i) => i.trim())) ?? []
);
};
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions adapters/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export {
getImageURL,
getConnectorImage,
getCertificationImage,
} from "./get-image-url.js";
export { default as hostedImages } from "./hosted-images.js";
export { truncate } from "./create-comment.js";
export { auth } from "./auth.js";
export {
getGitLabEnvironments,
getEnvironments,
} from "./get-environment-variables.js";
10,271 changes: 7,848 additions & 2,423 deletions dist/index.js

Large diffs are not rendered by default.

209 changes: 190 additions & 19 deletions package-lock.json
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -29,11 +29,17 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@gitbeaker/rest": "^39.17.0",
"@gitbeaker/cli": "^39.19.0",
"@gitbeaker/core": "^39.19.0",
"@gitbeaker/requester-utils": "^39.19.0",
"@gitbeaker/rest": "^39.19.0",
"@vercel/ncc": "^0.34.0",
"dotenv": "^16.0.3",
"json-stringify-safe": "^5.0.1",
"node-fetch": "^3.3.0",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/json-stringify-safe": "^5.0.2"
}
}
45 changes: 0 additions & 45 deletions src/index.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/main/index.js

This file was deleted.

105 changes: 0 additions & 105 deletions src/main/print-downstream-assets.js

This file was deleted.

58 changes: 0 additions & 58 deletions src/main/set-resource-on-asset.js

This file was deleted.

182 changes: 0 additions & 182 deletions src/utils/create-comment.js

This file was deleted.

82 changes: 0 additions & 82 deletions src/utils/file-system.js

This file was deleted.

52 changes: 0 additions & 52 deletions src/utils/get-environment-variables.js

This file was deleted.

23 changes: 0 additions & 23 deletions src/utils/index.js

This file was deleted.