mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-04-24 22:47:08 -04:00
## [2.27.0] - 2024-04-01 Thanks to: @bugsounet, @crazyscot, @illimarkangur, @jkriegshauser, @khassel, @KristjanESPERANTO, @Paranoid93, @rejas, @sdetweil and @vppencilsharpener. This release marks the first release without Michael Teeuw (@michmich). A very special thanks to him for creating MagicMirror and leading the project for so many years. For more info, please read the following post: [A New Chapter for MagicMirror: The Community Takes the Lead](https://forum.magicmirror.builders/topic/18329/a-new-chapter-for-magicmirror-the-community-takes-the-lead). ### Added - Output of system information to the console for troubleshooting (#3328 and #3337), ignore errors under aarch64 (#3349) - [chore] Add `eslint-plugin-package-json` to lint the `package.json` files (#3368) - [weather] `showHumidity` config is now a string describing where to show this element. Supported values: "wind", "temp", "feelslike", "below", "none". (#3330) - electron-rebuild test suite for electron and 3rd party modules compatibility (#3392) - Create MM² icon and attach it to electron process (#3407) ### Updated - Update updatenotification (update_helper.js): Recode with pm2 library (#3332) - Removing lodash dependency by replacing merge by spread operator (#3339) - Use node prefix for build-in modules (#3340) - Rework logging colors (#3350) - Update pm2 to v5.3.1 with no allow-ghsas (#3364) - [chore] Update husky and let lint-staged fix ESLint issues - [chore] Update dependencies including electron to v29 (#3357) and node-ical - Update translations for estonian (#3371) - Update electron to v29 and update other dependencies - [calendar] fullDay events over several days now show the left days from the first day on and 'today' on the last day - Update layout of current weather indoor values ### Fixed - Correct apibase of weathergov weatherprovider to match documentation (#2926) - Worked around several issues in the RRULE library that were causing deleted calender events to still show, some initial and recurring events to not show, and some event times to be off an hour. (#3291) - Skip changelog requirement when running tests for dependency updates (#3320) - Display precipitation probability when it is 0% instead of blank/empty (#3345) - [newsfeed] Suppress unsightly animation cases when there are 0 or 1 active news items (#3336) - [newsfeed] Always compute the feed item URL using the same helper function (#3336) - Ignore all custom css files (#3359) - [newsfeed] Fix newsfeed stall issue introduced by #3336 (#3361) - Changed `log.debug` to `log.log` in `app.js` where logLevel is not set because config is not loaded at this time (#3353) - [calendar] deny fetch interval < 60000 and set 60000 in this case (prevent fetch loop failed) (#3382) - added message in case where config.js is missing the module.export line PR #3383 - Fixed an issue where recurring events could extend past their recurrence end date (#3393) - Don't display any `npm WARN <....>` on install (#3399) - Fixed move suncalc dependency to production from dev, as it is used by clock module - [compliments] Fix mirror not responding anymore when no compliments are to be shown (#3385) ### Deleted - Unneeded file headers (#3358) --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Michael Teeuw <michael@xonaymedia.nl> Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Karsten Hassel <hassel@gmx.de> Co-authored-by: Ross Younger <crazyscot@gmail.com> Co-authored-by: Bugsounet - Cédric <github@bugsounet.fr> Co-authored-by: jkriegshauser <joshuakr@nvidia.com> Co-authored-by: illimarkangur <116028111+illimarkangur@users.noreply.github.com> Co-authored-by: sam detweiler <sdetweil@gmail.com> Co-authored-by: vppencilsharpener <tim.pray@gmail.com> Co-authored-by: Paranoid93 <6515818+Paranoid93@users.noreply.github.com>
213 lines
6.1 KiB
JavaScript
213 lines
6.1 KiB
JavaScript
const util = require("node:util");
|
|
const exec = util.promisify(require("node:child_process").exec);
|
|
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
const Log = require("logger");
|
|
|
|
const BASE_DIR = path.normalize(`${__dirname}/../../../`);
|
|
|
|
class GitHelper {
|
|
constructor () {
|
|
this.gitRepos = [];
|
|
this.gitResultList = [];
|
|
}
|
|
|
|
getRefRegex (branch) {
|
|
return new RegExp(`s*([a-z,0-9]+[.][.][a-z,0-9]+) ${branch}`, "g");
|
|
}
|
|
|
|
async execShell (command) {
|
|
const { stdout = "", stderr = "" } = await exec(command);
|
|
|
|
return { stdout, stderr };
|
|
}
|
|
|
|
async isGitRepo (moduleFolder) {
|
|
const { stderr } = await this.execShell(`cd ${moduleFolder} && git remote -v`);
|
|
|
|
if (stderr) {
|
|
Log.error(`Failed to fetch git data for ${moduleFolder}: ${stderr}`);
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
async add (moduleName) {
|
|
let moduleFolder = BASE_DIR;
|
|
|
|
if (moduleName !== "MagicMirror") {
|
|
moduleFolder = `${moduleFolder}modules/${moduleName}`;
|
|
}
|
|
|
|
try {
|
|
Log.info(`Checking git for module: ${moduleName}`);
|
|
// Throws error if file doesn't exist
|
|
fs.statSync(path.join(moduleFolder, ".git"));
|
|
|
|
// Fetch the git or throw error if no remotes
|
|
const isGitRepo = await this.isGitRepo(moduleFolder);
|
|
|
|
if (isGitRepo) {
|
|
// Folder has .git and has at least one git remote, watch this folder
|
|
this.gitRepos.push({ module: moduleName, folder: moduleFolder });
|
|
}
|
|
} catch (err) {
|
|
// Error when directory .git doesn't exist or doesn't have any remotes
|
|
// This module is not managed with git, skip
|
|
}
|
|
}
|
|
|
|
async getStatusInfo (repo) {
|
|
let gitInfo = {
|
|
module: repo.module,
|
|
behind: 0, // commits behind
|
|
current: "", // branch name
|
|
hash: "", // current hash
|
|
tracking: "", // remote branch
|
|
isBehindInStatus: false
|
|
};
|
|
|
|
if (repo.module === "MagicMirror") {
|
|
// the hash is only needed for the mm repo
|
|
const { stderr, stdout } = await this.execShell(`cd ${repo.folder} && git rev-parse HEAD`);
|
|
|
|
if (stderr) {
|
|
Log.error(`Failed to get current commit hash for ${repo.module}: ${stderr}`);
|
|
}
|
|
|
|
gitInfo.hash = stdout;
|
|
}
|
|
|
|
const { stderr, stdout } = await this.execShell(`cd ${repo.folder} && git status -sb`);
|
|
|
|
if (stderr) {
|
|
Log.error(`Failed to get git status for ${repo.module}: ${stderr}`);
|
|
// exit without git status info
|
|
return;
|
|
}
|
|
|
|
// only the first line of stdout is evaluated
|
|
let status = stdout.split("\n")[0];
|
|
// examples for status:
|
|
// ## develop...origin/develop
|
|
// ## master...origin/master [behind 8]
|
|
// ## master...origin/master [ahead 8, behind 1]
|
|
// ## HEAD (no branch)
|
|
status = status.match(/## (.*)\.\.\.([^ ]*)(?: .*behind (\d+))?/);
|
|
// examples for status:
|
|
// [ '## develop...origin/develop', 'develop', 'origin/develop' ]
|
|
// [ '## master...origin/master [behind 8]', 'master', 'origin/master', '8' ]
|
|
// [ '## master...origin/master [ahead 8, behind 1]', 'master', 'origin/master', '1' ]
|
|
if (status) {
|
|
gitInfo.current = status[1];
|
|
gitInfo.tracking = status[2];
|
|
|
|
if (status[3]) {
|
|
// git fetch was already called before so `git status -sb` delivers already the behind number
|
|
gitInfo.behind = parseInt(status[3]);
|
|
gitInfo.isBehindInStatus = true;
|
|
}
|
|
}
|
|
|
|
return gitInfo;
|
|
}
|
|
|
|
async getRepoInfo (repo) {
|
|
const gitInfo = await this.getStatusInfo(repo);
|
|
|
|
if (!gitInfo || !gitInfo.current) {
|
|
return;
|
|
}
|
|
|
|
if (gitInfo.isBehindInStatus && (gitInfo.module !== "MagicMirror" || gitInfo.current !== "master")) {
|
|
return gitInfo;
|
|
}
|
|
|
|
const { stderr } = await this.execShell(`cd ${repo.folder} && git fetch -n --dry-run`);
|
|
|
|
// example output:
|
|
// From https://github.com/MagicMirrorOrg/MagicMirror
|
|
// e40ddd4..06389e3 develop -> origin/develop
|
|
// here the result is in stderr (this is a git default, don't ask why ...)
|
|
const matches = stderr.match(this.getRefRegex(gitInfo.current));
|
|
|
|
// this is the default if there was no match from "git fetch -n --dry-run".
|
|
// Its a fallback because if there was a real "git fetch", the above "git fetch -n --dry-run" would deliver nothing.
|
|
let refDiff = `${gitInfo.current}..origin/${gitInfo.current}`;
|
|
if (matches && matches[0]) {
|
|
refDiff = matches[0];
|
|
}
|
|
|
|
// get behind with refs
|
|
try {
|
|
const { stdout } = await this.execShell(`cd ${repo.folder} && git rev-list --ancestry-path --count ${refDiff}`);
|
|
gitInfo.behind = parseInt(stdout);
|
|
|
|
// for MagicMirror-Repo and "master" branch avoid getting notified when no tag is in refDiff
|
|
// so only releases are reported and we can change e.g. the README.md without sending notifications
|
|
if (gitInfo.behind > 0 && gitInfo.module === "MagicMirror" && gitInfo.current === "master") {
|
|
let tagList = "";
|
|
try {
|
|
const { stdout } = await this.execShell(`cd ${repo.folder} && git ls-remote -q --tags --refs`);
|
|
tagList = stdout.trim();
|
|
} catch (err) {
|
|
Log.error(`Failed to get tag list for ${repo.module}: ${err}`);
|
|
}
|
|
// check if tag is between commits and only report behind > 0 if so
|
|
try {
|
|
const { stdout } = await this.execShell(`cd ${repo.folder} && git rev-list --ancestry-path ${refDiff}`);
|
|
let cnt = 0;
|
|
for (const ref of stdout.trim().split("\n")) {
|
|
if (tagList.includes(ref)) cnt++; // tag found
|
|
}
|
|
if (cnt === 0) gitInfo.behind = 0;
|
|
} catch (err) {
|
|
Log.error(`Failed to get git revisions for ${repo.module}: ${err}`);
|
|
}
|
|
}
|
|
|
|
return gitInfo;
|
|
} catch (err) {
|
|
Log.error(`Failed to get git revisions for ${repo.module}: ${err}`);
|
|
}
|
|
}
|
|
|
|
async getRepos () {
|
|
this.gitResultList = [];
|
|
|
|
for (const repo of this.gitRepos) {
|
|
try {
|
|
const gitInfo = await this.getRepoInfo(repo);
|
|
|
|
if (gitInfo) {
|
|
this.gitResultList.push(gitInfo);
|
|
}
|
|
} catch (e) {
|
|
Log.error(`Failed to retrieve repo info for ${repo.module}: ${e}`);
|
|
}
|
|
}
|
|
|
|
return this.gitResultList;
|
|
}
|
|
|
|
async checkUpdates () {
|
|
var updates = [];
|
|
|
|
const allRepos = await this.gitResultList.map((module) => {
|
|
return new Promise((resolve) => {
|
|
if (module.behind > 0 && module.module !== "MagicMirror") {
|
|
Log.info(`Update found for module: ${module.module}`);
|
|
updates.push(module);
|
|
}
|
|
resolve(module);
|
|
});
|
|
});
|
|
await Promise.all(allRepos);
|
|
|
|
return updates;
|
|
}
|
|
}
|
|
|
|
module.exports = GitHelper;
|