Skip to content

Commit

Permalink
feat: comment the application status on gitlab
Browse files Browse the repository at this point in the history
  • Loading branch information
soumyadip007 committed Sep 20, 2023
1 parent 6083ad5 commit 816471a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
10 changes: 5 additions & 5 deletions controllers/events.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const { log } = require('@spaship/common/lib/logging/pino');
const { commentOnGitlabCommit } = require('../services/gitlab/api');
const { processResponse } = require('../services/events');

module.exports.post = async (req, res) => {
const payload = req.body;
const { projectId, commitId, commentBody } = payload;
log.info(payload);
try {
await commentOnGitlabCommit(payload, projectId, commitId, commentBody);
return res.sendStatus(200);
const response = await processResponse(payload);
res.status(200);
return res.send(response);
} catch (error) {
res.status(500);
return res.send({ message: 'Error while commenting on Gitlab' });
return res.send(error);
}
};
31 changes: 31 additions & 0 deletions services/events/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { commentOnGitlabCommit } = require('./../gitlab/api');
const { status: deploymentStatus } = require('../../config');
const processResponse = async (payload) => {
const { projectId, commitId, status: applicationStatus, accessUrl } = payload;
const messageHeader = '<b>🔔 Application Build & Deployment Status 🚀 </b> \n\n';
let commentBody = "We're encountering some issue with the Deployment, Please connect with the SPAship Team.";
try {
if (applicationStatus) {
if (applicationStatus === deploymentStatus.APPLICATION_DEPLOYED)
commentBody = `${messageHeader} 🥳 Application is deployed Successfully. 🌐 You can access the Application from here : ${accessUrl?.toString()}`;
else if (applicationStatus === deploymentStatus.APPLICATION_BUILD_FAILED)
commentBody = `${messageHeader} ❌ Application build is failed, please check the logs from the SPAship manager for the stacktrace.`;
else if (applicationStatus === deploymentStatus.APPLICATION_BUILD_TIMEOUT)
commentBody = `${messageHeader} 🕘 ❌ There is the timeout while building the application, please check the logs from the SPAship manager for the stacktrace.`;
else if (applicationStatus === deploymentStatus.APPLICATION_BUILD_TERMINATED)
commentBody = `${messageHeader} 🚫 Application build has been terminated, please check the logs from the SPAship manager for the stacktrace.`;
else if (applicationStatus === deploymentStatus.APPLICATION_DEPLOYMENT_FAILED)
commentBody = `${messageHeader} ❌ Application deployment is failed, please check the SPAship manager for the more details.`;
else if (applicationStatus === deploymentStatus.APPLICATION_DEPLOYMENT_TIMEOUT)
commentBody = `${messageHeader} 🕘 ❌ There is the timeout while deploying the application, please check the SPAship manager for the more details.`;
await commentOnGitlabCommit(payload, projectId, commitId, commentBody);
}
return { message: `Commented on the ${commitId} commit successfully.` };
} catch (error) {
throw new Error({ message: 'Error while commenting on Gitlab' });
}
};

module.exports = {
processResponse
};

0 comments on commit 816471a

Please sign in to comment.