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,51 +36,61 @@ 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)"
}
}
console.log(stdout);
if (checkSendMail === "True") {
const transporter = nodeMailer.createTransport({
pool: true,
host: "mail.ipsupply.com.au",
port: 465,
secure: true,
auth: {
user: "admin@apactech.io",
pass: "BGK!dyt6upd2eax1bhz",
},
});
const options = {
from: "admin@apactech.io",
to: emailAddress,
subject: "New Git envent: " + giteaEvent,
html:
"<h1>*** " +
giteaEvent +
" event ***</h1><h4>Committer: " +
req.body.commits[0]?.committer.name +
"</h4><h4>Message: " +
req.body.commits[0]?.message +
"</h4><h4>Branch: " +
req.body.ref +
"</h4><a href='" +
req.body.commits[0]?.url +
"'>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 +
"</textarea>",
};
return transporter.sendMail(options);
}
const transporter = nodeMailer.createTransport({
pool: true,
host: "mail.ipsupply.com.au",
port: 465,
secure: true,
auth: {
user: "admin@apactech.io",
pass: "BGK!dyt6upd2eax1bhz",
},
});
const options = {
from: "admin@apactech.io",
to: emailAddress,
subject: title,
html:
"<h1>*** " +
giteaEvent +
" event ***</h1><h4>Committer: " +
req.body.commits[0]?.committer.name +
"</h4><h4>Message: " +
req.body.commits[0]?.message +
"</h4><h4>Branch: " +
req.body.ref +
"</h4><a href='" +
req.body.commits[0]?.url +
"'>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'>" +
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,58 +39,66 @@ function run_commands() {
}
result=$(git pull origin $GIT_BRANCH) &&
echo "" &&
echo "--> git pull origin $GIT_BRANCH" &&
echo "" &&
echo "$result" &&
if [[ $result == *$fe_path* ]]; then
echo "|--------------------------------------------------------|"
echo "|***** THERE ARE CHANGES INSIDE FOLDER $fe_path *****|"
echo "|--------------------------------------------------------|"
echo "|---------------|"
echo "|*** INSTALL ***|"
echo "|---------------|"
cd $project/$fe_path &&
npm install
echo "|-------------|"
echo "|*** BUILD ***|"
echo "|-------------|"
npm run build &&
cp -rf $project/$fe_path/build/* $FE_ROOT_FOLDER_PATH
fi
echo "|----------------------|"
echo "|*** UPDATE LIBRARY ***|"
echo "|----------------------|"
input_file="$HOOK_PATH/service_run/giteaService.conf" &&
# Doc va xu ly tung dong
while IFS= read -r line; do
# Kiem tra xem dong có chua "_PATH" không
if [[ $line == *"_PROCESS_PATH"* && $line != "#"* && $line != *"_COMMAND"* ]]; then
IFS="=" read -r variable value <<<"$line"
variable=$(echo "$variable" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
path=$(echo "$value" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# Loai bo khoang trong trong duong dan
path=$(echo "$path" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# Kiem tra duong dan ton tai
if [ ! -e "$path" ]; then
echo ""
echo -e "\e[41mError: $path not exists.\e[0m"
echo ""
exit 1 # Dung chuong trinh
else
echo -e "\e[32mProcessing in\e[0m: $path"
run_commands "$variable"
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 *****|"
echo "|--------------------------------------------------------|"
echo "|---------------|"
echo "|*** INSTALL ***|"
echo "|---------------|"
cd $project/$fe_path &&
npm install
echo "|-------------|"
echo "|*** BUILD ***|"
echo "|-------------|"
npm run build &&
cp -rf $project/$fe_path/build/* $FE_ROOT_FOLDER_PATH
fi
fi
done <"$input_file" &&
echo "|------------|"
echo "|*** DONE ***|"
echo "|------------|"
echo "|----------------------|"
echo "|*** UPDATE LIBRARY ***|"
echo "|----------------------|"
input_file="$HOOK_PATH/service_run/giteaService.conf" &&
# Doc va xu ly tung dong
while IFS= read -r line; do
# Kiem tra xem dong có chua "_PATH" không
if [[ $line == *"_PROCESS_PATH"* && $line != "#"* && $line != *"_COMMAND"* ]]; then
IFS="=" read -r variable value <<<"$line"
variable=$(echo "$variable" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
path=$(echo "$value" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# Loai bo khoang trong trong duong dan
path=$(echo "$path" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# Kiem tra duong dan ton tai
if [ ! -e "$path" ]; then
echo ""
echo -e "\e[41mError: $path not exists.\e[0m"
echo ""
exit 1 # Dung chuong trinh
else
echo -e "\e[32mProcessing in\e[0m: $path"
run_commands "$variable"
fi
fi
done <"$input_file" &&
echo "|------------|"
echo "|*** DONE ***|"
echo "|------------|"
fi