Add 'CherryPickOf' field for a change
After a change is created or updated using the 'cherry-pick' functionality, this field will contain the source change number and the patchset. Having this field helps us identify changes where actual dev time was spent on by filtering out propagated changes. This is especially useful for organizations wanting to generate cost metrics. Change-Id: I782a56aa52c52670ec74fabb713fe47ecba24de1
This commit is contained in:
committed by
Kaushik Lingarkar
parent
8b457aeb17
commit
4a711eda84
@@ -301,6 +301,7 @@ public class ChangeData {
|
||||
private Integer unresolvedCommentCount;
|
||||
private Integer totalCommentCount;
|
||||
private LabelTypes labelTypes;
|
||||
private Optional<PatchSet.Id> cherryPickOf;
|
||||
|
||||
private ImmutableList<byte[]> refStates;
|
||||
private ImmutableList<byte[]> refStatePatterns;
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.google.gerrit.entities.Account;
|
||||
import com.google.gerrit.entities.AccountGroup;
|
||||
import com.google.gerrit.entities.BranchNameKey;
|
||||
import com.google.gerrit.entities.Change;
|
||||
import com.google.gerrit.entities.PatchSet;
|
||||
import com.google.gerrit.entities.RefNames;
|
||||
import com.google.gerrit.exceptions.NotSignedInException;
|
||||
import com.google.gerrit.exceptions.StorageException;
|
||||
@@ -189,6 +190,9 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData, ChangeQueryBuil
|
||||
public static final String FIELD_WATCHEDBY = "watchedby";
|
||||
public static final String FIELD_WIP = "wip";
|
||||
public static final String FIELD_REVERTOF = "revertof";
|
||||
public static final String FIELD_CHERRY_PICK_OF = "cherrypickof";
|
||||
public static final String FIELD_CHERRY_PICK_OF_CHANGE = "cherrypickofchange";
|
||||
public static final String FIELD_CHERRY_PICK_OF_PATCHSET = "cherrypickofpatchset";
|
||||
|
||||
public static final String ARG_ID_USER = "user";
|
||||
public static final String ARG_ID_GROUP = "group";
|
||||
@@ -1268,6 +1272,29 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData, ChangeQueryBuil
|
||||
"'submissionid' operator is not supported by change index version");
|
||||
}
|
||||
|
||||
@Operator
|
||||
public Predicate<ChangeData> cherryPickOf(String value) throws QueryParseException {
|
||||
if (args.getSchema().hasField(ChangeField.CHERRY_PICK_OF_CHANGE)
|
||||
&& args.getSchema().hasField(ChangeField.CHERRY_PICK_OF_PATCHSET)) {
|
||||
if (Ints.tryParse(value) != null) {
|
||||
return new CherryPickOfChangePredicate(value);
|
||||
}
|
||||
try {
|
||||
PatchSet.Id patchSetId = PatchSet.Id.parse(value);
|
||||
return Predicate.and(
|
||||
new CherryPickOfChangePredicate(patchSetId.changeId().toString()),
|
||||
new CherryPickOfPatchSetPredicate(patchSetId.getId()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new QueryParseException(
|
||||
"'"
|
||||
+ value
|
||||
+ "' is not a valid input. It must be in the 'ChangeNumber[,PatchsetNumber]' format.");
|
||||
}
|
||||
}
|
||||
throw new QueryParseException(
|
||||
"'cherrypickof' operator is not supported by change index version");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<ChangeData> defaultField(String query) throws QueryParseException {
|
||||
if (query.startsWith("refs/")) {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2019 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.server.query.change;
|
||||
|
||||
import com.google.gerrit.server.index.change.ChangeField;
|
||||
|
||||
public class CherryPickOfChangePredicate extends ChangeIndexPredicate {
|
||||
public CherryPickOfChangePredicate(String cherryPickOfChange) {
|
||||
super(ChangeField.CHERRY_PICK_OF_CHANGE, cherryPickOfChange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(ChangeData cd) {
|
||||
if (cd.change().getCherryPickOf() == null) {
|
||||
return false;
|
||||
}
|
||||
return Integer.toString(cd.change().getCherryPickOf().changeId().get()).equals(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCost() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2019 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.server.query.change;
|
||||
|
||||
import com.google.gerrit.server.index.change.ChangeField;
|
||||
|
||||
public class CherryPickOfPatchSetPredicate extends ChangeIndexPredicate {
|
||||
public CherryPickOfPatchSetPredicate(String cherryPickOfPatchSet) {
|
||||
super(ChangeField.CHERRY_PICK_OF_PATCHSET, cherryPickOfPatchSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(ChangeData cd) {
|
||||
if (cd.change().getCherryPickOf() == null) {
|
||||
return false;
|
||||
}
|
||||
return cd.change().getCherryPickOf().getId().equals(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCost() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user