mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
fix update notification, remove simple-git
This commit is contained in:
parent
860840c367
commit
22384342db
@ -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
|
||||
|
||||
|
@ -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,20 +56,26 @@ 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 () {
|
||||
for (let repo of gitRepos) {
|
||||
getRepoInfo: async function (repo) {
|
||||
let gitInfo = {
|
||||
module: repo.module,
|
||||
// commits behind:
|
||||
@ -80,64 +87,49 @@ module.exports = NodeHelper.create({
|
||||
// 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);
|
||||
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();
|
||||
// console.log("current: " + gitInfo.current);
|
||||
status = status[1].split(" ");
|
||||
gitInfo.tracking = status[0].trim();
|
||||
// console.log("tracking: " + gitInfo.tracking);
|
||||
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));
|
||||
// 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
|
||||
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 = stderr.split('\n')[1].match(/s*([a-z,0-9]+[\.]+[a-z,0-9]+)s*/g)[0];
|
||||
// console.dir(refs);
|
||||
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) {
|
||||
const gitInfo = await this.getRepoInfo(repo);
|
||||
if (gitInfo) {
|
||||
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);
|
||||
// }
|
||||
}
|
||||
|
||||
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
|
||||
|
21
package-lock.json
generated
21
package-lock.json
generated
@ -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",
|
||||
|
@ -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": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user