Support for --file option for ssh queries.
Allows user to list files and attributes (ADDED, MODIFIED, DELETED, RENAMED, COPIED) when querying for patch sets. Should provide an easy mechanism for some CI systems to trigger only on certain file changes in larger repositories. Change-Id: I61b5203bc1ad1aec9c7d4458a44c207b99a1c4e3
This commit is contained in:
@@ -12,6 +12,7 @@ SYNOPSIS
|
||||
[--format {TEXT | JSON}]
|
||||
[--current-patch-set]
|
||||
[--patch-sets | --all-approvals]
|
||||
[--files]
|
||||
[--comments]
|
||||
[--]
|
||||
<query>
|
||||
@@ -59,6 +60,10 @@ OPTIONS
|
||||
the --current-patch-set flag then the current patch set
|
||||
information will be output twice, once in each field.
|
||||
|
||||
--files::
|
||||
Support for listing files with patch sets and their
|
||||
attributes (ADDED, MODIFIED, DELETED, RENAMED, COPIED).
|
||||
|
||||
--comments::
|
||||
Include comments for all changes. If combined with the
|
||||
--patch-sets flag then all in-line comments are included for
|
||||
|
@@ -26,6 +26,9 @@ import com.google.gerrit.reviewdb.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.TrackingId;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||
import com.google.gerrit.server.patch.PatchList;
|
||||
import com.google.gerrit.server.patch.PatchListCache;
|
||||
import com.google.gerrit.server.patch.PatchListEntry;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -43,14 +46,17 @@ public class EventFactory {
|
||||
private final AccountCache accountCache;
|
||||
private final Provider<String> urlProvider;
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final PatchListCache patchListCache;
|
||||
|
||||
@Inject
|
||||
EventFactory(AccountCache accountCache,
|
||||
@CanonicalWebUrl @Nullable Provider<String> urlProvider,
|
||||
ApprovalTypes approvalTypes) {
|
||||
ApprovalTypes approvalTypes,
|
||||
PatchListCache patchListCache) {
|
||||
this.accountCache = accountCache;
|
||||
this.urlProvider = urlProvider;
|
||||
this.approvalTypes = approvalTypes;
|
||||
this.patchListCache = patchListCache;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,11 +120,18 @@ public class EventFactory {
|
||||
}
|
||||
|
||||
public void addPatchSets(ChangeAttribute a, Collection<PatchSet> ps) {
|
||||
addPatchSets(a, ps, null);
|
||||
addPatchSets(a, ps, null, false, null);
|
||||
}
|
||||
|
||||
public void addPatchSets(ChangeAttribute ca, Collection<PatchSet> ps,
|
||||
Map<PatchSet.Id,Collection<PatchSetApproval>> approvals) {
|
||||
addPatchSets(ca, ps, approvals, false, null);
|
||||
}
|
||||
|
||||
public void addPatchSets(ChangeAttribute ca, Collection<PatchSet> ps,
|
||||
Map<PatchSet.Id,Collection<PatchSetApproval>> approvals,
|
||||
boolean includeFiles, Change change) {
|
||||
|
||||
if (!ps.isEmpty()) {
|
||||
ca.patchSets = new ArrayList<PatchSetAttribute>(ps.size());
|
||||
for (PatchSet p : ps) {
|
||||
@@ -127,6 +140,9 @@ public class EventFactory {
|
||||
addApprovals(psa, p.getId(), approvals);
|
||||
}
|
||||
ca.patchSets.add(psa);
|
||||
if (includeFiles && change != null) {
|
||||
addPatchSetFileNames(psa, change, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,6 +161,21 @@ public class EventFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public void addPatchSetFileNames(PatchSetAttribute patchSetAttribute,
|
||||
Change change, PatchSet patchSet) {
|
||||
PatchList patchList = patchListCache.get(change, patchSet);
|
||||
for (PatchListEntry patch : patchList.getPatches()) {
|
||||
if (patchSetAttribute.files == null) {
|
||||
patchSetAttribute.files = new ArrayList<PatchAttribute>();
|
||||
}
|
||||
|
||||
PatchAttribute p = new PatchAttribute();
|
||||
p.file = patch.getNewName();
|
||||
p.type = patch.getChangeType();
|
||||
patchSetAttribute.files.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void addComments(ChangeAttribute ca,
|
||||
Collection<ChangeMessage> messages) {
|
||||
if (!messages.isEmpty()) {
|
||||
|
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2011 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.events;
|
||||
|
||||
import com.google.gerrit.reviewdb.Patch.ChangeType;
|
||||
|
||||
public class PatchAttribute {
|
||||
public String file;
|
||||
public ChangeType type;
|
||||
}
|
@@ -25,4 +25,5 @@ public class PatchSetAttribute {
|
||||
|
||||
public List<ApprovalAttribute> approvals;
|
||||
public List<PatchSetCommentAttribute> comments;
|
||||
public List<PatchAttribute> files;
|
||||
}
|
||||
|
@@ -73,6 +73,7 @@ public class QueryProcessor {
|
||||
private boolean includeCurrentPatchSet;
|
||||
private boolean includeApprovals;
|
||||
private boolean includeComments;
|
||||
private boolean includeFiles;
|
||||
|
||||
private OutputStream outputStream = DisabledOutputStream.INSTANCE;
|
||||
private PrintWriter out;
|
||||
@@ -106,6 +107,10 @@ public class QueryProcessor {
|
||||
includeComments = on;
|
||||
}
|
||||
|
||||
public void setIncludeFiles(boolean on) {
|
||||
includeFiles = on;
|
||||
}
|
||||
|
||||
public void setOutput(OutputStream out, OutputFormat fmt) {
|
||||
this.outputStream = out;
|
||||
this.outputFormat = fmt;
|
||||
@@ -173,8 +178,14 @@ public class QueryProcessor {
|
||||
eventFactory.addTrackingIds(c, d.trackingIds(db));
|
||||
|
||||
if (includePatchSets) {
|
||||
eventFactory.addPatchSets(c, d.patches(db),
|
||||
includeApprovals ? d.approvalsMap(db) : null);
|
||||
if (includeFiles) {
|
||||
eventFactory.addPatchSets(c, d.patches(db),
|
||||
includeApprovals ? d.approvalsMap(db) : null,
|
||||
includeFiles, d.change(db));
|
||||
} else {
|
||||
eventFactory.addPatchSets(c, d.patches(db),
|
||||
includeApprovals ? d.approvalsMap(db) : null);
|
||||
}
|
||||
}
|
||||
|
||||
if (includeCurrentPatchSet) {
|
||||
@@ -183,6 +194,11 @@ public class QueryProcessor {
|
||||
c.currentPatchSet = eventFactory.asPatchSetAttribute(current);
|
||||
eventFactory.addApprovals(c.currentPatchSet, //
|
||||
d.approvalsFor(db, current.getId()));
|
||||
|
||||
if (includeFiles) {
|
||||
eventFactory.addPatchSetFileNames(c.currentPatchSet,
|
||||
d.change(db), d.currentPatchSet(db));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -56,6 +56,11 @@ class Query extends BaseCommand {
|
||||
processor.setIncludeComments(on);
|
||||
}
|
||||
|
||||
@Option(name = "--files", usage = "Include file list on patch sets")
|
||||
void setFiles(boolean on) {
|
||||
processor.setIncludeFiles(on);
|
||||
}
|
||||
|
||||
@Argument(index = 0, required = true, multiValued = true, metaVar = "QUERY", usage = "Query to execute")
|
||||
private List<String> query;
|
||||
|
||||
|
Reference in New Issue
Block a user