Skip to content

Commit

Permalink
Added logs for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ArpitShukla12 committed Oct 3, 2023
1 parent 74744c9 commit 63c7d59
Show file tree
Hide file tree
Showing 10 changed files with 3,345 additions and 2,669 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test Action

on:
pull_request:
types: [ opened, edited, synchronize, reopened, closed ]
types: [opened, edited, synchronize, reopened, closed]

jobs:
get-downstream-assets:
Expand All @@ -28,4 +28,4 @@ jobs:
main: DBT-DEMO-PROD
beta: Wide World Importers PE1
test-action: Wide World Importers PE1
IGNORE_MODEL_ALIAS_MATCHING: true
IGNORE_MODEL_ALIAS_MATCHING: true
6 changes: 4 additions & 2 deletions adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import dotenv from "dotenv";
import { runAction } from "./gateway.js";
import GitHubIntegration from "./integrations/github-integration.js";
import GitLabIntegration from "./integrations/gitlab-integration.js";
// import GitLabIntegration from "./integrations/gitlab-integration.js";
import core from "@actions/core";

dotenv.config();

Expand All @@ -11,8 +12,9 @@ const GITLAB_TOKEN = process.env.GITLAB_TOKEN;

async function run() {
//Add new integrations over here
console.log("oii");
await runAction(GITHUB_TOKEN, GitHubIntegration);
await runAction(GITLAB_TOKEN, GitLabIntegration);
// await runAction(GITLAB_TOKEN, GitLabIntegration);
}

run();
77 changes: 48 additions & 29 deletions adapters/integrations/github-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import github from "@actions/github";
import { isIgnoreModelAliasMatching } from "../../src/utils/get-environment-variables.js";
import { getConnectorImage } from "../../src/utils/get-image-url.js";
import { getEnvironments } from "../../src/utils/get-environment-variables.js";
import stringify from "json-stringify-safe";
import {
getAsset,
getDownstreamAssets,
Expand All @@ -16,6 +17,7 @@ import { getImageURL, auth } from "../../src/utils/index.js";
import { isDev } from "../../src/utils/get-environment-variables.js";
import { truncate } from "../../src/utils/create-comment.js";
import { getInstanceUrl } from "../../src/utils/get-environment-variables.js";

const IS_DEV = isDev();
const ATLAN_INSTANCE_URL = getInstanceUrl();

Expand All @@ -30,23 +32,30 @@ export default class GitHubIntegration extends IntegrationInterface {
//Done
//Complete
console.log("Run Github");
console.log(IS_DEV);
const timeStart = Date.now();
const { context } = github;
console.log("Context:", context);
const octokit = github.getOctokit(this.token);
const { pull_request } = context.payload;
const { state, merged } = pull_request;
const { pull_request } = context?.payload;
console.log(pull_request, "hii");

console.log("Interesting");
const { state, merged } = pull_request;
console.log("state", state);
console.log("merged", merged);
if (!(await this.authIntegration({ octokit, context }))) {
//DONE
//Complete
throw { message: "Wrong API Token" };
}

let total_assets = 0;

console.log("After auth Integration");
if (state === "open") {
total_assets = await this.printDownstreamAssets({ octokit, context });
} else if (state === "closed" && merged) {
console.log("Hmm");
total_assets = await this.setResourceOnAsset({ octokit, context });
}

Expand All @@ -61,7 +70,8 @@ export default class GitHubIntegration extends IntegrationInterface {

async printDownstreamAssets({ octokit, context }) {
//Done
const changedFiles = await this.getChangedFiles(octokit, context); //Complete
console.log("Brother");
const changedFiles = await this.getChangedFiles({ octokit, context }); //Complete
let comments = ``;
let totalChangedFiles = 0;

Expand All @@ -74,7 +84,7 @@ export default class GitHubIntegration extends IntegrationInterface {
filePath,
});
const assetName = isIgnoreModelAliasMatching() ? fileName : aliasName; //Complete

console.log("acha2");
const environments = getEnvironments();

let environment = null;
Expand All @@ -84,55 +94,57 @@ export default class GitHubIntegration extends IntegrationInterface {
break;
}
}

console.log("Before getAsset");
const asset = await getAsset({
//Done
name: assetName,
sendSegmentEventOfIntegration: this.sendSegmentEventOfIntegration,
environment: environment,
integration: "github",
});

console.log("After getAsset");
if (totalChangedFiles !== 0) comments += "\n\n---\n\n";

console.log("Status: ", status);
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;
}

console.log("Before filtering");
console.log("Asset", asset);
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;
console.log("Before getDownstreamAssets");
const downstreamAssets = await getDownstreamAssets(
//Complete
asset,
materialisedAsset.guid,
totalModifiedFiles
);

console.log("After getDownstreamAssets");
if (downstreamAssets.error) {
comments += downstreamAssets.error;
totalChangedFiles++;
continue;
}

console.log("At line 139 after getDownstreamAssets in printDownstream");
this.sendSegmentEventOfIntegration("dbt_ci_action_downstream_unfurl", {
//Complete
asset_guid: asset.guid,
asset_type: asset.typeName,
downstream_count: downstreamAssets.entities.length,
total_fetch_time: Date.now() - timeStart,
});
console.log("At line 147 after getDownstreamAssets in printDownstream");

const classifications = await getClassifications({
//Complete
Expand All @@ -158,8 +170,8 @@ Its a new model and not present in Atlan yet, you'll see the downstream impact f
comments = `### ${getImageURL("atlan-logo", 15, 15)} Atlan impact analysis
Here is your downstream impact analysis for **${totalChangedFiles} ${
totalChangedFiles > 1 ? "models" : "model"
}** you have edited.
}** you have edited.
${comments}`;

const existingComment = await this.checkCommentExists({ octokit, context }); //Complete
Expand Down Expand Up @@ -252,7 +264,7 @@ ${comments}`;
octokit,
context,
content: `🎊 Congrats on the merge!
This pull request has been added as a resource to all the assets modified. ✅
`,
comment_id: null,
Expand All @@ -265,39 +277,42 @@ This pull request has been added as a resource to all the assets modified. ✅
async authIntegration({ octokit, context }) {
//DONE
//COMPLETE
console.log("Here is Context:", context);
const response = await auth();
console.log("Inside authIntegration befor comment exists");
const existingComment = await this.checkCommentExists({ octokit, context });

console.log("Existing Comment", existingComment);

if (response?.status === 401) {
await this.createIssueComment(
console.log("Inside authIntegration befor createIssueComment");
await this.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.
content: `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).`,
existingComment?.id
);
comment_id: existingComment?.id,
});
return false;
}

if (response === undefined) {
await this.createIssueComment(
await this.createIssueComment({
octokit,
context,
`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.
content: `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).`,
existingComment?.id
);
comment_id: existingComment?.id,
});
return false;
}

