Updates notification (#3119)

Hi,

Like some default modules, I propose to send an `UPDATES` notification
in an array with the git information of these modules

This allows developers to create their own auto-update system (which
I've been using in my case since 3 years, with automatic things)

Of course, for security reasons `MagicMirror` is excluded

---------

Co-authored-by: bugsounet <bugsounet@bugsounet.fr>
This commit is contained in:
Bugsounet - Cédric
2023-06-08 22:41:48 +02:00
committed by GitHub
parent b7371538bc
commit e985e99036
4 changed files with 36 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ const BASE_DIR = path.normalize(`${__dirname}/../../../`);
class GitHelper {
constructor() {
this.gitRepos = [];
this.gitResultList = [];
}
getRefRegex(branch) {
@@ -171,21 +172,38 @@ class GitHelper {
}
async getRepos() {
const gitResultList = [];
this.gitResultList = [];
for (const repo of this.gitRepos) {
try {
const gitInfo = await this.getRepoInfo(repo);
if (gitInfo) {
gitResultList.push(gitInfo);
this.gitResultList.push(gitInfo);
}
} catch (e) {
Log.error(`Failed to retrieve repo info for ${repo.module}: ${e}`);
}
}
return gitResultList;
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;
}
}