Add change subject to output of change URL on push

When a new change / patch set is pushed, Gerrit prints out the URL to
the change as 'New Changes' / 'Updated Changes'. Include the change
subject into this output so that one can easily verify that the
correct commits were pushed. This is especially useful if many changes
are updated at once.

Output before this change:
  remote: Updated Changes:
  remote:   https://gerrit-review.googlesource.com/57524
  remote:   https://gerrit-review.googlesource.com/57511
  remote:   https://gerrit-review.googlesource.com/58153
  remote:   https://gerrit-review.googlesource.com/57510
  remote:   https://gerrit-review.googlesource.com/57522
  remote:   https://gerrit-review.googlesource.com/57512

Output after this change:
  remote: Updated Changes:
  remote:   https://gerrit-review.googlesource.com/57524 Add REST endpoint to get server summary
  remote:   https://gerrit-review.googlesource.com/57511 Require 'Administrate Server' capability to see server summary
  remote:   https://gerrit-review.googlesource.com/58153 Support flushing a set of caches at once via REST
  remote:   https://gerrit-review.googlesource.com/57510 Support flushing of all caches via REST
  remote:   https://gerrit-review.googlesource.com/57522 Support AcceptsPost on non top level REST collections
  remote:   https://gerrit-review.googlesource.com/57512 Support listing of cache names via REST

If a change subject exceeds 80 characters, it is truncated.

Change-Id: I72ef0621f40d85bc624a12df4af481afaa7af6a2
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2014-07-01 16:06:49 +02:00
committed by David Pursehouse
parent 5f945d68a2
commit 7d6db3c15e
2 changed files with 21 additions and 1 deletions

View File

@@ -96,6 +96,10 @@ public class ChangeUtil {
private static int uuidPrefix;
private static int uuidSeq;
private static final int SUBJECT_MAX_LENGTH = 80;
private static final String SUBJECT_CROP_APPENDIX = "...";
private static final int SUBJECT_CROP_RANGE = 10;
private static final Logger log =
LoggerFactory.getLogger(ChangeUtil.class);
@@ -196,6 +200,20 @@ public class ChangeUtil {
return nextPatchSetId(git.getRefDatabase().getRefs(RefDatabase.ALL), id);
}
public static String cropSubject(String subject) {
if (subject.length() > SUBJECT_MAX_LENGTH) {
int maxLength = SUBJECT_MAX_LENGTH - SUBJECT_CROP_APPENDIX.length();
for (int cropPosition = maxLength;
cropPosition > maxLength - SUBJECT_CROP_RANGE; cropPosition--) {
if (Character.isWhitespace(subject.charAt(cropPosition - 1))) {
return subject.substring(0, cropPosition) + SUBJECT_CROP_APPENDIX;
}
}
return subject.substring(0, maxLength) + SUBJECT_CROP_APPENDIX;
}
return subject;
}
private final Provider<CurrentUser> userProvider;
private final CommitValidators.Factory commitValidatorsFactory;
private final Provider<ReviewDb> db;