diff --git a/bin/cml/comment/create.js b/bin/cml/comment/create.js index a965311cf..ff6bb15fe 100644 --- a/bin/cml/comment/create.js +++ b/bin/cml/comment/create.js @@ -43,7 +43,8 @@ exports.options = kebabcaseKeys({ update: { type: 'boolean', description: - 'Update the last CML comment (if any) instead of creating a new one' + 'Update the last CML comment (if any) instead of creating a new one', + hidden: true }, rmWatermark: { type: 'boolean', diff --git a/bin/cml/comment/create.test.js b/bin/cml/comment/create.test.js index 9b3de5300..8ed29a39a 100644 --- a/bin/cml/comment/create.test.js +++ b/bin/cml/comment/create.test.js @@ -38,8 +38,6 @@ describe('Comment integration tests', () => { --native Uses driver's native capabilities to upload assets instead of CML's storage; not available on GitHub [boolean] - --update Update the last CML comment (if any) instead of - creating a new one [boolean] --rm-watermark Avoid watermark; CML needs a watermark to be able to distinguish CML comments from others [boolean]" `); diff --git a/bin/cml/comment/update.js b/bin/cml/comment/update.js new file mode 100644 index 000000000..adfdb6483 --- /dev/null +++ b/bin/cml/comment/update.js @@ -0,0 +1,10 @@ +const { builder, handler } = require('./create'); + +exports.command = 'update '; +exports.description = 'Update a comment'; + +exports.handler = async (opts) => { + await handler({ ...opts, update: true }); +}; + +exports.builder = builder; diff --git a/src/cml.js b/src/cml.js index a1f22b255..505c1d749 100755 --- a/src/cml.js +++ b/src/cml.js @@ -229,20 +229,26 @@ class CML { } if (watch) { - let lock; + let first = true; + let lock = false; watcher.add(triggerFile || markdownFile); watcher.on('all', async (event, path) => { if (lock) return; lock = true; try { winston.info(`watcher event: ${event} ${path}`); - await this.commentCreate({ ...opts, update: true, watch: false }); + await this.commentCreate({ + ...opts, + update: update || !first, + watch: false + }); if (event !== 'unlink' && path === triggerFile) { await fs.unlink(triggerFile); } } catch (err) { winston.warn(err); } + first = false; lock = false; }); winston.info('watching for file changes...');