summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Smith <daniel.smith@qt.io>2022-10-24 12:25:13 +0200
committerDaniel Smith <daniel.smith@qt.io>2023-02-10 12:15:55 +0100
commita937e9bc55deef8b1de851bd7a354496e42c6198 (patch)
tree95ab062f3beadddfb44d95ab10dcc106a7023bd5
parentd5b4ee998560c56635fac992a56dfede86063c95 (diff)
downloadqtqa-a937e9bc55deef8b1de851bd7a354496e42c6198.tar.gz
Use proper fallbacks for selecting an attention set user
Fixes: QTQAINFRA-5249 Change-Id: I128375501a269d16d1b88474620ca9a9dee97d81 Reviewed-by: Jukka Jokiniva <jukka.jokiniva@qt.io>
-rw-r--r--scripts/gerrit/cherry-pick_automation/gerritRESTTools.js34
-rw-r--r--scripts/gerrit/cherry-pick_automation/plugin_bots/integration_monitor/integration_monitor.js22
2 files changed, 39 insertions, 17 deletions
diff --git a/scripts/gerrit/cherry-pick_automation/gerritRESTTools.js b/scripts/gerrit/cherry-pick_automation/gerritRESTTools.js
index edb901c..33d0b2a 100644
--- a/scripts/gerrit/cherry-pick_automation/gerritRESTTools.js
+++ b/scripts/gerrit/cherry-pick_automation/gerritRESTTools.js
@@ -376,7 +376,9 @@ exports.queryRelated = function (parentUuid, fullChangeID, customAuth, callback)
};
// Query gerrit for a change and return it along with the current revision if it exists.
-exports.queryChange = function (parentUuid, fullChangeID, fields, customAuth, callback) {
+
+exports.queryChange = queryChange;
+function queryChange(parentUuid, fullChangeID, fields, customAuth, callback) {
let url = `${gerritBaseURL("changes")}/${fullChangeID}/?o=CURRENT_COMMIT&o=CURRENT_REVISION`;
// Tack on any additional fields requested
if (fields)
@@ -504,7 +506,7 @@ function addToAttentionSet(parentUuid, changeJSON, user, reason, customAuth, cal
logger.log(msg, "warn", parentUuid);
callback(false, msg);
let botAssignee = envOrConfig("GERRIT_USER");
- if (botAssignee && newAssignee != botAssignee) {
+ if (botAssignee && user != botAssignee) {
logger.log(`Falling back to GERRIT_USER (${botAssignee}) as assignee...`);
addToAttentionSet(
parentUuid, changeJSON, botAssignee, "fallback to bot", customAuth,
@@ -685,14 +687,14 @@ function locateDefaultAttentionUser(uuid, cherryPickChange, uploader, callback)
let cherryPickRegex = /^\((?:partial(?:ly)? )?(?:cherry[- ]pick|(?:back-?)?port|adapt)(?:ed)?(?: from| of)?(?: commit)? (\w+\/)?([0-9a-fA-F]{7,40})/m;
let originSha = undefined;
try{
- originSha = commitMessage.match(cherryPickRegex)[0];
+ originSha = commitMessage.match(cherryPickRegex)[2];
} catch {
- _this.logger.log(`Failed to match a cherry-pick footer for ${cherryPickChange.fullChangeID}`,
+ logger.log(`Failed to match a cherry-pick footer for ${cherryPickChange.fullChangeID}`,
"error", uuid);
callback(false); // No point in continuing. Log the error and move on.
return;
}
- gerritTools.queryChange(uuid, originSha, undefined, undefined,
+ queryChange(uuid, originSha, undefined, undefined,
function(success, changeData) {
if (success) {
let originalAuthor = changeData.revisions[changeData.current_revision]
@@ -706,17 +708,23 @@ function locateDefaultAttentionUser(uuid, cherryPickChange, uploader, callback)
if (canRead)
callback(originalAuthor);
else {
- // Now we have a problem. The uploader is the original author, but
- // they also appear to have self-approved the original patch.
- // Try to copy all the reviewers from the original change
- // (hopefully there are some).
- // Adding them as a reviewer will also add them to the attention set.
- callback("copyReviewers", changeData.id);
+ if (changeData.owner._account_id == 1007413 // Cherry-pick bot
+ && /^(tqtc(?:%2F|\/)lts-)/.test(changeData.branch)) {
+ // LTS release manager
+ callback(envOrConfig("TQTC_LTS_NOTIFY_FALLBACK_USER"));
+ } else {
+ // Now we have a problem. The uploader is the original author, but
+ // they also appear to have self-approved the original patch.
+ // Try to copy all the reviewers from the original change
+ // (hopefully there are some).
+ // Adding them as a reviewer will also add them to the attention set.
+ callback("copyReviewers", changeData.id);
+ }
}
});
}
} else {
- _this.logger.log(`Failed to query gerrit for ${originSha}`, "error", uuid);
+ logger.log(`Failed to query gerrit for ${originSha}`, "error", uuid);
}
}
);
@@ -728,7 +736,7 @@ function locateDefaultAttentionUser(uuid, cherryPickChange, uploader, callback)
} catch {
// Should really never fail, since cherry-picks should always be created
// with the original Review footers intact.
- _this.logger.log(`Failed to locate a reviewer from commit message:\n${commitMessage}`,
+ logger.log(`Failed to locate a reviewer from commit message:\n${commitMessage}`,
"error", uuid);
}
if (originalApprover && originalApprover != uploader) {
diff --git a/scripts/gerrit/cherry-pick_automation/plugin_bots/integration_monitor/integration_monitor.js b/scripts/gerrit/cherry-pick_automation/plugin_bots/integration_monitor/integration_monitor.js
index 19fb107..e92c815 100644
--- a/scripts/gerrit/cherry-pick_automation/plugin_bots/integration_monitor/integration_monitor.js
+++ b/scripts/gerrit/cherry-pick_automation/plugin_bots/integration_monitor/integration_monitor.js
@@ -44,7 +44,7 @@ class integration_monitor {
notifier.server.emit("integration_monitor_failed", req, author);
}
} else {
- logger.log(`Failed to query gerrit for ${req.fullChangeID}`, "error", req.uuid);
+ this.logger.log(`Failed to query gerrit for ${req.fullChangeID}`, "error", req.uuid);
}
}
);
@@ -67,12 +67,13 @@ class integration_monitor {
);
}
- doAddToAttentionSet(req, user, reason) {
+ doAddToAttentionSet(req, user, reason, callback) {
let _this = this;
gerritTools.addToAttentionSet(
req.uuid, req.change, user, reason, undefined,
function (success, msg) {
- // No need to do anything after adding.
+ if (callback)
+ callback(success);
}
);
}
@@ -84,7 +85,20 @@ class integration_monitor {
"info", req.uuid
);
req.change.fullChangeID = req.fullChangeID // Tack on the full change ID so it gets used
- _this.doAddToAttentionSet(req, author, "Change author");
+ _this.doAddToAttentionSet(req, author, "Change author", (success) => {
+ if (!success) {
+ gerritTools.locateDefaultAttentionUser(req.uuid, req.change, req.change.patchSet.uploader.email,
+ (user, fallbackId) => {
+ if (user == "copyReviewers")
+ gerritTools.copyChangeReviewers(req.uuid, fallbackId, req.change.fullChangeID);
+ else {
+ gerritTools.setChangeReviewers(req.uuid, req.change.fullChangeID, [user], undefined,
+ function(){})
+ _this.doAddToAttentionSet(req, user, "Original reviewer");
+ }
+ });
+ }
+ });
}
handlePatchsetCreated(req, uploader) {