update index

This commit is contained in:
Joseph Le 2023-10-13 13:46:46 +00:00
parent 52e19c07ff
commit 618d0a4151
2 changed files with 112 additions and 94 deletions

View File

@ -16,7 +16,7 @@ const PORT = contentFile
app.use(express.json());
app.post("/git/gitea-webhook", async (req, res) => {
console.log("AAAAAAAAAAAAAAAA")
let title = ""
const checkSendMail = contentFile
.split("\n")
.filter((i) => i.includes("SEND_EMAIL"))[0]
@ -36,12 +36,21 @@ console.log("AAAAAAAAAAAAAAAA")
.send({ mess: "The event has been received!", data: req.body });
exec("./service_run/giteaHook.sh", (error, stdout, stderr) => {
let content = stdout !== ""? stdout : stderr
if (error) {
console.log("Pull failed. Please check");
console.log(`Error executing command: ${error}`);
// res.status(500).send("PULL ERROR")
}
title += "New Git envent: " + giteaEvent + "(error)"
}else{
console.log(stdout);
if(stderr.includes("Error") || stderr.includes("failed") || stdout.includes("Error") || stdout.includes("failed")){
title += "New Git envent: " + giteaEvent + "(error)"
}else{
title += "New Git envent: " + giteaEvent + "(success)"
}
}
if (checkSendMail === "True") {
const transporter = nodeMailer.createTransport({
pool: true,
@ -57,7 +66,7 @@ console.log("AAAAAAAAAAAAAAAA")
const options = {
from: "admin@apactech.io",
to: emailAddress,
subject: "New Git envent: " + giteaEvent,
subject: title,
html:
"<h1>*** " +
giteaEvent +
@ -72,15 +81,16 @@ console.log("AAAAAAAAAAAAAAAA")
"'>Link: " +
req.body.commits[0]?.url +
"</a><h4>Process output:</h4><textarea style='wordWrap:break-word; display: block; width:100%; height:70vh;border:solid 2px orange'>" +
stdout +
content +
"</textarea>",
};
return transporter.sendMail(options);
}
});
});
app.listen(PORT, () => {
console.log("Server is running on port ", PORT);
console.log("Service is running on port ", PORT);
});

View File

@ -39,10 +39,16 @@ function run_commands() {
}
result=$(git pull origin $GIT_BRANCH) &&
echo "" &&
echo "--> git pull origin $GIT_BRANCH" &&
echo "" &&
echo "$result" &&
if [ $? -ne 0 ]; then
echo "Pull failed. Please check!"
error_message=$(git pull origin $GIT_BRANCH 2>&1)
echo "Error: $error_message"
else
echo "Pull success!"
echo "" &&
echo "--> git pull origin $GIT_BRANCH" &&
echo "" &&
echo "$result" &&
if [[ $result == *$fe_path* ]]; then
echo "|--------------------------------------------------------|"
echo "|***** THERE ARE CHANGES INSIDE FOLDER $fe_path *****|"
@ -63,11 +69,11 @@ echo "$result" &&
cp -rf $project/$fe_path/build/* $FE_ROOT_FOLDER_PATH
fi
echo "|----------------------|"
echo "|*** UPDATE LIBRARY ***|"
echo "|----------------------|"
echo "|----------------------|"
echo "|*** UPDATE LIBRARY ***|"
echo "|----------------------|"
input_file="$HOOK_PATH/service_run/giteaService.conf" &&
input_file="$HOOK_PATH/service_run/giteaService.conf" &&
# Doc va xu ly tung dong
while IFS= read -r line; do
@ -91,6 +97,8 @@ input_file="$HOOK_PATH/service_run/giteaService.conf" &&
fi
fi
done <"$input_file" &&
echo "|------------|"
echo "|*** DONE ***|"
echo "|------------|"
echo "|------------|"
echo "|*** DONE ***|"
echo "|------------|"
fi