1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-02 12:47:41 +02:00

Plugin Repo: Prevent faulty packages from generating commits on each check

This commit is contained in:
Laurent Cozic 2021-01-23 16:18:59 +00:00
parent 63559ac8b9
commit 0cbecabff2
6 changed files with 107 additions and 8 deletions

View File

@ -1458,6 +1458,15 @@ packages/plugin-repo-cli/lib/checkIfPluginCanBeAdded.js.map
packages/plugin-repo-cli/lib/checkIfPluginCanBeAdded.test.d.ts
packages/plugin-repo-cli/lib/checkIfPluginCanBeAdded.test.js
packages/plugin-repo-cli/lib/checkIfPluginCanBeAdded.test.js.map
packages/plugin-repo-cli/lib/errorsHaveChanged.d.ts
packages/plugin-repo-cli/lib/errorsHaveChanged.js
packages/plugin-repo-cli/lib/errorsHaveChanged.js.map
packages/plugin-repo-cli/lib/errorsHaveChanged.test.d.ts
packages/plugin-repo-cli/lib/errorsHaveChanged.test.js
packages/plugin-repo-cli/lib/errorsHaveChanged.test.js.map
packages/plugin-repo-cli/lib/types.d.ts
packages/plugin-repo-cli/lib/types.js
packages/plugin-repo-cli/lib/types.js.map
packages/plugin-repo-cli/lib/updateReadme.d.ts
packages/plugin-repo-cli/lib/updateReadme.js
packages/plugin-repo-cli/lib/updateReadme.js.map

9
.gitignore vendored
View File

@ -1446,6 +1446,15 @@ packages/plugin-repo-cli/lib/checkIfPluginCanBeAdded.js.map
packages/plugin-repo-cli/lib/checkIfPluginCanBeAdded.test.d.ts
packages/plugin-repo-cli/lib/checkIfPluginCanBeAdded.test.js
packages/plugin-repo-cli/lib/checkIfPluginCanBeAdded.test.js.map
packages/plugin-repo-cli/lib/errorsHaveChanged.d.ts
packages/plugin-repo-cli/lib/errorsHaveChanged.js
packages/plugin-repo-cli/lib/errorsHaveChanged.js.map
packages/plugin-repo-cli/lib/errorsHaveChanged.test.d.ts
packages/plugin-repo-cli/lib/errorsHaveChanged.test.js
packages/plugin-repo-cli/lib/errorsHaveChanged.test.js.map
packages/plugin-repo-cli/lib/types.d.ts
packages/plugin-repo-cli/lib/types.js
packages/plugin-repo-cli/lib/types.js.map
packages/plugin-repo-cli/lib/updateReadme.d.ts
packages/plugin-repo-cli/lib/updateReadme.js
packages/plugin-repo-cli/lib/updateReadme.js.map

View File

@ -7,12 +7,8 @@ import validatePluginId from '@joplin/lib/services/plugins/utils/validatePluginI
import { execCommand2, resolveRelativePathWithinDir, gitPullTry, gitRepoCleanTry, gitRepoClean } from '@joplin/tools/tool-utils.js';
import checkIfPluginCanBeAdded from './lib/checkIfPluginCanBeAdded';
import updateReadme from './lib/updateReadme';
interface NpmPackage {
name: string;
version: string;
date: Date;
}
import { ImportErrors, NpmPackage } from './lib/types';
import errorsHaveChanged from './lib/errorsHaveChanged';
function stripOffPackageOrg(name: string): string {
const n = name.split('/');
@ -167,7 +163,7 @@ async function processNpmPackage(npmPackage: NpmPackage, repoDir: string) {
chdir(packageTempDir);
await execCommand2('npm init --yes --loglevel silent', { quiet: true });
const errors: any = await readJsonFile(errorsPath, {});
const errors: ImportErrors = await readJsonFile(errorsPath, {});
delete errors[npmPackage.name];
let actionType: ProcessingActionType = ProcessingActionType.Update;
@ -191,7 +187,9 @@ async function processNpmPackage(npmPackage: NpmPackage, repoDir: string) {
}
if (Object.keys(errors).length) {
if (errorsHaveChanged(await readJsonFile(errorsPath, {}), errors)) {
await fs.writeFile(errorsPath, JSON.stringify(errors, null, '\t'), 'utf8');
}
} else {
await fs.remove(errorsPath);
}

View File

@ -0,0 +1,65 @@
import errorsHaveChanged from './errorsHaveChanged';
describe('errorsHaveChanged', () => {
test('should tell if an errors object has changed', () => {
const testCases = [
[
{
'one': '111',
'two': '222',
},
{
'two': '222',
'one': '111',
},
false,
],
[
{
'one': '111',
'two': '222',
},
{
'one': '111',
'two': '222',
},
false,
],
[
{
'one': '111',
'two': '222',
},
{
'one': '111',
},
true,
],
[
{
'one': '111',
'two': '222',
},
{
'one': '222',
'two': '111',
},
true,
],
[
{},
{},
false,
],
];
for (const t of testCases) {
const [oldErrors, newErrors, expected] = t;
const result = errorsHaveChanged(oldErrors, newErrors);
expect(result).toBe(expected);
}
});
});

View File

@ -0,0 +1,11 @@
import { ImportErrors } from './types';
export default function(previousErrors: ImportErrors, newErrors: ImportErrors): boolean {
if (Object.keys(previousErrors).length !== Object.keys(newErrors).length) return true;
for (const packageName of Object.keys(previousErrors)) {
if (newErrors[packageName] !== previousErrors[packageName]) return true;
}
return false;
}

View File

@ -0,0 +1,7 @@
export type ImportErrors = Record<string, string>;
export interface NpmPackage {
name: string;
version: string;
date: Date;
}