From fb3145b2141c837cdc4cb4ab8f2868bbec2fb1c4 Mon Sep 17 00:00:00 2001 From: Alex <apuret@e-biz.fr> Date: Mon, 9 Nov 2020 17:14:13 +0100 Subject: [PATCH] feat: change way to name commit --- plugins/deadlock-extension/package-lock.json | 10 ++-- plugins/deadlock-extension/package.json | 4 +- plugins/deadlock-extension/src/gitMission.ts | 2 +- .../src/recorder/command-recorder.ts | 4 +- .../src/recorder/preStop.ts | 4 +- .../deadlock-extension/src/recorder/utils.ts | 12 +++-- test.js | 47 ------------------- 7 files changed, 21 insertions(+), 62 deletions(-) delete mode 100644 test.js diff --git a/plugins/deadlock-extension/package-lock.json b/plugins/deadlock-extension/package-lock.json index db1946e0..6f559476 100644 --- a/plugins/deadlock-extension/package-lock.json +++ b/plugins/deadlock-extension/package-lock.json @@ -343,6 +343,11 @@ "which": "^2.0.1" } }, + "date-fns": { + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.16.1.tgz", + "integrity": "sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ==" + }, "debug": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", @@ -1301,11 +1306,6 @@ "punycode": "^2.1.0" } }, - "uuid": { - "version": "8.3.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.1.tgz", - "integrity": "sha512-FOmRr+FmWEIG8uhZv6C2bTgEVXsHk08kE7mPlrBbEe+c3r9pjceVPgupIfNIhc4yx55H69OXANrUaSuu9eInKg==" - }, "v8-compile-cache": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz", diff --git a/plugins/deadlock-extension/package.json b/plugins/deadlock-extension/package.json index 6208de62..f5cdf38f 100644 --- a/plugins/deadlock-extension/package.json +++ b/plugins/deadlock-extension/package.json @@ -62,10 +62,10 @@ "dependencies": { "@types/marked": "^1.1.0", "async": "^3.2.0", + "date-fns": "^2.16.1", "keycloak-js": "^11.0.0", "marked": "^1.1.1", - "simple-git": "^2.21.0", - "uuid": "^8.3.1" + "simple-git": "^2.21.0" }, "devDependencies": { "@types/node": "^12.12.0", diff --git a/plugins/deadlock-extension/src/gitMission.ts b/plugins/deadlock-extension/src/gitMission.ts index 67f83737..87d95517 100644 --- a/plugins/deadlock-extension/src/gitMission.ts +++ b/plugins/deadlock-extension/src/gitMission.ts @@ -67,7 +67,7 @@ export default class GitMission { try { return (await this.git.remote([]) || '').replace(/(\r\n|\n|\r)/gm, ''); } catch (e) { - //ignore it, maybe the git repo does not exist + // ignore it, maybe the git repo does not exist } return ''; } diff --git a/plugins/deadlock-extension/src/recorder/command-recorder.ts b/plugins/deadlock-extension/src/recorder/command-recorder.ts index 82bc364e..23ade5a2 100644 --- a/plugins/deadlock-extension/src/recorder/command-recorder.ts +++ b/plugins/deadlock-extension/src/recorder/command-recorder.ts @@ -1,5 +1,5 @@ import GitMission from '../gitMission'; -import { error, commitAndPushCode } from './utils'; +import { error, commitAndPushCode, CommitFrom } from './utils'; const async = require("async"); // regex to match command line in ps aux @@ -50,7 +50,7 @@ export default class CommandRecorder { this.commandsInProgress.set(pid, new Command(pid, command)); try { - this.queue.push(async () => await commitAndPushCode(this.gitMission)); + this.queue.push(async () => await commitAndPushCode(this.gitMission, CommitFrom.Run)); } catch (e) { console.error('Cannot send user code to git'); console.error(e); diff --git a/plugins/deadlock-extension/src/recorder/preStop.ts b/plugins/deadlock-extension/src/recorder/preStop.ts index 9c1cf471..ce1fedcf 100644 --- a/plugins/deadlock-extension/src/recorder/preStop.ts +++ b/plugins/deadlock-extension/src/recorder/preStop.ts @@ -1,6 +1,6 @@ import UserConfigNode from "./userConfigNode"; import GitMission from "../gitMission"; -import { log, error, commitAndPushCode } from "./utils"; +import { log, error, commitAndPushCode, CommitFrom } from "./utils"; import { PROJECT_SRC_PATH, PROJECT_THEIA_PATH } from "../config.prod"; const util = require("util"); const exec = util.promisify(require("child_process").exec); @@ -39,7 +39,7 @@ async function containsDiff() { await userConfig.init(); const gitMission = await new GitMission(userConfig).init(); if (await containsDiff()) { - await commitAndPushCode(gitMission); + await commitAndPushCode(gitMission, CommitFrom.Auto); } } catch (e) { error("Cannot push user code at the end.."); diff --git a/plugins/deadlock-extension/src/recorder/utils.ts b/plugins/deadlock-extension/src/recorder/utils.ts index c3ff7625..dfa63343 100644 --- a/plugins/deadlock-extension/src/recorder/utils.ts +++ b/plugins/deadlock-extension/src/recorder/utils.ts @@ -1,7 +1,7 @@ import GitMission from "../gitMission"; import { PROJECT_SRC_PATH, PROJECT_THEIA_PATH } from "../config.prod"; import { execSync } from "child_process"; -import { v4 as uuid } from 'uuid'; +import { format } from 'date-fns'; const util = require('util'); const unlink = util.promisify(require('fs').unlink); @@ -48,15 +48,21 @@ export async function clearFilesExceptGit(path) { }); } -export async function commitAndPushCode(gitMission: GitMission) { +export enum CommitFrom { + Run = 'Run', + Auto = 'Auto' +} + +export async function commitAndPushCode(gitMission: GitMission, from: CommitFrom) { try { log(`Commit & push`); await clearFilesExceptGit(PROJECT_SRC_PATH); execSync(`rsync -r --exclude .git --exclude npm --exclude target ${PROJECT_THEIA_PATH}/* ${PROJECT_SRC_PATH} && cp ${Path.join(__dirname, '.gitignore')} ${PROJECT_SRC_PATH} && chown -R root:root /project`); + const currentDate = format(new Date(), "HH'H'mm'_'dd/LL/y"); await gitMission.addAll(); - await gitMission.commit(uuid()); + await gitMission.commit(currentDate); await gitMission.push(); log(`Commit & push done.`) } catch (e) { diff --git a/test.js b/test.js deleted file mode 100644 index f1750e4f..00000000 --- a/test.js +++ /dev/null @@ -1,47 +0,0 @@ -const child = require('child_process'); -// const watch = child.spawn('watch', ['-n', '0.5', 'ps aux']); - -const regexPsCommand = /(alex).+?([\d]+).+?([\d]+\:[\d]+).+?([\d+]\:[\d+]+) (.+)/ - -setInterval(() => { - const spawn = child.spawn('ps', ['aux']); - - spawn.stdout.setEncoding('utf8'); - spawn.stdout.on('data', function(data) { - const lines = data.toString().split('\n'); - - child.spawn('node commit.js'); - for (line of lines) { - const lineMatcher = line.match(regexPsCommand); - if (lineMatcher && lineMatcher.length > 4) { - console.log(lineMatcher[5]); - } - } - }); -}, 500); - - -// var execute = function(callback) { -// child.exec('ls', {maxBuffer: 1024 * 500}, function(error, stdout, stderr){ -// console.log('error', error); -// console.log('stdout', stdout); -// console.log('stderr', stderr); -// }); -// }; - - -// const regexTopCommand = /([\d]+) (theia).+?([\d]+\.[\d]+) +([\d]+\.[\d]+) +([\d]+\:[\d]+\.[\d]+) (.+)/ -// watch.stdout.addListener('data', (data) => { -// try { -// console.log('================='); -// console.log(data.toString()); -// } catch (e) { -// //catch anything to avoid the program exit -// console.error(e); -// } -// }); - -// watch.on('exit', function (code) { -// console.error(`exit command recorder ${code}`) -// process.exit(code); -// }); -- GitLab