From e01ca12368677e1f8f72f97c4170b386cb250fb8 Mon Sep 17 00:00:00 2001
From: Joyee Cheung <joyeec9h3@gmail.com>
Date: Fri, 7 Oct 2022 18:12:24 +0800
Subject: [PATCH 1/5] feat: add --since option to ncu-ci (#649)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* feat: add --since option to ncu-ci

Co-authored-by: Michaƫl Zasso <targos@protonmail.com>
---
 bin/ncu-ci.js      | 23 ++++++++++++++++++++++-
 lib/ci/ci_utils.js |  9 ++++++---
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/bin/ncu-ci.js b/bin/ncu-ci.js
index 5e865927..d0fd8bf1 100755
--- a/bin/ncu-ci.js
+++ b/bin/ncu-ci.js
@@ -86,6 +86,19 @@ const args = yargs(hideBin(process.argv))
         .option('limit', {
           default: 99,
           describe: 'Maximum number of CIs to get data from'
+        })
+        .option('since <date>', {
+          type: 'string',
+          describe: 'Time since when the CI results should be queried'
+        }).check(argv => {
+          try {
+            // eslint-disable-next-line no-new
+            new Date(argv.since);
+          } catch {
+            throw new Error('--since <date> should be string that can ' +
+                            'be parsed by new Date()');
+          }
+          return true;
         });
     },
     handler
