mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 21:00:57 +00:00
added possibility to ignore MagicMirror repo in updatenotification (#3002)
was [requested in the forum](https://forum.magicmirror.builders/topic/17519/updatenotification). - added possibility to exclude MagicMirror Repo and renamed it from `default` to `MagicMirror` - improved getting `behind` in case a hard `git fetch` was already done - removed test "excludes repo if refs don't match regex" because of above improvement this case is obsolete - improved `git fetch --dry-run` with `-n` option to exclude tags (noise reduction)
This commit is contained in:
@@ -13,6 +13,7 @@ _This release is scheduled to be released on 2023-04-01._
|
|||||||
|
|
||||||
- Added increments for hourly forecasts in weather module (#2996)
|
- Added increments for hourly forecasts in weather module (#2996)
|
||||||
- Added tests for hourly weather forecast
|
- Added tests for hourly weather forecast
|
||||||
|
- Added possibility to ignore MagicMirror repo in updatenotification module
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@ class GitHelper {
|
|||||||
async add(moduleName) {
|
async add(moduleName) {
|
||||||
let moduleFolder = BASE_DIR;
|
let moduleFolder = BASE_DIR;
|
||||||
|
|
||||||
if (moduleName !== "default") {
|
if (moduleName !== "MagicMirror") {
|
||||||
moduleFolder = `${moduleFolder}modules/${moduleName}`;
|
moduleFolder = `${moduleFolder}modules/${moduleName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ class GitHelper {
|
|||||||
isBehindInStatus: false
|
isBehindInStatus: false
|
||||||
};
|
};
|
||||||
|
|
||||||
if (repo.module === "default") {
|
if (repo.module === "MagicMirror") {
|
||||||
// the hash is only needed for the mm repo
|
// the hash is only needed for the mm repo
|
||||||
const { stderr, stdout } = await this.execShell(`cd ${repo.folder} && git rev-parse HEAD`);
|
const { stderr, stdout } = await this.execShell(`cd ${repo.folder} && git rev-parse HEAD`);
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ class GitHelper {
|
|||||||
return gitInfo;
|
return gitInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { stderr } = await this.execShell(`cd ${repo.folder} && git fetch --dry-run`);
|
const { stderr } = await this.execShell(`cd ${repo.folder} && git fetch -n --dry-run`);
|
||||||
|
|
||||||
// example output:
|
// example output:
|
||||||
// From https://github.com/MichMich/MagicMirror
|
// From https://github.com/MichMich/MagicMirror
|
||||||
@@ -129,14 +129,16 @@ class GitHelper {
|
|||||||
// here the result is in stderr (this is a git default, don't ask why ...)
|
// here the result is in stderr (this is a git default, don't ask why ...)
|
||||||
const matches = stderr.match(this.getRefRegex(gitInfo.current));
|
const matches = stderr.match(this.getRefRegex(gitInfo.current));
|
||||||
|
|
||||||
if (!matches || !matches[0]) {
|
// this is the default if there was no match from "git fetch -n --dry-run".
|
||||||
// no refs found, nothing to do
|
// Its a fallback because if there was a real "git fetch", the above "git fetch -n --dry-run" would deliver nothing.
|
||||||
return;
|
let refDiff = gitInfo.current + "..origin/" + gitInfo.current;
|
||||||
|
if (matches && matches[0]) {
|
||||||
|
refDiff = matches[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// get behind with refs
|
// get behind with refs
|
||||||
try {
|
try {
|
||||||
const { stdout } = await this.execShell(`cd ${repo.folder} && git rev-list --ancestry-path --count ${matches[0]}`);
|
const { stdout } = await this.execShell(`cd ${repo.folder} && git rev-list --ancestry-path --count ${refDiff}`);
|
||||||
gitInfo.behind = parseInt(stdout);
|
gitInfo.behind = parseInt(stdout);
|
||||||
|
|
||||||
return gitInfo;
|
return gitInfo;
|
||||||
|
@@ -19,7 +19,9 @@ module.exports = NodeHelper.create({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.gitHelper.add("default");
|
if (!this.ignoreUpdateChecking("MagicMirror")) {
|
||||||
|
await this.gitHelper.add("MagicMirror");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async socketNotificationReceived(notification, payload) {
|
async socketNotificationReceived(notification, payload) {
|
||||||
|
@@ -77,7 +77,7 @@ Module.register("updatenotification", {
|
|||||||
|
|
||||||
addFilters() {
|
addFilters() {
|
||||||
this.nunjucksEnvironment().addFilter("diffLink", (text, status) => {
|
this.nunjucksEnvironment().addFilter("diffLink", (text, status) => {
|
||||||
if (status.module !== "default") {
|
if (status.module !== "MagicMirror") {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
<div class="small bright">
|
<div class="small bright">
|
||||||
<i class="fas fa-exclamation-circle"></i>
|
<i class="fas fa-exclamation-circle"></i>
|
||||||
<span>
|
<span>
|
||||||
{% set mainTextLabel = "UPDATE_NOTIFICATION" if name === "default" else "UPDATE_NOTIFICATION_MODULE" %}
|
{% set mainTextLabel = "UPDATE_NOTIFICATION" if name === "MagicMirror" else "UPDATE_NOTIFICATION_MODULE" %}
|
||||||
{{ mainTextLabel | translate({MODULE_NAME: name}) }}
|
{{ mainTextLabel | translate({MODULE_NAME: name}) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -11,24 +11,24 @@ exports[`Updatenotification custom module returns status information without has
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Updatenotification default returns status information 1`] = `
|
exports[`Updatenotification MagicMirror returns status information 1`] = `
|
||||||
{
|
{
|
||||||
"behind": 5,
|
"behind": 5,
|
||||||
"current": "develop",
|
"current": "develop",
|
||||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||||
"isBehindInStatus": false,
|
"isBehindInStatus": false,
|
||||||
"module": "default",
|
"module": "MagicMirror",
|
||||||
"tracking": "origin/develop",
|
"tracking": "origin/develop",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Updatenotification default returns status information early if isBehindInStatus 1`] = `
|
exports[`Updatenotification MagicMirror returns status information early if isBehindInStatus 1`] = `
|
||||||
{
|
{
|
||||||
"behind": 5,
|
"behind": 5,
|
||||||
"current": "develop",
|
"current": "develop",
|
||||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||||
"isBehindInStatus": true,
|
"isBehindInStatus": true,
|
||||||
"module": "default",
|
"module": "MagicMirror",
|
||||||
"tracking": "origin/develop",
|
"tracking": "origin/develop",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
@@ -57,7 +57,7 @@ describe("Updatenotification", () => {
|
|||||||
return { stdout: gitRevParseOut, stderr: gitRevParseErr };
|
return { stdout: gitRevParseOut, stderr: gitRevParseErr };
|
||||||
} else if (command.includes("git status -sb")) {
|
} else if (command.includes("git status -sb")) {
|
||||||
return { stdout: gitStatusOut, stderr: gitStatusErr };
|
return { stdout: gitStatusOut, stderr: gitStatusErr };
|
||||||
} else if (command.includes("git fetch --dry-run")) {
|
} else if (command.includes("git fetch -n --dry-run")) {
|
||||||
return { stdout: gitFetchOut, stderr: gitFetchErr };
|
return { stdout: gitFetchOut, stderr: gitFetchErr };
|
||||||
} else if (command.includes("git rev-list --ancestry-path --count")) {
|
} else if (command.includes("git rev-list --ancestry-path --count")) {
|
||||||
return { stdout: gitRevListOut, stderr: gitRevListErr };
|
return { stdout: gitRevListOut, stderr: gitRevListErr };
|
||||||
@@ -71,8 +71,8 @@ describe("Updatenotification", () => {
|
|||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("default", () => {
|
describe("MagicMirror", () => {
|
||||||
const moduleName = "default";
|
const moduleName = "MagicMirror";
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
gitRemoteOut = "origin\tgit@github.com:MichMich/MagicMirror.git (fetch)\norigin\tgit@github.com:MichMich/MagicMirror.git (push)\n";
|
gitRemoteOut = "origin\tgit@github.com:MichMich/MagicMirror.git (fetch)\norigin\tgit@github.com:MichMich/MagicMirror.git (push)\n";
|
||||||
@@ -108,13 +108,6 @@ describe("Updatenotification", () => {
|
|||||||
const { error } = require("logger");
|
const { error } = require("logger");
|
||||||
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
|
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("excludes repo if refs don't match regex", async () => {
|
|
||||||
gitFetchErr = "";
|
|
||||||
|
|
||||||
const repos = await gitHelper.getRepos();
|
|
||||||
expect(repos.length).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("custom module", () => {
|
describe("custom module", () => {
|
||||||
|
Reference in New Issue
Block a user