From a2b21ebd2ba7a73b3982b7741645c4938c1826d8 Mon Sep 17 00:00:00 2001 From: DavidGOrtega Date: Fri, 29 Oct 2021 14:47:49 +0200 Subject: [PATCH] Fix send comment pr error without PR (#791) * Fix send comment pr error without PR * revert #790 * add info messages Co-authored-by: Casper da Costa-Luis --- src/cml.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cml.js b/src/cml.js index 4a1d14182..10576bef0 100755 --- a/src/cml.js +++ b/src/cml.js @@ -82,13 +82,9 @@ class CML { this.driver = driver || inferDriver({ repo: this.repo }); } - async headSha() { - return exec(`git rev-parse HEAD`); - } - async triggerSha() { const { sha } = getDriver(this); - return sha || (await this.headSha()); + return sha || (await exec(`git rev-parse HEAD`)); } async branch() { @@ -99,7 +95,7 @@ class CML { async commentCreate(opts = {}) { const { report: userReport, - commitSha = await this.headSha(), + commitSha = await this.triggerSha(), rmWatermark, update, pr @@ -125,8 +121,15 @@ class CML { if (pr || this.driver === 'bitbucket') { let commentUrl; + if ( + (await exec(`git rev-parse ${commitSha}`)) !== + (await exec('git rev-parse HEAD')) + ) + winston.info( + `Looking for PR associated with --commit-sha="${commitSha}".\nSee https://cml.dev/doc/ref/send-comment.` + ); const longReport = `${commitSha.substr(0, 7)}\n\n${report}`; - const [commitPr] = await drv.commitPrs({ commitSha }); + const [commitPr = {}] = await drv.commitPrs({ commitSha }); const { url } = commitPr; if (!url) throw new Error(`PR for commit sha "${commitSha}" not found`);