aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Smith <[email protected]>2024-10-18 16:16:13 +0200
committerDaniel Smith <[email protected]>2025-02-24 10:53:33 +0000
commiteb3adfa163fb5134c897b0bce214ee5641a2af03 (patch)
treea5dbe3f5caaf346a602df1aed91b7478c14d5760
parentca936d04a499b24e53c3ef144deb9a92628fa889 (diff)
Fix calls to loggerHEADdev
Change-Id: I54b21d67d8338a120f933fd102d2e5ae0a88e55f Reviewed-by: Daniel Smith <[email protected]>
-rw-r--r--README.md7
-rw-r--r--gerritRESTTools.js104
-rw-r--r--logger.js3
-rw-r--r--qt-submodule-update-watcher.service15
-rw-r--r--submodule_update_watcher.js144
5 files changed, 133 insertions, 140 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..10f72a5
--- /dev/null
+++ b/README.md
@@ -0,0 +1,7 @@
+This bot works in tadem with a Jenkins instance running the Submodule Update Bot.
+
+It listens for incoming events from gerrit in order to trigger jobs
+in the jenkins instance, and receives requests from Microsoft Teams
+button clicks on messages posted by the Submodule Update Bot.
+
+See config.json for configuration requirements.
diff --git a/gerritRESTTools.js b/gerritRESTTools.js
index e3c1414..d844a9d 100644
--- a/gerritRESTTools.js
+++ b/gerritRESTTools.js
@@ -1,5 +1,5 @@
// /* eslint-disable no-unused-vars */
-// Copyright (C) 2020 The Qt Company Ltd.
+// Copyright (C) 2024 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
@@ -14,7 +14,7 @@ const config = require("./config.json");
axiosRetry(axios, {
retries: 3,
// Random delay in ms between 1 and 6 sec. Helps reduce load on gerrit.
- retryDelay: function() {Math.floor(Math.random() * 5 * 1000) + 1},
+ retryDelay: function () { Math.floor(Math.random() * 5 * 1000) + 1 },
shouldResetTimeout: true,
retryCondition: (error) => {
let status = error.response.status;
@@ -70,36 +70,33 @@ function trimResponse(response) {
// Post a comment to the change on the latest revision.
exports.postGerritComment = postGerritComment;
function postGerritComment(
- parentUuid, fullChangeID, revision, message, reviewers,
+ fullChangeID, revision, message, reviewers,
notifyScope, customAuth, callback
) {
function _postComment() {
- let url = `${gerritBaseURL("changes")}/${fullChangeID}/revisions/${
- revision || "current"}/review`;
+ let url = `${gerritBaseURL("changes")}/${fullChangeID}/revisions/${revision || "current"}/review`;
let data = { message: message, notify: notifyScope || "OWNER_REVIEWERS" };
if (reviewers) {
// format reviewers as a list of ReviewInput entities
data.reviewers = reviewers.map((reviewer) => { return { reviewer: reviewer }; });
}
- logger.log(
+ logger.info(
`POST request to: ${url}\nRequest Body: ${safeJsonStringify(data)}`,
- "debug", parentUuid
);
axios({ method: "post", url: url, data: data, auth: customAuth || gerritAuth })
.then(function (response) {
- logger.log(`Posted comment "${message}" to change "${fullChangeID}"`, "info", parentUuid);
+ logger.info(`Posted comment "${message}" to change "${fullChangeID}"`);
callback(true, undefined);
})
.catch(function (error) {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
- logger.log(
- `An error occurred in POST (gerrit comment) to "${url}". Error ${
- error.response.status}: ${error.response.data}`,
- "error", parentUuid
+ logger.info(
+ `An error occurred in POST (gerrit comment) to "${url}". Error ${error.response.status}: ${error.response.data}`,
+
);
callback(false, error.response);
} else if (error.request) {
@@ -107,9 +104,9 @@ function postGerritComment(
callback(false, "retry");
} else {
// Something happened in setting up the request that triggered an Error
- logger.log(
+ logger.info(
`Error in HTTP request while posting comment. Error: ${safeJsonStringify(error)}`,
- "error", parentUuid
+
);
callback(false, error.message);
}
@@ -118,7 +115,7 @@ function postGerritComment(
// Query the change first to see if we've posted the same comment on the current revision before
const message_url = `${gerritBaseURL("changes")}/${fullChangeID}/messages`;
- logger.log(`GET request to: ${message_url}`, "debug", parentUuid);
+ logger.info(`GET request to: ${message_url}`);
axios({ method: "get", url: message_url, auth: customAuth || gerritAuth })
.then(function (response) {
let parsedResponse = JSON.parse(trimResponse(response.data));
@@ -135,9 +132,8 @@ function postGerritComment(
// Then iterate and check for message in the current patchset.
for (let i = messages.length - 1; i >= 0; i--) {
if (messages[i].includes(message) && messages[i].includes(`Patch Set ${patchset}:`)) {
- logger.log(
- `Comment "${message}" already posted on patchset ${patchset} of ${fullChangeID}`,
- "verbose", parentUuid
+ logger.info(
+ `Comment "${message}" already posted on patchset ${patchset} of ${fullChangeID}`
);
callback(true, undefined);
return;
@@ -150,16 +146,16 @@ function postGerritComment(
// Query gerrit for a change and return it along with the current revision if it exists.
exports.queryChange = queryChange;
-function queryChange(parentUuid, fullChangeID, fields, customAuth, callback) {
+function queryChange(fullChangeID, fields, customAuth, callback) {
let url = `${gerritBaseURL("changes")}/${fullChangeID}/?o=CURRENT_COMMIT&o=CURRENT_REVISION`;
// Tack on any additional fields requested
if (fields)
fields.forEach((field) => url = `${url}&o=${field}`);
- logger.log(`Querying gerrit for ${url}`, "debug", parentUuid);
+ logger.info(`Querying gerrit for ${url}`);
axios.get(url, { auth: customAuth || gerritAuth })
.then(function (response) {
// Execute callback and return the list of changes
- logger.log(`Raw response: ${response.data}`, "debug", parentUuid);
+ logger.info(`Raw response: ${response.data}`);
callback(true, JSON.parse(trimResponse(response.data)));
})
.catch(function (error) {
@@ -171,10 +167,9 @@ function queryChange(parentUuid, fullChangeID, fields, customAuth, callback) {
callback(false, { statusCode: 404 });
} else {
// Some other error was returned
- logger.log(
- `An error occurred in GET "${url}". Error ${error.response.status}: ${
- error.response.data}`,
- "error", parentUuid
+ logger.info(
+ `An error occurred in GET "${url}". Error ${error.response.status}: ${error.response.data}`,
+
);
callback(false, { statusCode: error.response.status, statusDetail: error.response.data });
}
@@ -183,9 +178,9 @@ function queryChange(parentUuid, fullChangeID, fields, customAuth, callback) {
callback(false, "retry");
} else {
// Something happened in setting up the request that triggered an Error
- logger.log(
+ logger.info(
`Error in HTTP request while trying to query ${fullChangeID}. ${error}`,
- "error", parentUuid
+
);
callback(false, error.message);
}
@@ -194,36 +189,34 @@ function queryChange(parentUuid, fullChangeID, fields, customAuth, callback) {
// Add a user to the attention set of a change
exports.addToAttentionSet = addToAttentionSet;
-function addToAttentionSet(parentUuid, changeJSON, user, reason, customAuth, callback) {
+function addToAttentionSet(changeJSON, user, reason, customAuth, callback) {
let project = changeJSON.project.name ? changeJSON.project.name : changeJSON.project;
checkAccessRights(
- parentUuid, project, changeJSON.branch || changeJSON.change.branch,
+ project, changeJSON.branch || changeJSON.change.branch,
user, "push", customAuth || gerritAuth,
function (success, data) {
if (!success) {
let msg = `User "${user}" cannot push to ${project}:${changeJSON.branch}.`
- logger.log(msg, "warn", parentUuid);
+ logger.info(msg);
callback(false, msg);
let botAssignee = envOrConfig("GERRIT_USER");
if (botAssignee && user != botAssignee) {
- logger.log(`Falling back to GERRIT_USER (${botAssignee}) as assignee...`);
+ logger.info(`Falling back to GERRIT_USER (${botAssignee}) as assignee...`);
addToAttentionSet(
- parentUuid, changeJSON, botAssignee, "fallback to bot", customAuth,
- function () {}
+ changeJSON, botAssignee, "fallback to bot", customAuth,
+ function () { }
);
}
} else {
let url = `${gerritBaseURL("changes")}/${changeJSON.fullChangeID || changeJSON.id}/attention`;
let data = { user: user, "reason": reason || "Update Attention Set" };
- logger.log(
- `POST request to: ${url}\nRequest Body: ${safeJsonStringify(data)}`,
- "debug", parentUuid
+ logger.info(
+ `POST request to: ${url}\nRequest Body: ${safeJsonStringify(data)}`
);
axios({ method: "POST", url: url, data: data, auth: customAuth || gerritAuth })
.then(function (response) {
- logger.log(
- `Added Attention Set user: "${user}" on "${changeJSON.fullChangeID || changeJSON.id}"`,
- "info", parentUuid
+ logger.info(
+ `Added Attention Set user: "${user}" on "${changeJSON.fullChangeID || changeJSON.id}"`
);
callback(true, undefined);
})
@@ -231,10 +224,9 @@ function addToAttentionSet(parentUuid, changeJSON, user, reason, customAuth, cal
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
- logger.log(
- `An error occurred in POST to "${url}". Error: ${error.response.status}: ${
- error.response.data}`,
- "error", parentUuid
+ logger.info(
+ `An error occurred in POST to "${url}". Error: ${error.response.status}: ${error.response.data}`
+
);
callback(false, { status: error.response.status, data: error.response.data });
} else if (error.request) {
@@ -242,9 +234,8 @@ function addToAttentionSet(parentUuid, changeJSON, user, reason, customAuth, cal
callback(false, "retry");
} else {
// Something happened in setting up the request that triggered an Error
- logger.log(
- `Error in HTTP request while trying to add to attention set. Error: ${error}`,
- "error", parentUuid
+ logger.info(
+ `Error in HTTP request while trying to add to attention set. Error: ${error}`
);
callback(false, error.message);
}
@@ -255,21 +246,20 @@ function addToAttentionSet(parentUuid, changeJSON, user, reason, customAuth, cal
}
// Check permissions for a branch. Returns Bool.
-function checkAccessRights(uuid, repo, branch, user, permission, customAuth, callback) {
+function checkAccessRights(repo, branch, user, permission, customAuth, callback) {
// Decode and re-encode to be sure we don't double-encode something that was already
// passed to us in URI encoded format.
repo = encodeURIComponent(decodeURIComponent(repo));
branch = encodeURIComponent(decodeURIComponent(branch));
- let url = `${gerritBaseURL("projects")}/${repo}/check.access?account=${
- user}&ref=${encodeURIComponent('refs/for/refs/heads/')}${branch}&perm=${permission}`;
- logger.log(`GET request for ${url}`, "debug", uuid);
+ let url = `${gerritBaseURL("projects")}/${repo}/check.access?account=${user}&ref=${encodeURIComponent('refs/for/refs/heads/')}${branch}&perm=${permission}`;
+ logger.info(`GET request for ${url}`);
axios
.get(url, { auth: customAuth || gerritAuth })
.then(function (response) {
// A successful response's JSON object has a status field (independent
// of the HTTP response's status), that tells us whether this user
// does (200) or doesn't (403) have the requested permissions.
- logger.log(`Raw Response: ${response.data}`, "debug", uuid);
+ logger.info(`Raw Response: ${response.data}`);
callback(JSON.parse(trimResponse(response.data)).status == 200, undefined)
})
.catch(function (error) {
@@ -282,17 +272,13 @@ function checkAccessRights(uuid, repo, branch, user, permission, customAuth, cal
// to check permissions of other users, a much bigger problem.
data = "retry";
}
- logger.log(
- `An error occurred in GET to "${url}". Error ${error.response.status}: ${
- error.response.data}`,
- "error", uuid
+ logger.info(
+ `An error occurred in GET to "${url}". Error ${error.response.status}: ${error.response.data}`
);
} else {
data = `${error.status}:${error.message}`;
- logger.log(
- `Failed to get ${permission} access rights on ${repo}:${branch}\n${
- safeJsonStringify(error)}`,
- "error", uuid
+ logger.info(
+ `Failed to get ${permission} access rights on ${repo}:${branch}\n${safeJsonStringify(error)}`
);
}
callback(false, data);
diff --git a/logger.js b/logger.js
index f072731..5ab7211 100644
--- a/logger.js
+++ b/logger.js
@@ -1,3 +1,6 @@
+// Copyright (C) 2024 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 winston = require('winston');
const { combine, printf, colorize, align } = winston.format;
diff --git a/qt-submodule-update-watcher.service b/qt-submodule-update-watcher.service
new file mode 100644
index 0000000..9923bca
--- /dev/null
+++ b/qt-submodule-update-watcher.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=Qt Submodule Update Watcher
+After=network.target
+
+[Service]
+SyslogIdentifier=qt-submodule-update-watcher
+WorkingDirectory=/home/qt/qtsubmoduleupdatewatcher
+User=qt
+Group=qt
+Restart=always
+ExecStart=node submodule_update_watcher.js
+
+
+[Install]
+WantedBy=multi-user.target
diff --git a/submodule_update_watcher.js b/submodule_update_watcher.js
index ae80960..41eeb98 100644
--- a/submodule_update_watcher.js
+++ b/submodule_update_watcher.js
@@ -10,6 +10,7 @@ const bodyParser = require('body-parser');
const gerritTools = require("./gerritRESTTools");
const { logger } = require("./logger");
const config = require("./config.json");
+const safeJsonStringify = require("safe-json-stringify");
function envOrConfig(ID) {
return process.env[ID] || config[ID];
@@ -25,33 +26,37 @@ const jenkinsAuth = {
};
const jenkinsURL = envOrConfig("SUBMODULE_UPDATE_JENKINS_URL");
+if (!gerritAuth.username || !gerritAuth.password || !jenkinsAuth.username) {
+ logger.error("Missing credentials for submodule update watcher. Exiting.");
+ logger.error(jenkinsURL ? `Jenkins URL set to ${jenkinsURL}` : "No Jenkins URL set.");
+ process.exit(1);
+}
+
function handleIntegrationFailed(req) {
- logger.log(
- `Received dependency update failure notification for ${req.change.project}`,
- "info", req.uuid
+ logger.info(
+ `Received dependency update failure notification for ${req.change.project}`
);
- gerritTools.queryChange(
- req.uuid, req.fullChangeID, undefined, req.customGerritAuth,
+ gerritTools.queryChange(req.fullChangeID, undefined, gerritAuth,
function (success, data) {
- if (envOrConfig("SUBMODULE_UPDATE_FAILED_ATTENTION_USER")) {
+ if (success && envOrConfig("SUBMODULE_UPDATE_FAILED_ATTENTION_USER")) {
gerritTools.addToAttentionSet(
- req.uuid, req, envOrConfig("SUBMODULE_UPDATE_FAILED_ATTENTION_USER"), undefined,
- req.customGerritAuth,
+ req, envOrConfig("SUBMODULE_UPDATE_FAILED_ATTENTION_USER"), undefined,
+ gerritAuth,
function () {
- gerritTools.postGerritComment(req.uuid, req.fullChangeID,
+ gerritTools.postGerritComment(req.fullChangeID,
undefined, `${req.change.project} dependency update integration failed.`,
- undefined, req.customGerritAuth
+ undefined, gerritAuth
);
}
);
} else {
- logger.log("No default user configured to add to the attention set"
- + " for submodule updates.", undefined, req.uuid);
+ logger.info("No default user configured to add to the attention set"
+ + " for submodule updates.", undefined,);
}
// Run the bot again, which will either stage it or give up.
- sendBuildRequest(req);
}
);
+ sendBuildRequest(req);
}
function handleIntegrationPassed(req) {
@@ -64,7 +69,7 @@ function handleIntegrationPassed(req) {
+ ` set in [https://codereview.qt-project.org/#/q/${req.change.id},n,z]`
+ `(https://codereview.qt-project.org/#/q/${req.change.id},n,z)`
}).catch(function (error) {
- logger.log("Unable to send teams message...", "warn", "SUBMODULE");
+ logger.info(`Unable to send teams message... ${safeJsonStringify(error)}`);
});
}
sendBuildRequest(req)
@@ -72,154 +77,148 @@ function handleIntegrationPassed(req) {
function handleJenkinsError(req, res, error, action) {
- logger.log(`Unable to ${action} submodule update job for ${req.branch || req.change.branch}.`,
- "warn", "SUBMODULE");
+ logger.info(`Unable to ${action} submodule update job for ${req.branch || req.change.branch}.`);
if (error.response)
- logger.log(`Jenkins Error: ${error.response.status}: ${error.response.data}`,
- "warn", "SUBMODULE");
+ logger.info(`Jenkins Error: ${error.response.status}: ${error.response.data}`);
if (res === undefined)
return; // Only button presses from Teams carry a res object to respond to.
if (error.response) {
res.status(500).send(`Bad response from Jenkins: ${error.response.status}`
+ ` - ${error.response.data}<br>Contact the gerrit admins at`
- logger.log(`Jenkins responded with: ${error.response.status}`
- + ` - ${error.response.data}`, "error", "SUBMODULE");
+ logger.info(`Jenkins responded with: ${error.response.status} - ${error.response.data}`);
} else if (error.request) {
res.status(504).send("Timeout when attempting to contact Jenkins. Contact the gerrit"
+ " admins at [email protected]");
- logger.log(`Jenkins timed out! URL: ${req.jenkinsURL}`, "error", "SUBMODULE");
+ logger.info(`Jenkins timed out! URL: ${jenkinsURL}`, "SUBMODULE");
} else {
res.status(500).send(`Unknown error attempting to ${action} submodule update job in`
+ " Jenkins. Contact the gerrit admins at [email protected]");
- logger.log(`Unknown error attempting to ${action} submodule updates ${error}`,
- "error", "SUBMODULE");
+ logger.info(`Unknown error attempting to ${action} submodule updates ${error}`,
+ "SUBMODULE");
}
}
function sendBuildRequest(req, res) {
-
// Need to make the branch compatible with jenkins project naming rules.
let branch = (req.branch || req.change.branch).replace("/", "-");
- if (req.jenkinsURL) {
- logger.log(`Running new submodule update job on ${branch}`,
- undefined, "SUBMODULE");
- let url = `${req.jenkinsURL}/job/qt_submodule_update_${branch}/buildWithParameters`
- axios.post(url, undefined, { auth: req.jenkinsAuth }
+ if (jenkinsURL) {
+ logger.info(`Running new submodule update job on ${branch}`);
+ let url = `${jenkinsURL}/job/qt_submodule_update_${branch}/buildWithParameters`
+ axios.post(url, undefined, { auth: jenkinsAuth }
).catch(function (error) {
handleJenkinsError(req, res, error, "trigger new");
});
} else {
- logger.log("Unable to run new submodule update job. No URL set!", "warn", "SUBMODULE");
+ logger.info("Unable to run new submodule update job. No URL set!");
}
}
function pause_updates(req, res) {
- if (req.jenkinsURL) {
- logger.log(`Pausing submodule updates for ${req.branch}`, undefined, "SUBMODULE");
+ if (jenkinsURL) {
+ logger.info(`Pausing submodule updates for ${req.branch}`);
axios.post(
- `${req.jenkinsURL}/job/qt_submodule_update_${req.branch}/disable`,
- undefined, { auth: req.jenkinsAuth }
+ `${jenkinsURL}/job/qt_submodule_update_${req.branch}/disable`,
+ undefined, { auth: jenkinsAuth }
).then(function (response) {
res.status(200).send(`Submodule update job for ${req.branch} disabled.`);
axios.post(envOrConfig("SUBMODULE_UPDATE_TEAMS_URL"), {
"Text": `INFO: Paused submodule update automation on '**${req.branch}**'`
}).catch(function (error) {
- logger.log("Unable to send teams message...", "warn", "SUBMODULE");
+ logger.info(`Unable to send teams message... ${safeJsonStringify(error)}`);
});
}).catch(function (error) {
handleJenkinsError(req, res, error, "disable");
})
} else {
- logger.log(`Unable to disable submodule update job for ${req.branch}. Jenkins`
- + " URL not set!", "warn", "SUBMODULE");
+ logger.info(`Unable to disable submodule update job for ${req.branch}. Jenkins`
+ + " URL not set!");
res.status(500).send("No destination URL for Jenkins set. Contact the Gerrit Admins.");
}
}
function resume_updates(req, res) {
- if (req.jenkinsURL) {
- logger.log(`Resuming submodule updates for ${req.branch}`, undefined, "SUBMODULE");
+ if (jenkinsURL) {
+ logger.info(`Resuming submodule updates for ${req.branch}`);
axios.post(
- `${req.jenkinsURL}/job/qt_submodule_update_${req.branch}/enable`,
- undefined, { auth: req.jenkinsAuth }
+ `${jenkinsURL}/job/qt_submodule_update_${req.branch}/enable`,
+ undefined, { auth: jenkinsAuth }
).then(function (response) {
res.status(200).send(`Submodule update job for ${req.branch} enabled and restarted.`);
sendBuildRequest(req, res);
axios.post(envOrConfig("SUBMODULE_UPDATE_TEAMS_URL"), {
"Text": `INFO: Resumed submodule update automation on '**${req.branch}**'`
}).catch(function (error) {
- logger.log("Unable to send teams message...", "warn", "SUBMODULE");
+ logger.info(`Unable to send teams message... ${safeJsonStringify(error)}`);
});
}).catch(function (error) {
handleJenkinsError(req, res, error, "resume");
});
} else {
- logger.log(`Unable to resume submodule update job for ${req.branch}.`
- + " Jenkins URL not set!", "warn", "SUBMODULE");
+ logger.info(`Unable to resume submodule update job for ${req.branch}.`
+ + " Jenkins URL not set!");
res.status(500).send("No destination URL for Jenkins set. Contact the Gerrit Admins.");
}
}
function reset_updates(req, res) {
- if (req.jenkinsURL) {
+ if (jenkinsURL) {
// Temporary block of this button in Teams since it has been abused.
// Will be replaced with a better button or deprecated.
res.status(401).send("Unauthorized. Contact [email protected] to perform a reset.");
return;
- // logger.log(`Resetting submodule update round on ${req.branch}`, undefined, "SUBMODULE");
+ // logger.info(`Resetting submodule update round on ${req.branch}`);
// axios.post(
- // `${req.jenkinsURL}/job/qt_submodule_update_${req.branch}/buildWithParameters?RESET=true`,
- // undefined, { auth: req.jenkinsAuth }
+ // `${jenkinsURL}/job/qt_submodule_update_${req.branch}/buildWithParameters?RESET=true`,
+ // undefined, { auth: jenkinsAuth }
// ).then(function (response) {
// res.status(200).send(`Submodule update job for ${req.branch} reset.`);
// axios.post(envOrConfig("SUBMODULE_UPDATE_TEAMS_URL"), {
// "Text": `INFO: Reset submodule update round on '**${req.branch}**'`
// }).catch(function (error) {
- // logger.log("Unable to send teams message...", "warn", "SUBMODULE");
+ // logger.info("Unable to send teams message...");
// });
// // Then kick off a new round immediately
// axios.post(
- // `${req.jenkinsURL}/job/qt_submodule_update_${req.branch}/buildWithParameters`,
- // undefined, { auth: req.jenkinsAuth }
+ // `${jenkinsURL}/job/qt_submodule_update_${req.branch}/buildWithParameters`,
+ // undefined, { auth: jenkinsAuth }
// ).catch(function (error) {
- // logger.log(`Unable to start new submodule update job for ${req.branch}.`
- // + `\n${error.response ? error.response.status : error}`, "warn", "SUBMODULE");
+ // logger.info(`Unable to start new submodule update job for ${req.branch}.`
+ // + `\n${error.response ? error.response.status : error}`);
// })
// }).catch(function (error) {
// _handleJenkinsError(req, res, error, "reset");
// })
} else {
- logger.log(`Unable to reset submodule update job for ${req.branch}.`
- + " Jenkins URL not set!", "warn", "SUBMODULE")
+ logger.info(`Unable to reset submodule update job for ${req.branch}.`
+ + " Jenkins URL not set!")
res.status(500).send("No destination URL for Jenkins set. Contact the Gerrit Admins.");
}
}
function retry_updates(req, res) {
- if (req.jenkinsURL) {
- logger.log(`Running RETRY submodule update job on ${req.branch}`,
- undefined, "SUBMODULE");
+ if (jenkinsURL) {
+ logger.info(`Running RETRY submodule update job on ${req.branch}`);
axios.post(
- `${req.jenkinsURL}/job/qt_submodule_update_${req.branch}`
+ `${jenkinsURL}/job/qt_submodule_update_${req.branch}`
+ `/buildWithParameters?RETRY_FAILED_MODULES=true`, undefined,
- { auth: req.jenkinsAuth }
+ { auth: jenkinsAuth }
).then(function (response) {
res.status(200).send(`Submodule update job for ${req.branch} started.`);
axios.post(envOrConfig("SUBMODULE_UPDATE_TEAMS_URL"), {
"Text": `INFO: Retrying failed submodules on '**${req.branch}**'`
}).catch(function (error) {
- logger.log("Unable to send teams message...", "warn", "SUBMODULE");
+ logger.info(`Unable to send teams message... ${safeJsonStringify(error)}`);
});
}).catch(function (error) {
handleJenkinsError(req, res, error, "retry");
})
} else {
- logger.log(`Unable to start submodule update job for ${req.branch}.`
- + " Jenkins URL not set!", "warn", "SUBMODULE")
+ logger.info(`Unable to start submodule update job for ${req.branch}.`
+ + " Jenkins URL not set!")
res.status(500).send("No destination URL for Jenkins set. Contact the Gerrit Admins.")
}
}
@@ -238,21 +237,16 @@ function runWebserver() {
app.post('/', async (req, res) => {
const event = req.body;
+ event.fullChangeID = `${event.change.project}~${event.change.branch}~${event.change.id}`;
if (event.type === 'change-integration-fail') {
if (event.change.commitMessage.match(
/Update (submodule|submodules|dependencies) (refs )?on/)) {
- event["customGerritAuth"] = gerritAuth;
- event["jenkinsURL"] = jenkinsURL;
- event["jenkinsAuth"] = jenkinsAuth;
handleIntegrationFailed(event);
}
} else if (event.type === 'change-integration-pass') {
if (event.change.commitMessage.match(
/Update (submodule|submodules|dependencies) (refs )?on/)) {
- event["customGerritAuth"] = gerritAuth;
- event["jenkinsURL"] = jenkinsURL;
- event["jenkinsAuth"] = jenkinsAuth;
handleIntegrationPassed(event);
}
} else {
@@ -265,33 +259,21 @@ function runWebserver() {
app.post("/pause-submodule-updates", express.json(),
(req, res) => {
req = req.body;
- req["customGerritAuth"] = gerritAuth;
- req["jenkinsURL"] = jenkinsURL;
- req["jenkinsAuth"] = jenkinsAuth;
pause_updates(req, res);
})
app.post("/resume-submodule-updates", express.json(),
(req, res) => {
req = req.body;
- req["customGerritAuth"] = gerritAuth;
- req["jenkinsURL"] = jenkinsURL;
- req["jenkinsAuth"] = jenkinsAuth;
resume_updates(req, res);
})
app.post("/reset-submodule-updates", express.json(),
(req, res) => {
req = req.body;
- req["customGerritAuth"] = gerritAuth;
- req["jenkinsURL"] = jenkinsURL;
- req["jenkinsAuth"] = jenkinsAuth;
reset_updates(req, res);
})
app.post("/retry-submodule-updates", express.json(),
(req, res) => {
req = req.body;
- req["customGerritAuth"] = gerritAuth;
- req["jenkinsURL"] = jenkinsURL;
- req["jenkinsAuth"] = jenkinsAuth;
retry_updates(req, res);
})