From fa09ae76bb3b12bf753ccebaa1ab7bacc6f72b9c Mon Sep 17 00:00:00 2001 From: Joseph Le Date: Fri, 13 Oct 2023 13:21:50 +1100 Subject: [PATCH] update index.js, env --- README.md | 2 +- index.js | 14 +++++++++----- service/giteaHook.sh | 21 ++------------------- service/giteaService.conf | 5 +++-- 4 files changed, 15 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 7c3bb72..ee3c0f3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ### 1) Clone project to your server ```sh - git clone https://:gitea.nswteam.net/joseph/gitea_CICD.git + git clone https://:@gitea.nswteam.net/joseph/gitea_CICD.git ``` - Get username:
getUsername
diff --git a/index.js b/index.js index 4abd8cc..c1c55fe 100644 --- a/index.js +++ b/index.js @@ -3,14 +3,19 @@ const express = require("express"); const app = express(); const { exec } = require("child_process"); const nodeMailer = require("nodemailer"); +const contentFile = fs.readFileSync( + "./service_run/giteaService.conf", + "utf8" +); +const PORT = contentFile + .split("\n") + .filter((i) => i.includes("PORT_SERVICE"))[0] + ?.split("=")[1] + .trim(); app.use(express.json()); app.post("/git/gitea-webhook", async (req, res) => { - const contentFile = await fs.readFileSync( - "./service_run/giteaService.conf", - "utf8" - ); const checkSendMail = contentFile .split("\n") .filter((i) => i.includes("SEND_EMAIL"))[0] @@ -75,7 +80,6 @@ app.post("/git/gitea-webhook", async (req, res) => { }); }); -const PORT = 5000; app.listen(PORT, () => { console.log("Server is running on port ", PORT); }); diff --git a/service/giteaHook.sh b/service/giteaHook.sh index 880eee6..4059c2b 100755 --- a/service/giteaHook.sh +++ b/service/giteaHook.sh @@ -38,25 +38,8 @@ function run_commands() { echo "" } -result=$(expect -c " - set timeout 10 - spawn git pull origin $GIT_BRANCH - expect { - \"Username for *\" { - send \"$username\r\" - exp_continue - } - \"Password for *\" { - sleep 2 - send \"$password\r\r\" - exp_continue - } - eof - } - catch wait result - exit [lindex \$result 3] -") && - echo "$result" && +result=$(spawn git pull origin $GIT_BRANCH) && +echo "$result" && if [[ $result == *$fe_path* ]]; then echo "|--------------------------------------------------------|" echo "|***** THERE ARE CHANGES INSIDE FOLDER $fe_path *****|" diff --git a/service/giteaService.conf b/service/giteaService.conf index 5c63ab6..36af598 100755 --- a/service/giteaService.conf +++ b/service/giteaService.conf @@ -4,10 +4,11 @@ HOOK_PATH=/home/gitea_CICD # Git account (*) -GIT_USERNAME= -GIT_PASSWORD= GIT_BRANCH= +# Port of server (*) +PORT_SERVICE=5000 + # Email: Used to send notifications when the repository has updates (*) EMAIL_ADDRESS= # Enable/Disable send mail: True or False (*)