summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-11-25 13:02:20 -0500
committerJames Moger <james.moger@gitblit.com>2013-12-03 10:36:19 -0500
commitc6f3d01c29bb67156b8154bfe5780537b0ef43ac (patch)
tree9af2cdf8bc2137d937d48ef78ecd0971e9f7e7a6 /src/main/java/com/gitblit
parentb6976fc0a4b1fd07e1e72fdd06597a0ffb9d48ef (diff)
downloadgitblit-c6f3d01c29bb67156b8154bfe5780537b0ef43ac.tar.gz
gitblit-c6f3d01c29bb67156b8154bfe5780537b0ef43ac.zip
Add support for per-repository bugtraq configuration
Imported the reference implementation contributed by syntevo which is used in their SmartGit product. You may create a bugtraq config section inf your .git/config file OR you may add a .gitbugtraq file to the root of your repository. Example: [bugtraq "issues"] url = http://code.google.com/p/gitblit/issues/detail?id=%BUGID% logRegex = "[Ii]ssue[-#:\\s]{1}\\d+" logRegex1 = "\\d+" [bugtraq "[pullrequests"] url = "https://github.com/gitblit/gitblit/pull/%BUGID%" logRegex = "(?:pull request|pull|pr)\\s*[-#]?([0-9]+)" Change-Id: Iaba305bf4280d08cc4d1abf533c2f1365470a43f
Diffstat (limited to 'src/main/java/com/gitblit')
-rw-r--r--src/main/java/com/gitblit/servlet/SyndicationServlet.java2
-rw-r--r--src/main/java/com/gitblit/utils/MessageProcessor.java59
-rw-r--r--src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java2
-rw-r--r--src/main/java/com/gitblit/wicket/pages/CommitPage.java6
-rw-r--r--src/main/java/com/gitblit/wicket/pages/RepositoryPage.java2
5 files changed, 58 insertions, 13 deletions
diff --git a/src/main/java/com/gitblit/servlet/SyndicationServlet.java b/src/main/java/com/gitblit/servlet/SyndicationServlet.java
index 739ee2d9..a35efa83 100644
--- a/src/main/java/com/gitblit/servlet/SyndicationServlet.java
+++ b/src/main/java/com/gitblit/servlet/SyndicationServlet.java
@@ -273,7 +273,7 @@ public class SyndicationServlet extends HttpServlet {
StringUtils.encodeURL(model.name.replace('/', fsc)), commit.getName());
entry.published = commit.getCommitterIdent().getWhen();
entry.contentType = "text/html";
- String message = processor.processCommitMessage(model, commit.getFullMessage());
+ String message = processor.processCommitMessage(repository, model, commit.getFullMessage());
entry.content = message;
entry.repository = model.name;
entry.branch = objectId;
diff --git a/src/main/java/com/gitblit/utils/MessageProcessor.java b/src/main/java/com/gitblit/utils/MessageProcessor.java
index 58493de4..087187f5 100644
--- a/src/main/java/com/gitblit/utils/MessageProcessor.java
+++ b/src/main/java/com/gitblit/utils/MessageProcessor.java
@@ -15,17 +15,24 @@
*/
package com.gitblit.utils;
+import java.io.IOException;
+import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.lib.Repository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.models.RepositoryModel;
+import com.syntevo.bugtraq.BugtraqConfig;
+import com.syntevo.bugtraq.BugtraqFormatter;
+import com.syntevo.bugtraq.BugtraqFormatter.OutputHandler;
public class MessageProcessor {
@@ -44,14 +51,15 @@ public class MessageProcessor {
* This method uses the preferred renderer to transform the commit message.
*
* @param repository
+ * @param model
* @param text
* @return html version of the commit message
*/
- public String processCommitMessage(RepositoryModel repository, String text) {
- switch (repository.commitMessageRenderer) {
+ public String processCommitMessage(Repository repository, RepositoryModel model, String text) {
+ switch (model.commitMessageRenderer) {
case MARKDOWN:
try {
- String prepared = processCommitMessageRegex(repository.name, text);
+ String prepared = processCommitMessageRegex(repository, model.name, text);
return MarkdownUtils.transformMarkdown(prepared);
} catch (Exception e) {
logger.error("Failed to render commit message as markdown", e);
@@ -62,7 +70,7 @@ public class MessageProcessor {
break;
}
- return processPlainCommitMessage(repository.name, text);
+ return processPlainCommitMessage(repository, model.name, text);
}
/**
@@ -71,13 +79,14 @@ public class MessageProcessor {
*
* This method assumes the commit message is plain text.
*
+ * @param repository
* @param repositoryName
* @param text
* @return html version of the commit message
*/
- public String processPlainCommitMessage(String repositoryName, String text) {
+ public String processPlainCommitMessage(Repository repository, String repositoryName, String text) {
String html = StringUtils.escapeForHtml(text, false);
- html = processCommitMessageRegex(repositoryName, html);
+ html = processCommitMessageRegex(repository, repositoryName, html);
return StringUtils.breakLinesForHtml(html);
}
@@ -86,11 +95,12 @@ public class MessageProcessor {
* Apply globally or per-repository specified regex substitutions to the
* commit message.
*
+ * @param repository
* @param repositoryName
* @param text
* @return the processed commit message
*/
- protected String processCommitMessageRegex(String repositoryName, String text) {
+ protected String processCommitMessageRegex(Repository repository, String repositoryName, String text) {
Map<String, String> map = new HashMap<String, String>();
// global regex keys
if (settings.getBoolean(Keys.regex.global, false)) {
@@ -121,6 +131,41 @@ public class MessageProcessor {
+ definition);
}
}
+
+ try {
+ // parse bugtraq repo config
+ BugtraqConfig config = BugtraqConfig.read(repository);
+ if (config != null) {
+ BugtraqFormatter formatter = new BugtraqFormatter(config);
+ StringBuilder sb = new StringBuilder();
+ formatter.formatLogMessage(text, new BugtraqOutputHandler(sb));
+ text = sb.toString();
+ }
+ } catch (IOException e) {
+ logger.error(MessageFormat.format("Bugtraq config for {0} is invalid!", repositoryName), e);
+ } catch (ConfigInvalidException e) {
+ logger.error(MessageFormat.format("Bugtraq config for {0} is invalid!", repositoryName), e);
+ }
+
return text;
}
+
+ private class BugtraqOutputHandler implements OutputHandler {
+
+ final StringBuilder sb;
+
+ BugtraqOutputHandler(StringBuilder sb) {
+ this.sb = sb;
+ }
+
+ @Override
+ public void appendText(String text) {
+ sb.append(text);
+ }
+
+ @Override
+ public void appendLink(String name, String target) {
+ sb.append(MessageFormat.format("<a class=\"bugtraq\" href=\"{1}\">{0}</a>", name, target));
+ }
+ }
}
diff --git a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
index 5d14bfec..f3f61753 100644
--- a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
@@ -107,7 +107,7 @@ public class CommitDiffPage extends RepositoryPage {
item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef
.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
- item.add(new Label("noteContent", messageProcessor().processPlainCommitMessage(repositoryName,
+ item.add(new Label("noteContent", messageProcessor().processPlainCommitMessage(getRepository(), repositoryName,
entry.content)).setEscapeModelStrings(false));
}
};
diff --git a/src/main/java/com/gitblit/wicket/pages/CommitPage.java b/src/main/java/com/gitblit/wicket/pages/CommitPage.java
index 59422332..0998c714 100644
--- a/src/main/java/com/gitblit/wicket/pages/CommitPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/CommitPage.java
@@ -135,7 +135,7 @@ public class CommitPage extends RepositoryPage {
item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef
.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
- item.add(new Label("noteContent", messageProcessor().processPlainCommitMessage(repositoryName,
+ item.add(new Label("noteContent", messageProcessor().processPlainCommitMessage(getRepository(), repositoryName,
entry.content)).setEscapeModelStrings(false));
}
};
@@ -198,11 +198,11 @@ public class CommitPage extends RepositoryPage {
.newPathParameter(repositoryName, entry.commitId, path)));
}
-
+
// quick links
if (entry.isSubmodule()) {
item.add(new ExternalLink("raw", "").setEnabled(false));
-
+
// submodule
item.add(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils
.newPathParameter(repositoryName, entry.commitId, entry.path))
diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
index a108f922..dc0233b5 100644
--- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
@@ -516,7 +516,7 @@ public abstract class RepositoryPage extends RootPage {
protected void addFullText(String wicketId, String text) {
RepositoryModel model = getRepositoryModel();
- String content = messageProcessor().processCommitMessage(model, text);
+ String content = messageProcessor().processCommitMessage(r, model, text);
String html;
switch (model.commitMessageRenderer) {
case MARKDOWN: