diff --git a/CHANGELOG.md b/CHANGELOG.md index d2c00f61..e1365099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ _This release is scheduled to be released on 2021-10-01._ - Fix undefined error with ignoreToday option in weather module (#2620). - Fix time zone correction in calendar module when the date hour is equal to the time zone correction value (#2632). - Fix black cursor on startup when using electron. +- Fix update notification not working for own repository (#2644). ## [2.16.0] - 2021-07-01 diff --git a/modules/default/updatenotification/node_helper.js b/modules/default/updatenotification/node_helper.js index fbe363f5..4815dd02 100644 --- a/modules/default/updatenotification/node_helper.js +++ b/modules/default/updatenotification/node_helper.js @@ -1,4 +1,5 @@ -const { exec } = require("child_process"); +const util = require("util"); +const exec = util.promisify(require("child_process").exec); const gitRepos = []; const fs = require("fs"); const path = require("path"); @@ -55,88 +56,79 @@ module.exports = NodeHelper.create({ } }, - isGitRepo: function (moduleFolder) { - exec("cd " + moduleFolder + " && git remote -v", (err, stdout, stderr) => { - if (err) { - Log.error("Failed to fetch git data for " + moduleFolder + ": " + err); - return false; - } - }); + execShell: async function (command) { + let res = { stdout: "", stderr: "" }; + const { stdout, stderr } = await exec(command); - return true; + res.stdout = stdout; + res.stderr = stderr; + return res; }, + isGitRepo: async function (moduleFolder) { + let res = await this.execShell("cd " + moduleFolder + " && git remote -v"); + if (res.stderr) { + Log.error("Failed to fetch git data for " + moduleFolder + ": " + res.stderr); + return false; + } else { + return true; + } + }, - performFetch: function () { + getRepoInfo: async function (repo) { + let gitInfo = { + module: repo.module, + // commits behind: + behind: 0, + // branch name: + current: "", + // current hash: + hash: "", + // remote branch: + tracking: "" + }; + let res = await this.execShell("cd " + repo.folder + " && git rev-parse HEAD"); + if (res.stderr) { + Log.error("Failed to get current commit hash for " + repo.module + ": " + res.stderr); + } + gitInfo.hash = res.stdout; + res = await this.execShell("cd " + repo.folder + " && git status -sb"); + if (res.stderr) { + Log.error("Failed to get git status for " + repo.module + ": " + res.stderr); + // exit without git status info + return; + } + // get branch and remote + let status = res.stdout.split("\n")[0]; + status = status.match(/(?![.#])([^.]*)/g); + gitInfo.current = status[0].trim(); + status = status[1].split(" "); + gitInfo.tracking = status[0].trim(); + if (status[2]) { + // git fetch was already called before so `git status -sb` delivers already the behind number + gitInfo.behind = parseInt(status[2].substring(0, status[2].length - 1)); + return gitInfo; + } + res = await this.execShell("cd " + repo.folder + " && git fetch --dry-run"); + // here the result is in stderr + if (res.stderr === "") return; + // set default > 0 + gitInfo.behind = 1; + let refs = res.stderr.match(/s*([a-z,0-9]+[.][.][a-z,0-9]+)s*/g)[0]; + if (refs === "") { + return gitInfo; + } + res = await this.execShell("cd " + repo.folder + " && git rev-list --ancestry-path --count " + refs); + gitInfo.behind = parseInt(res.stdout); + return gitInfo; + }, + + performFetch: async function () { for (let repo of gitRepos) { - let gitInfo = { - module: repo.module, - // commits behind: - behind: 0, - // branch name: - current: "", - // current hash: - hash: "", - // remote branch: - tracking: "" - }; - exec("cd " + repo.folder + " && git rev-parse HEAD", (err, stdout, stderr) => { - if (err) { - Log.error("Failed to get current commit hash for " + repo.module + ": " + err + " " + stderr); - } else { - // console.log(stdout); - gitInfo.hash = stdout; - // console.log("hash: " + gitInfo.hash); - exec("cd " + repo.folder + " && git status -sb", (err, stdout, stderr) => { - if (err) { - Log.error("Failed to get git status for " + repo.module + ": " + err + " " + stderr); - } else { - let status = stdout.split("\n")[0]; - // console.log(repo.module); - status = status.match(/(?![.#])([^.]*)/g); - gitInfo.current = status[0].trim(); - // console.log("current: " + gitInfo.current); - status = status[1].split(" "); - gitInfo.tracking = status[0].trim(); - // console.log("tracking: " + gitInfo.tracking); - if (status[2]) { - gitInfo.behind = parseInt(status[2].substring(0, status[2].length - 1)); - // console.log("behind: " + gitInfo.behind); - this.sendSocketNotification("STATUS", gitInfo); - } else { - exec("cd " + repo.folder + " && git fetch --dry-run", (err, stdout, stderr) => { - if (err) { - Log.error("Failed to fetch git data for " + repo.module + ": " + err); - } else { - // console.log(repo.module); - // console.dir(stderr); - if (stderr !== "") { - // get behind - gitInfo.behind = 1; - let refs = stderr.split('\n')[1].match(/s*([a-z,0-9]+[\.]+[a-z,0-9]+)s*/g)[0]; - // console.dir(refs); - if (refs === "") { - this.sendSocketNotification("STATUS", gitInfo); - } else { - exec("cd " + repo.folder + " && git rev-list --ancestry-path --count " + refs, (err, stdout, stderr) => { - gitInfo.behind = parseInt(stdout); - // console.log("behind: " + gitInfo.behind); - this.sendSocketNotification("STATUS", gitInfo); - }); - } - } - } - }); - } - } - }); - } - }); - // let gitInfo = await this.getGitData(repo); - // if (gitInfo) { - // console.dir(gitInfo); - // this.sendSocketNotification("STATUS", gitInfo); - // } + const gitInfo = await this.getRepoInfo(repo); + if (gitInfo) { + this.sendSocketNotification("STATUS", gitInfo); + } } this.scheduleNextFetch(this.config.updateInterval); @@ -169,9 +161,3 @@ module.exports = NodeHelper.create({ return false; } }); - - -// [03.09.2021 23:02.36.382] [LOG] hash: e19a42879896d2d8e2406fcb3fd4fdcf15d2ed6b -// [03.09.2021 23:02.36.382] [LOG] trackingorigin/master -// [03.09.2021 23:02.36.714] [LOG] hash: e40ddd4b69424349768b7e451d9c4f52ac4efe45 -// [03.09.2021 23:02.36.714] [LOG] trackingorigin/develop diff --git a/package-lock.json b/package-lock.json index ae6ab35e..db4615df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,6 @@ "moment": "^2.29.1", "node-fetch": "^2.6.1", "node-ical": "^0.13.0", - "simple-git": "^2.45.0", "socket.io": "^4.1.3" }, "devDependencies": { @@ -8707,16 +8706,6 @@ "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==", "dev": true }, - "node_modules/simple-git": { - "version": "2.45.0", - "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-2.45.0.tgz", - "integrity": "sha512-wu/Ujs9IXn0HuyYm4HyRvne+EKsjJSWKEMkB3wQa3gNHSMHt7y3oeNX9zRQ3UBPk7bRRMLLHAdIZCZfHT9ehPg==", - "dependencies": { - "@kwsites/file-exists": "^1.1.1", - "@kwsites/promise-deferred": "^1.1.1", - "debug": "^4.3.1" - } - }, "node_modules/sinon": { "version": "11.1.2", "resolved": "https://registry.npmjs.org/sinon/-/sinon-11.1.2.tgz", @@ -17206,16 +17195,6 @@ "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==", "dev": true }, - "simple-git": { - "version": "2.45.0", - "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-2.45.0.tgz", - "integrity": "sha512-wu/Ujs9IXn0HuyYm4HyRvne+EKsjJSWKEMkB3wQa3gNHSMHt7y3oeNX9zRQ3UBPk7bRRMLLHAdIZCZfHT9ehPg==", - "requires": { - "@kwsites/file-exists": "^1.1.1", - "@kwsites/promise-deferred": "^1.1.1", - "debug": "^4.3.1" - } - }, "sinon": { "version": "11.1.2", "resolved": "https://registry.npmjs.org/sinon/-/sinon-11.1.2.tgz", diff --git a/package.json b/package.json index 6bce27aa..dc92b908 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,6 @@ "moment": "^2.29.1", "node-fetch": "^2.6.1", "node-ical": "^0.13.0", - "simple-git": "^2.45.0", "socket.io": "^4.1.3" }, "_moduleAliases": {