Extract helpers for isOnParent and patchNum
Splitting is a prerequisite for first threading comments, then grouping them by line. Change-Id: I6b58d8bac9ba21244152b4e3596732362233b832
This commit is contained in:
@@ -398,6 +398,46 @@
|
|||||||
return threads;
|
return threads;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the patch number that new comment threads should be attached to.
|
||||||
|
*
|
||||||
|
* @param {GrDiffLine} line The line new thread will be attached to.
|
||||||
|
* @param {string=} opt_side Set to LEFT to force adding it to the LEFT side -
|
||||||
|
* will be ignored if the left is a parent or a merge parent
|
||||||
|
* @return {number} Patch set to attach the new thread to
|
||||||
|
*/
|
||||||
|
GrDiffBuilder.prototype._determinePatchNumForNewThreads = function(
|
||||||
|
patchRange, line, opt_side) {
|
||||||
|
if ((line.type === GrDiffLine.Type.REMOVE ||
|
||||||
|
opt_side === GrDiffBuilder.Side.LEFT) &&
|
||||||
|
patchRange.basePatchNum !== 'PARENT' &&
|
||||||
|
!Gerrit.PatchSetBehavior.isMergeParent(patchRange.basePatchNum)) {
|
||||||
|
return patchRange.basePatchNum;
|
||||||
|
} else {
|
||||||
|
return patchRange.patchNum;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the comments on the given line are on a (merge) parent.
|
||||||
|
*
|
||||||
|
* @param {string} firstCommentSide
|
||||||
|
* @param {{basePatchNum: number, patchNum: number}} patchRange
|
||||||
|
* @param {GrDiffLine} line The line the comments are on.
|
||||||
|
* @param {string=} opt_side
|
||||||
|
* @return {boolean} True iff the comments on the given line are on a (merge)
|
||||||
|
* parent.
|
||||||
|
*/
|
||||||
|
GrDiffBuilder.prototype._determineIsOnParent = function(
|
||||||
|
firstCommentSide, patchRange, line, opt_side) {
|
||||||
|
return ((line.type === GrDiffLine.Type.REMOVE ||
|
||||||
|
opt_side === GrDiffBuilder.Side.LEFT) &&
|
||||||
|
(patchRange.basePatchNum === 'PARENT' ||
|
||||||
|
Gerrit.PatchSetBehavior.isMergeParent(
|
||||||
|
patchRange.basePatchNum))) ||
|
||||||
|
firstCommentSide === 'PARENT';
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {GrDiffLine} line
|
* @param {GrDiffLine} line
|
||||||
* @param {string=} opt_side
|
* @param {string=} opt_side
|
||||||
@@ -411,18 +451,11 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let patchNum = this._comments.meta.patchRange.patchNum;
|
const patchNum = this._determinePatchNumForNewThreads(
|
||||||
let isOnParent = comments[0].side === 'PARENT' || false;
|
this._comments.meta.patchRange, line, opt_side);
|
||||||
if (line.type === GrDiffLine.Type.REMOVE ||
|
const isOnParent = this._determineIsOnParent(
|
||||||
opt_side === GrDiffBuilder.Side.LEFT) {
|
comments[0].side, this._comments.meta.patchRange, line, opt_side);
|
||||||
if (this._comments.meta.patchRange.basePatchNum === 'PARENT' ||
|
|
||||||
Gerrit.PatchSetBehavior.isMergeParent(
|
|
||||||
this._comments.meta.patchRange.basePatchNum)) {
|
|
||||||
isOnParent = true;
|
|
||||||
} else {
|
|
||||||
patchNum = this._comments.meta.patchRange.basePatchNum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const threadGroupEl = this._createThreadGroupFn(patchNum, isOnParent,
|
const threadGroupEl = this._createThreadGroupFn(patchNum, isOnParent,
|
||||||
opt_side);
|
opt_side);
|
||||||
threadGroupEl.threads = this._getThreads(comments, patchNum);
|
threadGroupEl.threads = this._getThreads(comments, patchNum);
|
||||||
|
Reference in New Issue
Block a user