diff --git a/index.js b/index.js
index c0f877f..c18c123 100644
--- a/index.js
+++ b/index.js
@@ -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:
- "
*** " +
- giteaEvent +
- " event ***
Committer: " +
- req.body.commits[0]?.committer.name +
- "
Message: " +
- req.body.commits[0]?.message +
- "
Branch: " +
- req.body.ref +
- "
Link: " +
- req.body.commits[0]?.url +
- "Process output:
",
- };
-
- 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:
+ "*** " +
+ giteaEvent +
+ " event ***
Committer: " +
+ req.body.commits[0]?.committer.name +
+ "
Message: " +
+ req.body.commits[0]?.message +
+ "
Branch: " +
+ req.body.ref +
+ "
Link: " +
+ req.body.commits[0]?.url +
+ "Process output:
",
+ };
+
+ return transporter.sendMail(options);
+ }
+
});
});
app.listen(PORT, () => {
- console.log("Server is running on port ", PORT);
+ console.log("Service is running on port ", PORT);
});
diff --git a/service/giteaHook.sh b/service/giteaHook.sh
index b3a2b16..2102973 100755
--- a/service/giteaHook.sh
+++ b/service/giteaHook.sh
@@ -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
+