Add change subject to the commit message
... of the snapshot manifest
Change-Id: I112f14c87dd38217cc7d1eaa23d4877e7fcd675f
diff --git a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ManifestSubscription.java b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ManifestSubscription.java
index 70873c4..b7bc738 100644
--- a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ManifestSubscription.java
+++ b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ManifestSubscription.java
@@ -28,6 +28,8 @@
import org.eclipse.jgit.errors.ConfigInvalidException;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -147,6 +149,24 @@
Manifest manifest = manifestStores.get(store, storeBranch);
String manifestSrc = manifestSource.get(store, storeBranch);
+ StringBuilder extraCommitMsg = new StringBuilder();
+
+ try {
+ Project.NameKey p = new Project.NameKey(projectName);
+ Repository r = gitRepoManager.openRepository(p);
+ RevWalk walk = new RevWalk(r);
+ RevCommit c = walk.parseCommit(
+ ObjectId.fromString(event.getNewObjectId()));
+
+ extraCommitMsg.append(event.getNewObjectId().substring(0,7));
+ extraCommitMsg.append(" ");
+ extraCommitMsg.append(projectName);
+ extraCommitMsg.append(" ");
+ extraCommitMsg.append(c.getShortMessage());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
// these are project from the above manifest previously
// cached in the lookup table
for (com.amd.gerrit.plugins.manifestsubscription.manifest.Project
@@ -156,7 +176,7 @@
try {
updateManifest(store, STORE_BRANCH_PREFIX + storeBranch,
- manifest, manifestSrc);
+ manifest, manifestSrc, extraCommitMsg.toString());
} catch (JAXBException | IOException e) {
e.printStackTrace();
}
@@ -426,6 +446,13 @@
private void updateManifest(String projectName, String refName,
Manifest manifest, String manifestSrc)
throws JAXBException, IOException {
+ updateManifest(projectName, refName, manifest, manifestSrc, "");
+ }
+
+ private void updateManifest(String projectName, String refName,
+ Manifest manifest, String manifestSrc,
+ String extraCommitMsg)
+ throws JAXBException, IOException {
Project.NameKey p = new Project.NameKey(projectName);
MetaDataUpdate update = metaDataUpdateFactory.create(p);
VersionedManifests vManifests = new VersionedManifests(refName);
@@ -443,6 +470,7 @@
entry.put("default.xml", manifest);
vManifests.setManifests(entry);
vManifests.setSrcManifestRepo(manifestSrc);
+ vManifests.setExtraCommitMsg(extraCommitMsg);
vManifests.commit(update);
} else {
vManifests = new VersionedManifests("master");
diff --git a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifests.java b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifests.java
index 99a255a..13ef9f7 100644
--- a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifests.java
+++ b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifests.java
@@ -47,6 +47,15 @@
private Marshaller manifestMarshaller;
private Map<String, Manifest> manifests;
private String srcManifestRepo = "";
+ private String extraCommitMsg = "";
+
+ public String getExtraCommitMsg() {
+ return extraCommitMsg;
+ }
+
+ public void setExtraCommitMsg(String extraCommitMsg) {
+ this.extraCommitMsg = extraCommitMsg;
+ }
public String getSrcManifestRepo() {
return srcManifestRepo;
@@ -141,6 +150,10 @@
commitMsg.append("Snapshot manifest from " +
srcManifestRepo + " updated\n\n");
+ if (extraCommitMsg != null && extraCommitMsg.length() > 0) {
+ commitMsg.append(extraCommitMsg);
+ }
+
String path;
Manifest manifest;
for (Map.Entry<String, Manifest> entry : manifests.entrySet()) {