-
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.
feat: add PR link as a resource when PR is merged
- Loading branch information
Showing
11 changed files
with
972 additions
and
52 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { v4 as uuidv4 } from "uuid"; | ||
import fetch from "node-fetch"; | ||
import core from "@actions/core"; | ||
import dotenv from "dotenv"; | ||
|
||
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; | ||
|
||
export default async function createResource(guid, name, link) { | ||
var myHeaders = { | ||
Authorization: `Bearer ${ATLAN_API_TOKEN}`, | ||
"Content-Type": "application/json", | ||
}; | ||
|
||
var raw = JSON.stringify({ | ||
entities: [ | ||
{ | ||
typeName: "Link", | ||
attributes: { | ||
qualifiedName: uuidv4(), | ||
name, | ||
link, | ||
tenantId: "default", | ||
}, | ||
relationshipAttributes: { | ||
asset: { | ||
guid, | ||
}, | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
var requestOptions = { | ||
method: "POST", | ||
headers: myHeaders, | ||
body: raw, | ||
}; | ||
|
||
var response = await fetch( | ||
`${ATLAN_INSTANCE_URL}/api/meta/entity/bulk`, | ||
requestOptions | ||
).then((e) => e.json()); | ||
|
||
return response; | ||
} |
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,2 +1,3 @@ | ||
export { default as getDownstreamAssets } from "./get-downstream-assets.js"; | ||
export { default as getAsset } from "./get-asset.js"; | ||
export { default as createResource } from "./create-resource.js"; |
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 +1,2 @@ | ||
export { default as printDownstreamAssets } from "./print-downstream-assets.js"; | ||
export { default as setResourceOnAsset } from "./set-resource-on-asset.js"; |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { getAsset, createResource } from "../api/index.js"; | ||
import { | ||
createCustomComment, | ||
getChangedFiles, | ||
getAssetName, | ||
} from "../utils/index.js"; | ||
|
||
export default async function setResourceOnAsset({ octokit, context }) { | ||
const changedFiles = await getChangedFiles(octokit, context); | ||
const { pull_request } = context.payload; | ||
|
||
if (changedFiles.length === 0) return; | ||
|
||
changedFiles.forEach(async ({ name, filePath }) => { | ||
const assetName = await getAssetName(octokit, context, name, filePath); | ||
const asset = await getAsset({ name: assetName }); | ||
|
||
if (!asset) return; | ||
|
||
const { guid: modelGuid } = asset; | ||
const { guid: tableAssetGuid } = asset.attributes.sqlAsset; | ||
|
||
await createResource( | ||
modelGuid, | ||
"Pull Request on GitHub", | ||
pull_request.html_url | ||
); | ||
await createResource( | ||
tableAssetGuid, | ||
"Pull Request on GitHub", | ||
pull_request.html_url | ||
); | ||
}); | ||
|
||
const comment = await createCustomComment( | ||
octokit, | ||
context, | ||
`🎊 Congrats on the merge! | ||
This pull request has been added as a resource to all the assets modified. ✅ | ||
` | ||
); | ||
console.log(comment); | ||
} |
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