Move all FooterKeys into one place
We want to have the common FooterKeys be setup in one place, preventing typo mistakes when reusing them. Change-Id: Id31652bf0f0415c7b1a72df4f034910245a1d690
This commit is contained in:
committed by
Dave Borowitz
parent
5be81b0b17
commit
55d8727967
@@ -0,0 +1,31 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.common;
|
||||
|
||||
import org.eclipse.jgit.revwalk.FooterKey;
|
||||
|
||||
public class FooterConstants {
|
||||
/** The change ID as used to track patch sets. */
|
||||
public static final FooterKey CHANGE_ID = new FooterKey("Change-Id");
|
||||
|
||||
/** The footer telling us who reviewed the change. */
|
||||
public static final FooterKey REVIEWED_BY = new FooterKey("Reviewed-by");
|
||||
|
||||
/** The footer telling us the URL where the review took place. */
|
||||
public static final FooterKey REVIEWED_ON = new FooterKey("Reviewed-on");
|
||||
|
||||
/** The footer telling us who tested the change. */
|
||||
public static final FooterKey TESTED_BY = new FooterKey("Tested-by");
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.common.FooterConstants;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -53,7 +54,6 @@ import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.RefUpdate;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.FooterKey;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
@@ -66,8 +66,6 @@ import java.util.TimeZone;
|
||||
@Singleton
|
||||
public class CherryPickChange {
|
||||
|
||||
private static final FooterKey CHANGE_ID = new FooterKey("Change-Id");
|
||||
|
||||
private final Provider<ReviewDb> db;
|
||||
private final GitRepositoryManager gitManager;
|
||||
private final TimeZone serverTimeZone;
|
||||
@@ -162,7 +160,8 @@ public class CherryPickChange {
|
||||
}
|
||||
|
||||
Change.Key changeKey;
|
||||
final List<String> idList = cherryPickCommit.getFooterLines(CHANGE_ID);
|
||||
final List<String> idList = cherryPickCommit.getFooterLines(
|
||||
FooterConstants.CHANGE_ID);
|
||||
if (!idList.isEmpty()) {
|
||||
final String idStr = idList.get(idList.size() - 1).trim();
|
||||
changeKey = new Change.Key(idStr);
|
||||
|
||||
@@ -16,6 +16,7 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.common.FooterConstants;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.common.data.Capable;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
@@ -250,7 +251,7 @@ public class CreateChange implements
|
||||
|
||||
private static Change.Key getChangeId(ObjectId id, RevCommit emptyCommit) {
|
||||
List<String> idList = emptyCommit.getFooterLines(
|
||||
MergeUtil.CHANGE_ID);
|
||||
FooterConstants.CHANGE_ID);
|
||||
Change.Key changeKey = !idList.isEmpty()
|
||||
? new Change.Key(idList.get(idList.size() - 1).trim())
|
||||
: new Change.Key("I" + id.name());
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.common.FooterConstants;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -80,8 +81,6 @@ import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class MergeUtil {
|
||||
public static final FooterKey CHANGE_ID = new FooterKey("Change-Id");
|
||||
private static final FooterKey REVIEWED_ON = new FooterKey("Reviewed-on");
|
||||
private static final Logger log = LoggerFactory.getLogger(MergeUtil.class);
|
||||
private static final String R_HEADS_MASTER =
|
||||
Constants.R_HEADS + Constants.MASTER;
|
||||
@@ -224,8 +223,8 @@ public class MergeUtil {
|
||||
msgbuf.append('\n');
|
||||
}
|
||||
|
||||
if (!contains(footers, CHANGE_ID, n.change().getKey().get())) {
|
||||
msgbuf.append(CHANGE_ID.getName());
|
||||
if (!contains(footers, FooterConstants.CHANGE_ID, n.change().getKey().get())) {
|
||||
msgbuf.append(FooterConstants.CHANGE_ID.getName());
|
||||
msgbuf.append(": ");
|
||||
msgbuf.append(n.change().getKey().get());
|
||||
msgbuf.append('\n');
|
||||
@@ -234,8 +233,8 @@ public class MergeUtil {
|
||||
final String siteUrl = urlProvider.get();
|
||||
if (siteUrl != null) {
|
||||
final String url = siteUrl + n.getPatchsetId().getParentKey().get();
|
||||
if (!contains(footers, REVIEWED_ON, url)) {
|
||||
msgbuf.append(REVIEWED_ON.getName());
|
||||
if (!contains(footers, FooterConstants.REVIEWED_ON, url)) {
|
||||
msgbuf.append(FooterConstants.REVIEWED_ON.getName());
|
||||
msgbuf.append(": ");
|
||||
msgbuf.append(url);
|
||||
msgbuf.append('\n');
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import static com.google.gerrit.common.FooterConstants.CHANGE_ID;
|
||||
import static com.google.gerrit.reviewdb.client.RefNames.REFS_CHANGES;
|
||||
import static com.google.gerrit.server.change.HashtagsUtil.cleanupHashtag;
|
||||
import static com.google.gerrit.server.git.MultiProgressMonitor.UNKNOWN;
|
||||
@@ -51,6 +52,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
import com.google.gerrit.common.ChangeHookRunner.HookResult;
|
||||
import com.google.gerrit.common.ChangeHooks;
|
||||
import com.google.gerrit.common.FooterConstants;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.common.data.Capable;
|
||||
@@ -133,7 +135,6 @@ import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.notes.NoteMap;
|
||||
import org.eclipse.jgit.revwalk.FooterKey;
|
||||
import org.eclipse.jgit.revwalk.FooterLine;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevObject;
|
||||
@@ -178,8 +179,6 @@ public class ReceiveCommits {
|
||||
public static final Pattern NEW_PATCHSET = Pattern.compile(
|
||||
"^" + REFS_CHANGES + "(?:[0-9][0-9]/)?([1-9][0-9]*)(?:/new)?$");
|
||||
|
||||
private static final FooterKey CHANGE_ID = new FooterKey("Change-Id");
|
||||
|
||||
private static final String COMMAND_REJECTION_MESSAGE_FOOTER =
|
||||
"Please read the documentation and contact an administrator\n"
|
||||
+ "if you feel the configuration is incorrect";
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.git.validators;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.gerrit.common.FooterConstants;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
@@ -59,8 +60,6 @@ public class CommitValidators {
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(CommitValidators.class);
|
||||
|
||||
private static final FooterKey CHANGE_ID = new FooterKey("Change-Id");
|
||||
|
||||
public interface Factory {
|
||||
CommitValidators create(RefControl refControl, SshInfo sshInfo,
|
||||
Repository repo);
|
||||
@@ -179,14 +178,15 @@ public class CommitValidators {
|
||||
@Override
|
||||
public List<CommitValidationMessage> onCommitReceived(
|
||||
CommitReceivedEvent receiveEvent) throws CommitValidationException {
|
||||
final List<String> idList = receiveEvent.commit.getFooterLines(CHANGE_ID);
|
||||
final List<String> idList = receiveEvent.commit.getFooterLines(
|
||||
FooterConstants.CHANGE_ID);
|
||||
|
||||
List<CommitValidationMessage> messages = new LinkedList<>();
|
||||
|
||||
if (idList.isEmpty()) {
|
||||
if (projectControl.getProjectState().isRequireChangeID()) {
|
||||
String shortMsg = receiveEvent.commit.getShortMessage();
|
||||
String changeIdPrefix = CHANGE_ID.getName() + ":";
|
||||
String changeIdPrefix = FooterConstants.CHANGE_ID.getName() + ":";
|
||||
if (shortMsg.startsWith(changeIdPrefix)
|
||||
&& shortMsg.substring(changeIdPrefix.length()).trim()
|
||||
.matches("^I[0-9a-f]{8,}.*$")) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.mail;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gerrit.common.FooterConstants;
|
||||
import com.google.gerrit.common.errors.NoSuchAccountException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
@@ -31,8 +32,6 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MailUtil {
|
||||
private static final FooterKey REVIEWED_BY = new FooterKey("Reviewed-by");
|
||||
private static final FooterKey TESTED_BY = new FooterKey("Tested-by");
|
||||
|
||||
public static MailRecipients getRecipientsFromFooters(
|
||||
final AccountResolver accountResolver, final PatchSet ps,
|
||||
@@ -77,8 +76,8 @@ public class MailUtil {
|
||||
private static boolean isReviewer(final FooterLine candidateFooterLine) {
|
||||
return candidateFooterLine.matches(FooterKey.SIGNED_OFF_BY)
|
||||
|| candidateFooterLine.matches(FooterKey.ACKED_BY)
|
||||
|| candidateFooterLine.matches(REVIEWED_BY)
|
||||
|| candidateFooterLine.matches(TESTED_BY);
|
||||
|| candidateFooterLine.matches(FooterConstants.REVIEWED_BY)
|
||||
|| candidateFooterLine.matches(FooterConstants.TESTED_BY);
|
||||
}
|
||||
|
||||
public static class MailRecipients {
|
||||
|
||||
Reference in New Issue
Block a user