-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: comment the application status on gitlab
- Loading branch information
1 parent
6083ad5
commit 816471a
Showing
2 changed files
with
36 additions
and
5 deletions.
There are no files selected for viewing
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,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); | ||
} | ||
}; |
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,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 | ||
}; |