@btag/react-trumbowyg
Version:
React wrapper for Trumbowyg
174 lines (152 loc) • 7.13 kB
JavaScript
const axios = require('axios');
const async = require('async');
console.log(` [INFO] BASIC_AUTH_BUILDKITE: ...${process.env.BASIC_AUTH_BUILDKITE.slice(-5)}`);
console.log(` [INFO] BASIC_AUTH_CONFLUENCE: ...${process.env.BASIC_AUTH_CONFLUENCE.slice(-5)}`);
console.log(` [INFO] BUILDKITE_BUILD_NUMBER: ${process.env.BUILDKITE_BUILD_NUMBER}`);
console.log(` [INFO] BUILDKITE_BUILD_URL: ${process.env.BUILDKITE_BUILD_URL}`);
console.log(` [INFO] BUILDKITE_PIPELINE_SLUG: ${process.env.BUILDKITE_PIPELINE_SLUG}`);
console.log(` [INFO] BUILDKITE_UNBLOCKER: ${process.env.BUILDKITE_UNBLOCKER}`);
console.log(` [INFO] DEPLOY_ENV: ${process.env.DEPLOY_ENV}`);
console.log(` [INFO] PROJECT_NAME: "${process.env.PROJECT_NAME}"`);
console.log(` [INFO] STEP_NAME: "${process.env.STEP_NAME}"`);
const buildkiteAuth = process.env.BASIC_AUTH_BUILDKITE;
const confluenceAuth = process.env.BASIC_AUTH_CONFLUENCE;
const confluenceProjectName = process.env.PROJECT_NAME;
const deployStepName = process.env.STEP_NAME;
const getRequest = (_url, auth) =>
axios({
method: 'get',
url: _url,
headers: {
Authorization: `${auth}`,
},
})
.then((response) => {
return response.data;
})
.catch((error) => {
console.log(error);
process.exit(1);
});
const putRequest = (_url, auth, _newBody) =>
axios({
method: 'put',
url: _url,
headers: {
Authorization: `${auth}`,
'Content-type': 'application/json',
Accept: 'application/json',
},
data: _newBody,
})
.then((response) => {
console.log(`Request Response: ${response.status}`);
})
.catch((error) => {
console.log(error);
process.exit(1);
});
async function main() {
let confluencePageId;
let pageTitle;
// if (process.env.DEPLOY_ENV.includes('prod')) {
// if (process.env.DEPLOY_ENV.includes('eu-c1')) {
// confluencePageId = 3781138705;
// pageTitle = 'Production Deployment Status - EU';
// } else if (process.env.DEPLOY_ENV.includes('us-w2')) {
// confluencePageId = 3781138695;
// pageTitle = 'Production Deployment Status - NA';
// }
// // Get the current version of Confluence page
// const curConfluenceVersion = await getRequest(
// `https://mitarbeiterapp.atlassian.net/wiki/rest/api/content/?id=${confluencePageId}&expand=version`,
// `Basic ${confluenceAuth}`,
// );
// const newConfluenceVersion = (curConfluenceVersion.results[0].version.number += 1);
// // Get the current body content of Confluence page
// const curConfluencePage = await getRequest(
// `https://mitarbeiterapp.atlassian.net/wiki/rest/api/content/?id=${confluencePageId}&expand=body.storage`,
// `Basic ${confluenceAuth}`,
// );
// const curConfluenceBodyValue = curConfluencePage.results[0].body.storage.value;
// // Get the pipeline details for the commit hash
// const buildkiteBuildDetails = await getRequest(
// `https://api.buildkite.com/v2/organizations/bananatag/pipelines/${process.env.BUILDKITE_PIPELINE_SLUG}/builds/${process.env.BUILDKITE_BUILD_NUMBER}`,
// `Bearer ${buildkiteAuth}`,
// );
// // Setting Indexes to prepare the message body
// const projectNameIndex = curConfluencePage.results[0].body.storage.value.indexOf(
// `${confluenceProjectName}`,
// );
// const startDeployedDetailIndex = curConfluencePage.results[0].body.storage.value.indexOf(
// ':',
// projectNameIndex,
// );
// const endDeployedDetailIndex = curConfluencePage.results[0].body.storage.value.indexOf(
// '</p>',
// projectNameIndex,
// );
// // String with the current latest deployed history
// const deployedHistory = curConfluencePage.results[0].body.storage.value.substring(
// startDeployedDetailIndex + 2,
// endDeployedDetailIndex,
// );
// // Get the time that the new deployment finished in Buildkite
// let jobFinishedTime;
// for (const buildJobDetails of buildkiteBuildDetails.jobs) {
// if (buildJobDetails.name === `${deployStepName} ${process.env.DEPLOY_ENV}`) {
// jobFinishedTime = buildJobDetails.finished_at;
// }
// }
// // New string containing the new deployment details
// const newDeploymentBody = `Deployed on ${jobFinishedTime} by ${process.env.BUILDKITE_UNBLOCKER} - <a href="${process.env.BUILDKITE_BUILD_URL}">Build #${process.env.BUILDKITE_BUILD_NUMBER}</a>`;
// // Removing the deployment details from previous deployment from the Confluence body
// const bodyWithoutLatestDeployment = [
// curConfluenceBodyValue.slice(0, startDeployedDetailIndex + 2),
// curConfluenceBodyValue.slice(endDeployedDetailIndex),
// ].join('');
// // Adding the new deployment details in the Confluence Body
// const newConfluenceBodyValue = [
// bodyWithoutLatestDeployment.slice(0, startDeployedDetailIndex + 2),
// newDeploymentBody,
// bodyWithoutLatestDeployment.slice(startDeployedDetailIndex + 2),
// ].join('');
// // Preparing the indexes to add the old deployment details to the history section
// const projectHistoryIndex = newConfluenceBodyValue.indexOf(
// `${confluenceProjectName} deployment history:`,
// );
// const startHistoryIndex = newConfluenceBodyValue.indexOf('<ul>', projectHistoryIndex);
// // Adding the old deployment to the history section
// const bodyWithUpdatedHistory = [
// newConfluenceBodyValue.slice(0, startHistoryIndex + 4),
// '<li>',
// deployedHistory,
// '</li>',
// newConfluenceBodyValue.slice(startHistoryIndex + 4),
// ].join('');
// const newConfluenceBodyValueStringified = JSON.stringify(bodyWithUpdatedHistory);
// // Preparing the complete body to be updated
// const newConflueceBody = `{
// "version": {
// "number": ${newConfluenceVersion}
// },
// "title": "${pageTitle}",
// "type": "page",
// "status": "current",
// "body": {
// "storage": {
// "value": ${newConfluenceBodyValueStringified},
// "representation": "storage"
// }
// }
// }`;
// putRequest(
// `https://mitarbeiterapp.atlassian.net/wiki/rest/api/content/${confluencePageId}`,
// `Basic ${confluenceAuth}`,
// newConflueceBody,
// );
// } else {
// console.log(`Current environment is not Production: ${process.env.DEPLOY_ENV}`);
// }
}
main();