summaryrefslogtreecommitdiffstats
path: root/sshTranslator.js
diff options
context:
space:
mode:
authorDaniel Smith <daniel.smith@qt.io>2024-10-09 10:10:26 +0200
committerDaniel Smith <daniel.smith@qt.io>2025-05-29 10:11:33 +0200
commit5186dcbcfa21d205ea5cc08aa49824ecd8ea4dee (patch)
treee4dba1689a0d0dd0f14a8968600b020ba2c78448 /sshTranslator.js
Initial commit of the Qt CI Analysis BotHEADdev
This bot performs analysis of CI integration failures, posting analysis and recommendations to the Gerrit change under test. Change-Id: Ie54061e63977f1e73e2401c399f3da4422b0c470
Diffstat (limited to 'sshTranslator.js')
-rw-r--r--sshTranslator.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/sshTranslator.js b/sshTranslator.js
new file mode 100644
index 0000000..c1504e2
--- /dev/null
+++ b/sshTranslator.js
@@ -0,0 +1,70 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+const http = require('http');
+const { spawn } = require('child_process');
+const EventEmitter = require('events');
+
+class SSHForwarder extends EventEmitter {
+ constructor() {
+ super();
+ this.sshProcess = null;
+ }
+
+ start() {
+ this.sshProcess = spawn('ssh', [
+ 'codereview.qt-project.org',
+ 'gerrit',
+ 'stream-events',
+ '-s',
+ 'change-integration-fail',
+ '-s',
+ 'comment-added',
+ ]);
+
+ this.sshProcess.stdout.on('data', (data) => {
+ try {
+ console.log(data.toString());
+ const jsonData = data.toString();
+ this.forwardEvent(jsonData);
+ } catch (err) {
+ console.error('Error processing event:', err);
+ }
+ });
+
+ this.sshProcess.stderr.on('data', (data) => {
+ console.error(`SSH stderr: ${data}`);
+ });
+
+ this.sshProcess.on('close', (code) => {
+ console.log(`SSH process exited with code ${code}`);
+ setTimeout(() => this.start(), 5000); // Reconnect after 5 seconds
+ });
+ }
+
+ forwardEvent(eventData) {
+ const postData = eventData;
+
+ const req = http.request({
+ hostname: 'localhost',
+ port: 8092,
+ path: '/',
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Content-Length': postData.length
+ }
+ });
+
+ req.on('error', (err) => {
+ console.error('Forwarding error:', err);
+ });
+
+ req.write(postData);
+ req.end();
+ }
+}
+
+// Create and start forwarder
+const forwarder = new SSHForwarder();
+forwarder.start();