summaryrefslogtreecommitdiffstats
path: root/scripts/gerrit/cherry-pick_automation/singleRequestManager.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gerrit/cherry-pick_automation/singleRequestManager.js')
-rw-r--r--scripts/gerrit/cherry-pick_automation/singleRequestManager.js74
1 files changed, 68 insertions, 6 deletions
diff --git a/scripts/gerrit/cherry-pick_automation/singleRequestManager.js b/scripts/gerrit/cherry-pick_automation/singleRequestManager.js
index b5b89311..300e18d4 100644
--- a/scripts/gerrit/cherry-pick_automation/singleRequestManager.js
+++ b/scripts/gerrit/cherry-pick_automation/singleRequestManager.js
@@ -4,6 +4,11 @@
exports.id = "singleRequestManager";
+const safeJsonStringify = require("safe-json-stringify");
+
+const { findPickToBranches } = require("./toolbox");
+const gerritTools = require("./gerritRESTTools");
+
// The singleRequestManager processes incoming changes linerally.
// When start() is called, the request progresses through branch
// validation, tries to create a cherry pick, and tries to stage it.
@@ -35,17 +40,74 @@ class singleRequestManager {
this.requestProcessor.addListener("singleRequest_stagingDone", this.handleStagingDone);
}
- start(parentJSON, branches) {
+ start(parentJSON, picks) {
let _this = this;
+
+ function emit(parentCopy, branch) {
+ _this.requestProcessor.emit(
+ "validateBranch", parentCopy, branch,
+ "singleRequest_validBranch"
+ );
+ }
_this.logger.log(
`Starting SingleRequest Manager process for ${parentJSON.fullChangeID}`,
"verbose", parentJSON.uuid
);
- branches.forEach(function (branch) {
- _this.requestProcessor.emit(
- "validateBranch", _this.requestProcessor.toolbox.deepCopy(parentJSON), branch,
- "singleRequest_validBranch"
- );
+ Object.keys(picks).forEach(function (branch) {
+ let parentCopy = _this.requestProcessor.toolbox.deepCopy(parentJSON)
+ if (picks[branch].length > 0) {
+ const originalPicks = Array.from(findPickToBranches(parentCopy.uuid, parentCopy.change.commitMessage));
+ let missing = picks[branch].filter(x => !originalPicks.includes(x));
+ // Check the target branch itself since it may not be in originalPicks and could have been
+ // added by the bot.
+ if (!originalPicks.includes(branch))
+ missing.push(branch);
+ if (missing.length > 0) {
+ gerritTools.locateDefaultAttentionUser(parentJSON.uuid, parentCopy,
+ parentJSON.patchSet.uploader.email, function(user) {
+ function postComment() {
+ const plural = missing.length > 1;
+ _this.requestProcessor.gerritCommentHandler(parentCopy.uuid,
+ parentCopy.fullChangeID, undefined,
+ `Automatic cherry-picking detected missing Pick-to targets.`
+ +`\nTarget${plural ? 's' : ''} "${missing.join(", ")}"`
+ + ` ${plural ? "have" : "has"} been automatically added to the`
+ + ` cherry-pick for ${branch}.\nPlease review for correctness.`);
+ }
+
+ if (user && user == "copyReviewers") {
+ // Do nothing since we don't have a default attention user.
+ // This typically means the change was self-approved.
+ } else {
+ gerritTools.setChangeReviewers(parentJSON.uuid, parentCopy.fullChangeID,
+ [user], undefined, function() {
+ gerritTools.addToAttentionSet(
+ parentJSON.uuid, parentCopy, user, "Relevant user",
+ parentJSON.customGerritAuth,
+ function (success, data) {
+ if (!success) {
+ _this.logger.log(
+ `Failed to add "${safeJsonStringify(parentJSON.change.owner)}" to the`
+ + ` attention set of ${parentCopy.id}\n`
+ + `Reason: ${safeJsonStringify(data)}`,
+ "error", parentJSON.uuid
+ );
+ }
+ postComment();
+ }
+ );
+ });
+ }
+ });
+ }
+ parentCopy.change.commitMessage = parentCopy.change.commitMessage
+ .replace(/^Pick-to:.+$/gm, `Pick-to: ${picks[branch].join(" ")}`);
+ emit(parentCopy, branch);
+ } else {
+ parentCopy.change.commitMessage = parentCopy.change.commitMessage
+ .replace(/^Pick-to:.+$\n/gm, "");
+ emit(parentCopy, branch);
+ }
});
}