Output full commit message in query results
If the user adds a flag to the query parameters, include the full commit message in the result data. This is helpful when verifying commit messages and with similar tasks. Change-Id: Iff93bfebfa0c5e2209be29fe60ae12809a76479a
This commit is contained in:
@@ -14,6 +14,7 @@ SYNOPSIS
|
|||||||
[--patch-sets | --all-approvals]
|
[--patch-sets | --all-approvals]
|
||||||
[--files]
|
[--files]
|
||||||
[--comments]
|
[--comments]
|
||||||
|
[--commit-message]
|
||||||
[--]
|
[--]
|
||||||
<query>
|
<query>
|
||||||
[limit:<n>]
|
[limit:<n>]
|
||||||
@@ -69,6 +70,9 @@ OPTIONS
|
|||||||
--patch-sets flag then all in-line comments are included for
|
--patch-sets flag then all in-line comments are included for
|
||||||
each patch set.
|
each patch set.
|
||||||
|
|
||||||
|
--commit-message::
|
||||||
|
Include the full commit message in the change description.
|
||||||
|
|
||||||
limit:<n>::
|
limit:<n>::
|
||||||
Maximum number of results to return. This is actually a
|
Maximum number of results to return. This is actually a
|
||||||
query operator, and not a command line option. If more
|
query operator, and not a command line option. If more
|
||||||
|
@@ -28,6 +28,8 @@ owner:: Owner in <<account,account attribute>>
|
|||||||
|
|
||||||
url:: Canonical URL to reach this change
|
url:: Canonical URL to reach this change
|
||||||
|
|
||||||
|
commitMessage:: The full commit message for the change.
|
||||||
|
|
||||||
lastUpdated:: Time in seconds since the UNIX epoch when this change
|
lastUpdated:: Time in seconds since the UNIX epoch when this change
|
||||||
was last updated.
|
was last updated.
|
||||||
|
|
||||||
|
@@ -27,6 +27,7 @@ public class ChangeAttribute {
|
|||||||
public String subject;
|
public String subject;
|
||||||
public AccountAttribute owner;
|
public AccountAttribute owner;
|
||||||
public String url;
|
public String url;
|
||||||
|
public String commitMessage;
|
||||||
|
|
||||||
public Long createdOn;
|
public Long createdOn;
|
||||||
public Long lastUpdated;
|
public Long lastUpdated;
|
||||||
|
@@ -119,6 +119,10 @@ public class EventFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addCommitMessage(ChangeAttribute a, String commitMessage) {
|
||||||
|
a.commitMessage = commitMessage;
|
||||||
|
}
|
||||||
|
|
||||||
public void addPatchSets(ChangeAttribute a, Collection<PatchSet> ps) {
|
public void addPatchSets(ChangeAttribute a, Collection<PatchSet> ps) {
|
||||||
addPatchSets(a, ps, null, false, null);
|
addPatchSets(a, ps, null, false, null);
|
||||||
}
|
}
|
||||||
|
@@ -20,15 +20,23 @@ import com.google.gerrit.reviewdb.Patch;
|
|||||||
import com.google.gerrit.reviewdb.PatchLineComment;
|
import com.google.gerrit.reviewdb.PatchLineComment;
|
||||||
import com.google.gerrit.reviewdb.PatchSet;
|
import com.google.gerrit.reviewdb.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.PatchSetApproval;
|
import com.google.gerrit.reviewdb.PatchSetApproval;
|
||||||
|
import com.google.gerrit.reviewdb.Project;
|
||||||
import com.google.gerrit.reviewdb.ReviewDb;
|
import com.google.gerrit.reviewdb.ReviewDb;
|
||||||
import com.google.gerrit.reviewdb.TrackingId;
|
import com.google.gerrit.reviewdb.TrackingId;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.patch.PatchList;
|
import com.google.gerrit.server.patch.PatchList;
|
||||||
import com.google.gerrit.server.patch.PatchListCache;
|
import com.google.gerrit.server.patch.PatchListCache;
|
||||||
import com.google.gerrit.server.patch.PatchListEntry;
|
import com.google.gerrit.server.patch.PatchListEntry;
|
||||||
import com.google.gwtorm.client.OrmException;
|
import com.google.gwtorm.client.OrmException;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
|
import org.eclipse.jgit.lib.Repository;
|
||||||
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -40,6 +48,7 @@ import java.util.Map;
|
|||||||
public class ChangeData {
|
public class ChangeData {
|
||||||
private final Change.Id legacyId;
|
private final Change.Id legacyId;
|
||||||
private Change change;
|
private Change change;
|
||||||
|
private String commitMessage;
|
||||||
private Collection<PatchSet> patches;
|
private Collection<PatchSet> patches;
|
||||||
private Collection<PatchSetApproval> approvals;
|
private Collection<PatchSetApproval> approvals;
|
||||||
private Map<PatchSet.Id,Collection<PatchSetApproval>> approvalsMap;
|
private Map<PatchSet.Id,Collection<PatchSetApproval>> approvalsMap;
|
||||||
@@ -164,6 +173,28 @@ public class ChangeData {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String commitMessage(GitRepositoryManager repoManager,
|
||||||
|
Provider<ReviewDb> db) throws IOException, OrmException {
|
||||||
|
if (commitMessage == null) {
|
||||||
|
PatchSet.Id psId = change(db).currentPatchSetId();
|
||||||
|
String sha1 = db.get().patchSets().get(psId).getRevision().get();
|
||||||
|
Project.NameKey name = change.getProject();
|
||||||
|
Repository repo = repoManager.openRepository(name);
|
||||||
|
try {
|
||||||
|
RevWalk walk = new RevWalk(repo);
|
||||||
|
try {
|
||||||
|
RevCommit c = walk.parseCommit(ObjectId.fromString(sha1));
|
||||||
|
commitMessage = c.getFullMessage();
|
||||||
|
} finally {
|
||||||
|
walk.release();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
repo.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commitMessage;
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<PatchSet> patches(Provider<ReviewDb> db)
|
public Collection<PatchSet> patches(Provider<ReviewDb> db)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
if (patches == null) {
|
if (patches == null) {
|
||||||
|
@@ -23,6 +23,7 @@ import com.google.gerrit.server.events.ChangeAttribute;
|
|||||||
import com.google.gerrit.server.events.EventFactory;
|
import com.google.gerrit.server.events.EventFactory;
|
||||||
import com.google.gerrit.server.events.PatchSetAttribute;
|
import com.google.gerrit.server.events.PatchSetAttribute;
|
||||||
import com.google.gerrit.server.events.QueryStats;
|
import com.google.gerrit.server.events.QueryStats;
|
||||||
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.query.Predicate;
|
import com.google.gerrit.server.query.Predicate;
|
||||||
import com.google.gerrit.server.query.QueryParseException;
|
import com.google.gerrit.server.query.QueryParseException;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -66,6 +67,7 @@ public class QueryProcessor {
|
|||||||
private final ChangeQueryBuilder queryBuilder;
|
private final ChangeQueryBuilder queryBuilder;
|
||||||
private final ChangeQueryRewriter queryRewriter;
|
private final ChangeQueryRewriter queryRewriter;
|
||||||
private final Provider<ReviewDb> db;
|
private final Provider<ReviewDb> db;
|
||||||
|
private final GitRepositoryManager repoManager;
|
||||||
private final int maxLimit;
|
private final int maxLimit;
|
||||||
|
|
||||||
private OutputFormat outputFormat = OutputFormat.TEXT;
|
private OutputFormat outputFormat = OutputFormat.TEXT;
|
||||||
@@ -74,6 +76,7 @@ public class QueryProcessor {
|
|||||||
private boolean includeApprovals;
|
private boolean includeApprovals;
|
||||||
private boolean includeComments;
|
private boolean includeComments;
|
||||||
private boolean includeFiles;
|
private boolean includeFiles;
|
||||||
|
private boolean includeCommitMessage;
|
||||||
|
|
||||||
private OutputStream outputStream = DisabledOutputStream.INSTANCE;
|
private OutputStream outputStream = DisabledOutputStream.INSTANCE;
|
||||||
private PrintWriter out;
|
private PrintWriter out;
|
||||||
@@ -81,11 +84,13 @@ public class QueryProcessor {
|
|||||||
@Inject
|
@Inject
|
||||||
QueryProcessor(EventFactory eventFactory,
|
QueryProcessor(EventFactory eventFactory,
|
||||||
ChangeQueryBuilder.Factory queryBuilder, CurrentUser currentUser,
|
ChangeQueryBuilder.Factory queryBuilder, CurrentUser currentUser,
|
||||||
ChangeQueryRewriter queryRewriter, Provider<ReviewDb> db) {
|
ChangeQueryRewriter queryRewriter, Provider<ReviewDb> db,
|
||||||
|
GitRepositoryManager repoManager) {
|
||||||
this.eventFactory = eventFactory;
|
this.eventFactory = eventFactory;
|
||||||
this.queryBuilder = queryBuilder.create(currentUser);
|
this.queryBuilder = queryBuilder.create(currentUser);
|
||||||
this.queryRewriter = queryRewriter;
|
this.queryRewriter = queryRewriter;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
|
this.repoManager = repoManager;
|
||||||
this.maxLimit = currentUser.getCapabilities()
|
this.maxLimit = currentUser.getCapabilities()
|
||||||
.getRange(GlobalCapability.QUERY_LIMIT)
|
.getRange(GlobalCapability.QUERY_LIMIT)
|
||||||
.getMax();
|
.getMax();
|
||||||
@@ -111,6 +116,10 @@ public class QueryProcessor {
|
|||||||
includeFiles = on;
|
includeFiles = on;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIncludeCommitMessage(boolean on) {
|
||||||
|
includeCommitMessage = on;
|
||||||
|
}
|
||||||
|
|
||||||
public void setOutput(OutputStream out, OutputFormat fmt) {
|
public void setOutput(OutputStream out, OutputFormat fmt) {
|
||||||
this.outputStream = out;
|
this.outputStream = out;
|
||||||
this.outputFormat = fmt;
|
this.outputFormat = fmt;
|
||||||
@@ -177,6 +186,10 @@ public class QueryProcessor {
|
|||||||
eventFactory.extend(c, d.getChange());
|
eventFactory.extend(c, d.getChange());
|
||||||
eventFactory.addTrackingIds(c, d.trackingIds(db));
|
eventFactory.addTrackingIds(c, d.trackingIds(db));
|
||||||
|
|
||||||
|
if (includeCommitMessage) {
|
||||||
|
eventFactory.addCommitMessage(c, d.commitMessage(repoManager, db));
|
||||||
|
}
|
||||||
|
|
||||||
if (includePatchSets) {
|
if (includePatchSets) {
|
||||||
if (includeFiles) {
|
if (includeFiles) {
|
||||||
eventFactory.addPatchSets(c, d.patches(db),
|
eventFactory.addPatchSets(c, d.patches(db),
|
||||||
|
@@ -61,6 +61,11 @@ class Query extends BaseCommand {
|
|||||||
processor.setIncludeFiles(on);
|
processor.setIncludeFiles(on);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Option(name = "--commit-message", usage = "Include the full commit message for a change")
|
||||||
|
void setCommitMessage(boolean on) {
|
||||||
|
processor.setIncludeCommitMessage(on);
|
||||||
|
}
|
||||||
|
|
||||||
@Argument(index = 0, required = true, multiValued = true, metaVar = "QUERY", usage = "Query to execute")
|
@Argument(index = 0, required = true, multiValued = true, metaVar = "QUERY", usage = "Query to execute")
|
||||||
private List<String> query;
|
private List<String> query;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user