From 3daba4304dba818d54eb9b74d8d35df5aab8fee5 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Fri, 22 Nov 2013 10:36:05 -0500
Subject: [PATCH] Add pull request linking in changelog to generated documentation

---
 src/main/java/com/gitblit/wicket/panels/RefsPanel.java |   40 +++++++++++++++++++++++++++++++++-------
 1 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/gitblit/wicket/panels/RefsPanel.java b/src/main/java/com/gitblit/wicket/panels/RefsPanel.java
index 3ba22c0..7a16f4a 100644
--- a/src/main/java/com/gitblit/wicket/panels/RefsPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/RefsPanel.java
@@ -15,6 +15,7 @@
  */
 package com.gitblit.wicket.panels;
 
+import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -22,20 +23,21 @@
 import java.util.Map;
 
 import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.WebPage;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.panel.Panel;
 import org.apache.wicket.markup.repeater.Item;
 import org.apache.wicket.markup.repeater.data.DataView;
 import org.apache.wicket.markup.repeater.data.ListDataProvider;
-import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.revwalk.RevCommit;
 
+import com.gitblit.Constants;
 import com.gitblit.models.RefModel;
+import com.gitblit.utils.StringUtils;
 import com.gitblit.wicket.WicketUtils;
 import com.gitblit.wicket.pages.CommitPage;
 import com.gitblit.wicket.pages.LogPage;
-import com.gitblit.wicket.pages.RepositoryPage;
 import com.gitblit.wicket.pages.TagPage;
 
 public class RefsPanel extends Panel {
@@ -63,7 +65,7 @@
 				boolean remote2 = o2.displayName.startsWith(Constants.R_REMOTES);
 				if (remote1 && remote2) {
 					// both are remote heads, sort by name
-					return o1.displayName.compareTo(o2.displayName);	
+					return o1.displayName.compareTo(o2.displayName);
 				}
 				if (remote1) {
 					// o1 is remote, o2 comes first
@@ -77,7 +79,7 @@
 				return o1.displayName.compareTo(o2.displayName);
 			}
 		});
-		
+
 		// count remote and determine if we should insert a break
 		int remoteCount = 0;
 		for (RefModel ref : refs) {
@@ -86,19 +88,21 @@
 			}
 		}
 		final boolean shouldBreak = remoteCount < refs.size();
-		
+
 		ListDataProvider<RefModel> refsDp = new ListDataProvider<RefModel>(refs);
 		DataView<RefModel> refsView = new DataView<RefModel>("ref", refsDp) {
 			private static final long serialVersionUID = 1L;
 			private boolean alreadyInsertedBreak = !shouldBreak;
 
+			@Override
 			public void populateItem(final Item<RefModel> item) {
 				RefModel entry = item.getModelObject();
 				String name = entry.displayName;
 				String objectid = entry.getReferencedObjectId().getName();
 				boolean breakLine = false;
-				Class<? extends RepositoryPage> linkClass = CommitPage.class;
+				Class<? extends WebPage> linkClass = CommitPage.class;
 				String cssClass = "";
+				String tooltip = "";
 				if (name.startsWith(Constants.R_HEADS)) {
 					// local branch
 					linkClass = LogPage.class;
@@ -108,6 +112,24 @@
 					// local head
 					linkClass = LogPage.class;
 					cssClass = "headRef";
+				} else if (name.startsWith(Constants.R_CHANGES)) {
+					// Gerrit change ref
+					name = name.substring(Constants.R_CHANGES.length());
+					// strip leading nn/ from nn/#####nn/ps = #####nn-ps
+					name = name.substring(name.indexOf('/') + 1).replace('/', '-');
+					String [] values = name.split("-");
+					tooltip = MessageFormat.format(getString("gb.reviewPatchset"), values[0], values[1]);
+					cssClass = "otherRef";
+				} else if (name.startsWith(Constants.R_PULL)) {
+					// Pull Request ref
+					String num = name.substring(Constants.R_PULL.length());
+					if (num.endsWith("/head")) {
+						// strip pull request head from name
+						num = num.substring(0, num.length() - "/head".length());
+					}
+					name = "pr #" + num;
+					tooltip = "pull request #" + num;
+					cssClass = "pullRef";
 				} else if (name.startsWith(Constants.R_REMOTES)) {
 					// remote branch
 					linkClass = LogPage.class;
@@ -142,7 +164,11 @@
 				Component c = new LinkPanel("refName", null, name, linkClass,
 						WicketUtils.newObjectParameter(repositoryName, objectid));
 				WicketUtils.setCssClass(c, cssClass);
-				WicketUtils.setHtmlTooltip(c, name);
+				if (StringUtils.isEmpty(tooltip)) {
+					WicketUtils.setHtmlTooltip(c, name);
+				} else {
+					WicketUtils.setHtmlTooltip(c, tooltip);
+				}
 				item.add(c);
 				Label lb = new Label("lineBreak", "<br/>");
 				lb.setVisible(breakLine);

--
Gitblit v1.9.1