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 #124

Merged
merged 22 commits into from
Nov 8, 2023
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a5830c7
Merge pull request #110 from atlanhq/ACTIV-1019-project-and-environme…
Jaagrav Aug 16, 2023
c941618
chore: Update dist
Aug 16, 2023
93bc75d
Did some restructuring of code
ArpitShukla12 Sep 26, 2023
74744c9
Restructured the code
ArpitShukla12 Sep 29, 2023
63c7d59
Added logs for debugging
ArpitShukla12 Oct 3, 2023
512a33c
Removed comments
ArpitShukla12 Oct 10, 2023
816b36a
Added few more logs
ArpitShukla12 Oct 11, 2023
efdf3de
Squashed all commits
ArpitShukla12 Nov 7, 2023
9e8a7cf
Merge branch 'feat/integration_support' into PR_staging_integration_s…
ArpitShukla12 Nov 7, 2023
4a63c0c
Changed setResourceOnAsset message
ArpitShukla12 Nov 7, 2023
556c63d
Merge branch 'feat/integration_support' into PR_staging_integration_s…
ArpitShukla12 Nov 7, 2023
32c1386
Added correct documentation link
ArpitShukla12 Nov 7, 2023
4e6deea
Merge branch 'feat/integration_support' into PR_staging_integration_s…
ArpitShukla12 Nov 7, 2023
83b0c07
Testing segments
ArpitShukla12 Nov 8, 2023
24f93a2
Debugging segment
ArpitShukla12 Nov 8, 2023
458e6c1
fixing bug
ArpitShukla12 Nov 8, 2023
e3c0d43
fixing bug1
ArpitShukla12 Nov 8, 2023
38c7ab5
Logging for fix
ArpitShukla12 Nov 8, 2023
31e0aa9
Resolved set resource on asset issue
ArpitShukla12 Nov 8, 2023
8ff1a35
Resolved segment event issue
ArpitShukla12 Nov 8, 2023
23714b9
Merge branch 'feat/integration_support' into PR_staging_integration_s…
ArpitShukla12 Nov 8, 2023
1d5e08b
Merge pull request #119 from ArpitShukla12/PR_staging_integration_sup…
ArpitShukla12 Nov 8, 2023
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
Added logs for debugging
ArpitShukla12 committed Oct 3, 2023
commit 63c7d59f1a41c80e149c6b9c24c578e08e08c330
4 changes: 2 additions & 2 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
@@ -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:
@@ -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
@@ -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();

@@ -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
@@ -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,
@@ -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();

@@ -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 });
}

@@ -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;

@@ -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;
@@ -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
@@ -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
@@ -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,
@@ -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;
}

@@ -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,
},
});
@@ -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}`;

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

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

if (IS_DEV) return content;

@@ -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(" | ")
@@ -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}`;
14 changes: 8 additions & 6 deletions adapters/integrations/gitlab-integration.js
Original file line number Diff line number Diff line change
@@ -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,
@@ -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;
@@ -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,
@@ -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}`
);
@@ -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}

@@ -532,7 +534,7 @@ ${content}`;
? getCertificationImage(asset.attributes.certificateStatus)
: ""
}

**${downstreamAssets.length} downstream assets** 👇
Name | Type | Description | Owners | Terms | Source URL
--- | --- | --- | --- | --- | ---
@@ -541,7 +543,7 @@ ${content}`;
row.map((i) => i.replace(/\|/g, "•").replace(/\n/g, "")).join(" | ")
)
.join("\n")}

${getImageURL(
"atlan-logo",
15,
Loading