diff options
author | James Moger <james.moger@gitblit.com> | 2014-03-04 13:37:12 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-03-04 13:37:12 -0500 |
commit | fef2341943be0a964922a1d504af8e282515af88 (patch) | |
tree | a77e65ab24e5ea13ad6d087496b8f1f1046307eb | |
parent | 5d0f712133cdda37aa43771022e1c681e946d594 (diff) | |
download | gitblit-fef2341943be0a964922a1d504af8e282515af88.tar.gz gitblit-fef2341943be0a964922a1d504af8e282515af88.zip |
Process bugtraq configuration in markup document rendering
-rw-r--r-- | .gitbugtraq | 6 | ||||
-rw-r--r-- | src/main/java/com/gitblit/servlet/SyndicationServlet.java | 4 | ||||
-rw-r--r-- | src/main/java/com/gitblit/utils/BugtraqProcessor.java (renamed from src/main/java/com/gitblit/utils/MessageProcessor.java) | 28 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java | 2 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/CommitPage.java | 2 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/DocPage.java | 4 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/RepositoryPage.java | 8 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/TicketPage.java | 2 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/TicketsPage.java | 2 |
9 files changed, 41 insertions, 17 deletions
diff --git a/.gitbugtraq b/.gitbugtraq index cd5b228d..21f08589 100644 --- a/.gitbugtraq +++ b/.gitbugtraq @@ -8,3 +8,9 @@ loglinkregex = "(?:pull request|pull|pr)\\s*[-#]?[0-9]+"
logregex = "\\d+"
loglinktext = "pull request #%BUGID%"
+[bugtraq "tickets"]
+ url = "https://dev.gitblit.com/tickets/gitblit.git/%BUGID%"
+ loglinkregex = "(?:ticket)\\s*[-#]?[0-9]+"
+ logregex = "\\d+"
+ loglinktext = "ticket #%BUGID%"
+
\ No newline at end of file diff --git a/src/main/java/com/gitblit/servlet/SyndicationServlet.java b/src/main/java/com/gitblit/servlet/SyndicationServlet.java index 66ca4a19..24def995 100644 --- a/src/main/java/com/gitblit/servlet/SyndicationServlet.java +++ b/src/main/java/com/gitblit/servlet/SyndicationServlet.java @@ -40,9 +40,9 @@ import com.gitblit.models.RefModel; import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.servlet.AuthenticationFilter.AuthenticatedRequest;
+import com.gitblit.utils.BugtraqProcessor;
import com.gitblit.utils.HttpUtils;
import com.gitblit.utils.JGitUtils;
-import com.gitblit.utils.MessageProcessor;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.SyndicationUtils;
@@ -257,7 +257,7 @@ public class SyndicationServlet extends DaggerServlet { offset, length);
}
Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository, model.showRemoteBranches);
- MessageProcessor processor = new MessageProcessor(settings);
+ BugtraqProcessor processor = new BugtraqProcessor(settings);
// convert RevCommit to SyndicatedEntryModel
for (RevCommit commit : commits) {
diff --git a/src/main/java/com/gitblit/utils/MessageProcessor.java b/src/main/java/com/gitblit/utils/BugtraqProcessor.java index c38e0e85..67f220f6 100644 --- a/src/main/java/com/gitblit/utils/MessageProcessor.java +++ b/src/main/java/com/gitblit/utils/BugtraqProcessor.java @@ -34,13 +34,13 @@ import com.syntevo.bugtraq.BugtraqConfig; import com.syntevo.bugtraq.BugtraqFormatter; import com.syntevo.bugtraq.BugtraqFormatter.OutputHandler; -public class MessageProcessor { +public class BugtraqProcessor { private final Logger logger = LoggerFactory.getLogger(getClass()); private final IStoredSettings settings; - public MessageProcessor(IStoredSettings settings) { + public BugtraqProcessor(IStoredSettings settings) { this.settings = settings; } @@ -59,7 +59,7 @@ public class MessageProcessor { switch (model.commitMessageRenderer) { case MARKDOWN: try { - String prepared = processCommitMessageRegex(repository, model.name, text); + String prepared = processTextRegex(repository, model.name, text); return MarkdownUtils.transformMarkdown(prepared); } catch (Exception e) { logger.error("Failed to render commit message as markdown", e); @@ -86,21 +86,35 @@ public class MessageProcessor { */ public String processPlainCommitMessage(Repository repository, String repositoryName, String text) { String html = StringUtils.escapeForHtml(text, false); - html = processCommitMessageRegex(repository, repositoryName, html); + html = processTextRegex(repository, repositoryName, html); return StringUtils.breakLinesForHtml(html); } /** + * Returns an processed version of the text with any global or + * repository-specific regular expression substitution applied. + * + * @param repository + * @param repositoryName + * @param text + * @return processed version of the text + */ + public String processText(Repository repository, String repositoryName, String text) { + String html = processTextRegex(repository, repositoryName, text); + return html; + } + + /** * Apply globally or per-repository specified regex substitutions to the - * commit message. + * text. * * @param repository * @param repositoryName * @param text - * @return the processed commit message + * @return the processed text */ - protected String processCommitMessageRegex(Repository repository, String repositoryName, String text) { + protected String processTextRegex(Repository repository, String repositoryName, String text) { Map<String, String> map = new HashMap<String, String>(); // global regex keys if (settings.getBoolean(Keys.regex.global, false)) { diff --git a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java index f3f61753..7f2a8a61 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(getRepository(), repositoryName, + item.add(new Label("noteContent", bugtraqProcessor().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 0998c714..8bc98489 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(getRepository(), repositoryName,
+ item.add(new Label("noteContent", bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName,
entry.content)).setEscapeModelStrings(false));
}
};
diff --git a/src/main/java/com/gitblit/wicket/pages/DocPage.java b/src/main/java/com/gitblit/wicket/pages/DocPage.java index 03d23372..875765ff 100644 --- a/src/main/java/com/gitblit/wicket/pages/DocPage.java +++ b/src/main/java/com/gitblit/wicket/pages/DocPage.java @@ -24,6 +24,7 @@ import org.apache.wicket.markup.html.panel.Fragment; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
+import com.gitblit.utils.BugtraqProcessor;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.CacheControl;
@@ -66,6 +67,9 @@ public class DocPage extends RepositoryPage { }
}
+ BugtraqProcessor bugtraq = new BugtraqProcessor(app().settings());
+ markupText = bugtraq.processText(getRepository(), repositoryName, markupText);
+
Fragment fragment;
MarkupDocument markupDoc = processor.parse(repositoryName, getBestCommitId(commit), documentPath, markupText);
if (MarkupSyntax.PLAIN.equals(markupDoc.syntax)) {
diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java index 86df4565..59cbdc89 100644 --- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java @@ -58,9 +58,9 @@ import com.gitblit.servlet.PagesServlet; import com.gitblit.servlet.SyndicationServlet;
import com.gitblit.tickets.TicketIndexer.Lucene;
import com.gitblit.utils.ArrayUtils;
+import com.gitblit.utils.BugtraqProcessor;
import com.gitblit.utils.DeepCopier;
import com.gitblit.utils.JGitUtils;
-import com.gitblit.utils.MessageProcessor;
import com.gitblit.utils.RefLogUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.CacheControl;
@@ -177,8 +177,8 @@ public abstract class RepositoryPage extends RootPage { return getClass();
}
- protected MessageProcessor messageProcessor() {
- return new MessageProcessor(app().settings());
+ protected BugtraqProcessor bugtraqProcessor() {
+ return new BugtraqProcessor(app().settings());
}
private Map<String, PageRegistration> registerPages() {
@@ -531,7 +531,7 @@ public abstract class RepositoryPage extends RootPage { protected void addFullText(String wicketId, String text) {
RepositoryModel model = getRepositoryModel();
- String content = messageProcessor().processCommitMessage(r, model, text);
+ String content = bugtraqProcessor().processCommitMessage(r, model, text);
String html;
switch (model.commitMessageRenderer) {
case MARKDOWN:
diff --git a/src/main/java/com/gitblit/wicket/pages/TicketPage.java b/src/main/java/com/gitblit/wicket/pages/TicketPage.java index 0d60ec20..3eb88dd5 100644 --- a/src/main/java/com/gitblit/wicket/pages/TicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TicketPage.java @@ -491,7 +491,7 @@ public class TicketPage extends TicketBasePage { add(new Label("ticketTopic").setVisible(false));
} else {
// process the topic using the bugtraq config to link things
- String topic = messageProcessor().processPlainCommitMessage(getRepository(), repositoryName, ticket.topic);
+ String topic = bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName, ticket.topic);
add(new Label("ticketTopic", topic).setEscapeModelStrings(false));
}
diff --git a/src/main/java/com/gitblit/wicket/pages/TicketsPage.java b/src/main/java/com/gitblit/wicket/pages/TicketsPage.java index 525658c5..2d60481f 100644 --- a/src/main/java/com/gitblit/wicket/pages/TicketsPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TicketsPage.java @@ -529,7 +529,7 @@ public class TicketsPage extends TicketBasePage { @Override
public void populateItem(final Item<String> labelItem) {
- String content = messageProcessor().processPlainCommitMessage(getRepository(), repositoryName, labelItem.getModelObject());
+ String content = bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName, labelItem.getModelObject());
Label label = new Label("label", content);
label.setEscapeModelStrings(false);
TicketLabel tLabel = app().tickets().getLabel(getRepositoryModel(), labelItem.getModelObject());
|