@@ -421,7 +434,12 @@ class WalkCommand extends CICommand {
 
   async initialize() {
     const ciType = commandToType[this.argv.type];
-    const builds = await listBuilds(this.cli, this.request, ciType);
+    const since = this.argv.since ? new Date(this.argv.since) : undefined;
+    const builds = await listBuilds(this.cli, this.request, ciType, since);
+    if (builds.count === 0) {
+      this.cli.log('No applicable builds found.');
+      return;
+    }
     this.queue.push({ type: 'health', ciType, builds });
     for (const build of builds.failed.slice(0, this.argv.limit)) {
       this.queue.push(build);
@@ -430,6 +448,9 @@ class WalkCommand extends CICommand {
 
   async aggregate() {
     const { argv, cli } = this;
+    if (this.queue.length === 0) {
+      return;
+    }
     const aggregator = new FailureAggregator(cli, this.json);
     this.json = aggregator.aggregate();
     cli.log('');
diff --git a/lib/ci/ci_utils.js b/lib/ci/ci_utils.js
index 79fa8a87..a442ff2e 100644
--- a/lib/ci/ci_utils.js
+++ b/lib/ci/ci_utils.js
@@ -50,16 +50,19 @@ function filterBuild(builds, type) {
     .map(build => parseJobFromURL(build.url));
 }
 
-export async function listBuilds(cli, request, type) {
+export async function listBuilds(cli, request, type, since) {
   // assert(type === COMMIT || type === PR)
   const { jobName } = CI_TYPES.get(type);
-  const tree = 'builds[url,result]';
+  const tree = 'builds[url,result,timestamp]';
   const url = `https://${CI_DOMAIN}/job/${jobName}/api/json?tree=${qs.escape(tree)}`;
 
   cli.startSpinner(`Querying ${url}`);
 
   const result = await request.json(url);
-  const builds = result.builds;
+  let builds = result.builds;
+  if (since) {
+    builds = builds.filter(build => build.timestamp > since);
+  }
   const failed = filterBuild(builds, statusType.FAILURE);
   const aborted = filterBuild(builds, statusType.ABORTED);
   const pending = filterBuild(builds, null);

From c4ab7f5904e793ddbc23122e3724efd6ad8c9b40 Mon Sep 17 00:00:00 2001
From: Feng Yu <F3n67u@outlook.com>
Date: Sun, 9 Oct 2022 22:23:22 +0800
Subject: [PATCH 2/5] docs: fix typo in git-node.md (#648)

---
 docs/git-node.md | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/docs/git-node.md b/docs/git-node.md
index c8e4d5fa..6b22205f 100644
--- a/docs/git-node.md
+++ b/docs/git-node.md
@@ -166,8 +166,8 @@ Options:
 
 ### Optional Settings
 
-The same Settings used by 
-[`git node metadata`](#git-node-metadata-optional-settings) are also used by 
+The same Settings used by
+[`git node metadata`](#git-node-metadata-optional-settings) are also used by
 `git node land`.
 
 ## `git node backport`
@@ -334,7 +334,7 @@ $ brew install gpatch
 
 And make sure `which patch` points to `/usr/local/bin/patch` installed by
 homebrew instead of `/usr/bin/patch` that comes with the system (e.g. by
-modifying yoru `PATH` environment variable).
+modifying your `PATH` environment variable).
 
 ### `git node v8 major`
 

From 4e59a647a1ffd87b79ad953936d20de495505bd0 Mon Sep 17 00:00:00 2001
From: Joyee Cheung <joyeec9h3@gmail.com>
Date: Wed, 12 Oct 2022 19:44:36 +0200
Subject: [PATCH 3/5] fix: only parse commit messages during git node backport
 analysis (#651)

Previously we parse the entire commit, including the diff, which
can result in ENOBUFS errors. Adding `-s` option to the `git show`
command would eliminate the commit body in the output, which
we don't need, so the error can be less likely to happen during
commit message analysis.
---
 lib/backport_session.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/backport_session.js b/lib/backport_session.js
index f45a86f8..849f787c 100644
--- a/lib/backport_session.js
+++ b/lib/backport_session.js
@@ -39,7 +39,7 @@ export default class BackportSession extends Session {
 
   getCommitMessage(rev) {
     return runSync('git',
-      ['show', '--format=%B', rev]
+      ['show', '--format=%B', '-s', rev]
     ).trim();
   }
 

From 046bc0dbea44dafdb42f92bc1006d7cdd7a5f286 Mon Sep 17 00:00:00 2001
From: gengjiawen <technicalcute@gmail.com>
Date: Thu, 13 Oct 2022 12:37:53 +0800
Subject: [PATCH 4/5] feat: add auto run v8 ci

---
 .npmrc                     |  1 +
 lib/ci/run_ci.js           | 40 ++++++++++++++++++++++++++++++++++++++
 test/unit/ci_start.test.js |  9 +++++++++
 3 files changed, 50 insertions(+)

diff --git a/.npmrc b/.npmrc
index 43c97e71..62a81f06 100644
--- a/.npmrc
+++ b/.npmrc
@@ -1 +1,2 @@
 package-lock=false
+auto-install-peers=true
diff --git a/lib/ci/run_ci.js b/lib/ci/run_ci.js
index beead3dc..74317908 100644
--- a/lib/ci/run_ci.js
+++ b/lib/ci/run_ci.js
@@ -5,11 +5,16 @@ import {
   CI_TYPES,
   CI_TYPES_KEYS
 } from './ci_type_parser.js';
+import PRData from '../pr_data.js';
+import { debuglog } from '../verbosity.js';
 
 export const CI_CRUMB_URL = `https://${CI_DOMAIN}/crumbIssuer/api/json`;
 const CI_PR_NAME = CI_TYPES.get(CI_TYPES_KEYS.PR).jobName;
 export const CI_PR_URL = `https://${CI_DOMAIN}/job/${CI_PR_NAME}/build`;
 
+const CI_V8_NAME = CI_TYPES.get(CI_TYPES_KEYS.V8).jobName;
+export const CI_V8_URL = `https://${CI_DOMAIN}/job/${CI_V8_NAME}/build`;
+
 export class RunPRJob {
   constructor(cli, request, owner, repo, prid) {
     this.cli = cli;
@@ -17,6 +22,7 @@ export class RunPRJob {
     this.owner = owner;
     this.repo = repo;
     this.prid = prid;
+    this.prData = new PRData({ prid, owner, repo }, cli, request);
   }
 
   async getCrumb() {
@@ -43,6 +49,18 @@ export class RunPRJob {
     return payload;
   }
 
+  get v8Payload() {
+    const payload = new FormData();
+    payload.append('json', JSON.stringify({
+      parameter: [
+        { name: 'GITHUB_ORG', value: this.owner },
+        { name: 'REPO_NAME', value: this.repo },
+        { name: 'GIT_REMOTE_REF', value: `refs/pull/${this.prid}/head` }
+      ]
+    }));
+    return payload;
+  }
+
   async start() {
     const { cli } = this;
     cli.startSpinner('Validating Jenkins credentials');
@@ -71,7 +89,29 @@ export class RunPRJob {
         return false;
       }
       cli.stopSpinner('PR CI job successfully started');
+
+      // check if the job need a v8 build and trigger it
+      await this.prData.getPR();
+      const labels = this.prData.pr.labels;
+      if (labels.nodes.map(i => i.name).includes('v8 engine')) {
+        cli.startSpinner('Starting V8 CI job');
+        const response = await this.request.fetch(CI_V8_URL, {
+          method: 'POST',
+          headers: {
+            'Jenkins-Crumb': crumb
+          },
+          body: this.v8Payload
+        });
+        if (response.status !== 201) {
+          cli.stopSpinner(
+            `Failed to start V8 CI: ${response.status} ${response.statusText}`,
+            this.cli.SPINNER_STATUS.FAILED);
+          return false;
+        }
+        cli.stopSpinner('V8 CI job successfully started');
+      }
     } catch (err) {
+      debuglog(err);
       cli.stopSpinner('Failed to start CI', this.cli.SPINNER_STATUS.FAILED);
       return false;
     }
diff --git a/test/unit/ci_start.test.js b/test/unit/ci_start.test.js
index cac43f62..deb9d46c 100644
--- a/test/unit/ci_start.test.js
+++ b/test/unit/ci_start.test.js
@@ -67,6 +67,15 @@ describe('Jenkins', () => {
     const cli = new TestCLI();
 
     const request = {
+      gql: sinon.stub().returns({
+        repository: {
+          pullRequest: {
+            labels: {
+              nodes: []
+            }
+          }
+        }
+      }),
       fetch: sinon.stub()
         .callsFake((url, { method, headers, body }) => {
           assert.strictEqual(url, CI_PR_URL);

From 04d513d9092ebf46d9435407422f19146e7eda96 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Sat, 22 Oct 2022 11:33:21 +0200
Subject: [PATCH 5/5] chore(main): release 2.1.0 (#650)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
---
 CHANGELOG.md | 13 +++++++++++++
 package.json |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 779bd56d..8d860e35 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,18 @@
 # Changelog
 
+## [2.1.0](https://github.com/nodejs/node-core-utils/compare/v2.0.1...v2.1.0) (2022-10-22)
+
+
+### Features
+
+* add --since option to ncu-ci ([#649](https://github.com/nodejs/node-core-utils/issues/649)) ([e01ca12](https://github.com/nodejs/node-core-utils/commit/e01ca12368677e1f8f72f97c4170b386cb250fb8))
+* add auto run v8 ci ([046bc0d](https://github.com/nodejs/node-core-utils/commit/046bc0dbea44dafdb42f92bc1006d7cdd7a5f286))
+
+
+### Bug Fixes
+
+* only parse commit messages during git node backport analysis ([#651](https://github.com/nodejs/node-core-utils/issues/651)) ([4e59a64](https://github.com/nodejs/node-core-utils/commit/4e59a647a1ffd87b79ad953936d20de495505bd0))
+
 ## [2.0.1](https://github.com/nodejs/node-core-utils/compare/v2.0.0...v2.0.1) (2022-07-31)
 
 
diff --git a/package.json b/package.json
index a4b3f5f4..182dd40b 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "node-core-utils",
-  "version": "2.0.1",
+  "version": "2.1.0",
   "description": "Utilities for Node.js core collaborators",
   "type": "module",
   "bin": {