Move commit message length checks to validation plugin
Checks of the commit message's length are removed from the ReceiveCommits class. These checks are now done in the commit message length validation plugin, which is added as a core plugin. Change-Id: Ia0858b11e475c48f50ec63fbe0076239edf8f64b
This commit is contained in:
parent
ec31ddf545
commit
9437b7be9f
@ -11,6 +11,9 @@ client.
|
|||||||
To make use of this feature, a plugin must implement the `CommitValidationListener`
|
To make use of this feature, a plugin must implement the `CommitValidationListener`
|
||||||
interface.
|
interface.
|
||||||
|
|
||||||
|
Out of the box, Gerrit includes a plugin that checks the length of the
|
||||||
|
subject and body lines of commit messages on uploaded commits.
|
||||||
|
|
||||||
|
|
||||||
GERRIT
|
GERRIT
|
||||||
------
|
------
|
||||||
|
@ -52,6 +52,12 @@ limitations under the License.
|
|||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.googlesource.gerrit.plugins.validators</groupId>
|
||||||
|
<artifactId>commit-message-length-validator</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -89,7 +89,6 @@ import com.google.inject.assistedinject.Assisted;
|
|||||||
|
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||||
import org.eclipse.jgit.errors.MissingObjectException;
|
import org.eclipse.jgit.errors.MissingObjectException;
|
||||||
import org.eclipse.jgit.lib.AbbreviatedObjectId;
|
|
||||||
import org.eclipse.jgit.lib.BatchRefUpdate;
|
import org.eclipse.jgit.lib.BatchRefUpdate;
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
@ -1341,7 +1340,6 @@ public class ReceiveCommits {
|
|||||||
|
|
||||||
CheckedFuture<Void, OrmException> insertChange() throws IOException {
|
CheckedFuture<Void, OrmException> insertChange() throws IOException {
|
||||||
rp.getRevWalk().parseBody(commit);
|
rp.getRevWalk().parseBody(commit);
|
||||||
warnMalformedMessage(commit);
|
|
||||||
|
|
||||||
final Thread caller = Thread.currentThread();
|
final Thread caller = Thread.currentThread();
|
||||||
ListenableFuture<Void> future = changeUpdateExector.submit(
|
ListenableFuture<Void> future = changeUpdateExector.submit(
|
||||||
@ -1632,7 +1630,6 @@ public class ReceiveCommits {
|
|||||||
CheckedFuture<PatchSet.Id, OrmException> insertPatchSet()
|
CheckedFuture<PatchSet.Id, OrmException> insertPatchSet()
|
||||||
throws IOException {
|
throws IOException {
|
||||||
rp.getRevWalk().parseBody(newCommit);
|
rp.getRevWalk().parseBody(newCommit);
|
||||||
warnMalformedMessage(newCommit);
|
|
||||||
|
|
||||||
final Thread caller = Thread.currentThread();
|
final Thread caller = Thread.currentThread();
|
||||||
ListenableFuture<PatchSet.Id> future = changeUpdateExector.submit(
|
ListenableFuture<PatchSet.Id> future = changeUpdateExector.submit(
|
||||||
@ -1904,41 +1901,6 @@ public class ReceiveCommits {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void warnMalformedMessage(RevCommit c) {
|
|
||||||
ObjectReader reader = rp.getRevWalk().getObjectReader();
|
|
||||||
if (65 < c.getShortMessage().length()) {
|
|
||||||
AbbreviatedObjectId id;
|
|
||||||
try {
|
|
||||||
id = reader.abbreviate(c);
|
|
||||||
} catch (IOException err) {
|
|
||||||
id = c.abbreviate(6);
|
|
||||||
}
|
|
||||||
addMessage("(W) " + id.name() //
|
|
||||||
+ ": commit subject >65 characters; use shorter first paragraph");
|
|
||||||
}
|
|
||||||
|
|
||||||
int longLineCnt = 0, nonEmptyCnt = 0;
|
|
||||||
for (String line : c.getFullMessage().split("\n")) {
|
|
||||||
if (!line.trim().isEmpty()) {
|
|
||||||
nonEmptyCnt++;
|
|
||||||
}
|
|
||||||
if (70 < line.length()) {
|
|
||||||
longLineCnt++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 < longLineCnt && 33 < longLineCnt * 100 / nonEmptyCnt) {
|
|
||||||
AbbreviatedObjectId id;
|
|
||||||
try {
|
|
||||||
id = reader.abbreviate(c);
|
|
||||||
} catch (IOException err) {
|
|
||||||
id = c.abbreviate(6);
|
|
||||||
}
|
|
||||||
addMessage("(W) " + id.name() //
|
|
||||||
+ ": commit message lines >70 characters; manually wrap lines");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void autoCloseChanges(final ReceiveCommand cmd) {
|
private void autoCloseChanges(final ReceiveCommand cmd) {
|
||||||
final RevWalk rw = rp.getRevWalk();
|
final RevWalk rw = rp.getRevWalk();
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user