Expand All @@ -317,7 +332,8 @@ Set your repository action secrets [here](https://github.com/${context.payload.r
userId: "atlan-annonymous-github",
properties: {
...properties,
github_action_id: `https://github.com/${context.payload.repository.full_name}/actions/runs/${context.runId}`,
//get context for this
// github_action_id: `https://github.com/${context.payload.repository.full_name}/actions/runs/${context.runId}`,
domain,
},
});
Expand Down Expand Up @@ -455,8 +471,10 @@ Set your repository action secrets [here](https://github.com/${context.payload.r
comment_id = null,
forceNewComment = false,
}) {
const { pull_request } = context.payload;

console.log("Inside CreateIssue:", context);
console.log("Inside CreateIssue Comment");
const { pull_request } = context?.payload || {};
console.log("Inside CreateIssue Comment");
content = `<!-- ActionCommentIdentifier: atlan-dbt-action -->
${content}`;

Expand All @@ -467,6 +485,7 @@ ${content}`;
};

console.log(content, content.length);
console.log("Inside CreateIssue Comment Complete");

if (IS_DEV) return content;

Expand Down Expand Up @@ -617,7 +636,7 @@ Materialised asset: ${getConnectorImage(
} 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(" | ")
Expand All @@ -644,13 +663,13 @@ ${
// Generating the final comment based on the presence of downstream assets
if (downstreamAssets.entities.length > 0) {
return `${assetInfo}
${downstreamTable}
${viewAssetButton}`;
} else {
return `${assetInfo}
No downstream assets found.
${viewAssetButton}`;
Expand Down
14 changes: 8 additions & 6 deletions adapters/integrations/gitlab-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import dotenv from "dotenv";

import IntegrationInterface from "./contract/contract.js";
import { Gitlab } from "@gitbeaker/node";
import { Gitlab } from "@gitbeaker/rest";
import {
createResource,
getAsset,
Expand All @@ -13,6 +13,8 @@ import { getImageURL, auth } from "../../src/utils/index.js";
import { getGitLabEnvironments } from "../../src/utils/get-environment-variables.js";
import { getConnectorImage } from "../../src/utils/index.js";
import { getCertificationImage } from "../../src/utils/index.js";
import stringify from "json-stringify-safe";

dotenv.config();
const ATLAN_INSTANCE_URL = process.env.ATLAN_INSTANCE_URL;
const { IS_DEV } = process.env;
Expand Down Expand Up @@ -238,7 +240,7 @@ ${comments}`;
//Complete
gitlab,
content: `🎊 Congrats on the merge!
This pull request has been added as a resource to all the assets modified. ✅
`,
comment_id: null,
Expand All @@ -256,7 +258,7 @@ This pull request has been added as a resource to all the assets modified. ✅
//Complete
await this.createIssueComment(
gitlab,
`We couldn't connect to your Atlan Instance, please make sure to set the valid Atlan Bearer Token as \`ATLAN_API_TOKEN\` in your .gitlab-ci.yml file.
`We couldn't connect to your Atlan Instance, please make sure to set the valid Atlan Bearer Token as \`ATLAN_API_TOKEN\` in your .gitlab-ci.yml file.
Atlan Instance URL: ${ATLAN_INSTANCE_URL}`
);
Expand All @@ -266,7 +268,7 @@ Atlan Instance URL: ${ATLAN_INSTANCE_URL}`
if (response === undefined) {
await this.createIssueComment(
gitlab,
`We couldn't connect to your Atlan Instance, please make sure to set the valid Atlan Instance URL as \`ATLAN_INSTANCE_URL\` in your .gitlab-ci.yml file.
`We couldn't connect to your Atlan Instance, please make sure to set the valid Atlan Instance URL as \`ATLAN_INSTANCE_URL\` in your .gitlab-ci.yml file.
Atlan Instance URL: ${ATLAN_INSTANCE_URL}
Expand Down Expand Up @@ -532,7 +534,7 @@ ${content}`;
? getCertificationImage(asset.attributes.certificateStatus)
: ""
}
**${downstreamAssets.length} downstream assets** 👇
Name | Type | Description | Owners | Terms | Source URL
--- | --- | --- | --- | --- | ---
Expand All @@ -541,7 +543,7 @@ ${content}`;
row.map((i) => i.replace(/\|/g, "•").replace(/\n/g, "")).join(" | ")
)
.join("\n")}
${getImageURL(
"atlan-logo",
15,
Expand Down
Loading

0 comments on commit 63c7d59

Please sign in to comment.