From 27ae9095639bb228a1b7ff86a3ebe4264abf05be Mon Sep 17 00:00:00 2001
From: mschaefers <mschaefers@scoop-gmbh.de>
Date: Thu, 29 Nov 2012 12:33:09 -0500
Subject: [PATCH] feature: when using LdapUserService one can configure Gitblit to fetch all users from ldap that can possibly login. This allows to see newly generated LDAP users instantly in Gitblit. By now an LDAP user had to log in once to appear in GitBlit.
---
src/com/gitblit/utils/TicgitUtils.java | 82 ++++++++++++++++++++++++-----------------
1 files changed, 48 insertions(+), 34 deletions(-)
diff --git a/src/com/gitblit/utils/TicgitUtils.java b/src/com/gitblit/utils/TicgitUtils.java
index 48e8558..aab5a3e 100644
--- a/src/com/gitblit/utils/TicgitUtils.java
+++ b/src/com/gitblit/utils/TicgitUtils.java
@@ -30,49 +30,46 @@
import com.gitblit.models.TicketModel;
import com.gitblit.models.TicketModel.Comment;
+/**
+ * Utility class for reading Ticgit issues.
+ *
+ * @author James Moger
+ *
+ */
public class TicgitUtils {
static final Logger LOGGER = LoggerFactory.getLogger(TicgitUtils.class);
- public static RefModel getTicketsBranch(Repository r) {
- RefModel ticgitBranch = null;
- try {
- // search for ticgit branch in local heads
- for (RefModel ref : JGitUtils.getLocalBranches(r, false, -1)) {
- if (ref.displayName.endsWith("ticgit")) {
- ticgitBranch = ref;
- break;
- }
- }
-
- // search for ticgit branch in remote heads
- if (ticgitBranch == null) {
- for (RefModel ref : JGitUtils.getRemoteBranches(r, false, -1)) {
- if (ref.displayName.endsWith("ticgit")) {
- ticgitBranch = ref;
- break;
- }
- }
- }
- } catch (Throwable t) {
- LOGGER.error("Failed to find ticgit branch!", t);
- }
- return ticgitBranch;
+ /**
+ * Returns a RefModel for the Ticgit branch in the repository. If the branch
+ * can not be found, null is returned.
+ *
+ * @param repository
+ * @return a refmodel for the ticgit branch or null
+ */
+ public static RefModel getTicketsBranch(Repository repository) {
+ return JGitUtils.getBranch(repository, "ticgit");
}
- public static List<TicketModel> getTickets(Repository r) {
- RefModel ticgitBranch = getTicketsBranch(r);
+ /**
+ * Returns a list of all tickets in the ticgit branch of the repository.
+ *
+ * @param repository
+ * @return list of tickets
+ */
+ public static List<TicketModel> getTickets(Repository repository) {
+ RefModel ticgitBranch = getTicketsBranch(repository);
if (ticgitBranch == null) {
return null;
}
RevCommit commit = (RevCommit) ticgitBranch.referencedObject;
- List<PathModel> paths = JGitUtils.getFilesInPath(r, null, commit);
+ List<PathModel> paths = JGitUtils.getFilesInPath(repository, null, commit);
List<TicketModel> tickets = new ArrayList<TicketModel>();
for (PathModel ticketFolder : paths) {
if (ticketFolder.isTree()) {
try {
TicketModel t = new TicketModel(ticketFolder.name);
- readTicketContents(r, ticgitBranch, t);
+ loadTicketContents(repository, ticgitBranch, t);
tickets.add(t);
} catch (Throwable t) {
LOGGER.error("Failed to get a ticket!", t);
@@ -84,12 +81,20 @@
return tickets;
}
- public static TicketModel getTicket(Repository r, String ticketFolder) {
- RefModel ticketsBranch = getTicketsBranch(r);
+ /**
+ * Returns a TicketModel for the specified ticgit ticket. Returns null if
+ * the ticket does not exist or some other error occurs.
+ *
+ * @param repository
+ * @param ticketFolder
+ * @return a ticket
+ */
+ public static TicketModel getTicket(Repository repository, String ticketFolder) {
+ RefModel ticketsBranch = getTicketsBranch(repository);
if (ticketsBranch != null) {
try {
TicketModel ticket = new TicketModel(ticketFolder);
- readTicketContents(r, ticketsBranch, ticket);
+ loadTicketContents(repository, ticketsBranch, ticket);
return ticket;
} catch (Throwable t) {
LOGGER.error("Failed to get ticket " + ticketFolder, t);
@@ -98,11 +103,20 @@
return null;
}
- private static void readTicketContents(Repository r, RefModel ticketsBranch, TicketModel ticket) {
+ /**
+ * Loads the contents of the ticket.
+ *
+ * @param repository
+ * @param ticketsBranch
+ * @param ticket
+ */
+ private static void loadTicketContents(Repository repository, RefModel ticketsBranch,
+ TicketModel ticket) {
RevCommit commit = (RevCommit) ticketsBranch.referencedObject;
- List<PathModel> ticketFiles = JGitUtils.getFilesInPath(r, ticket.name, commit);
+ List<PathModel> ticketFiles = JGitUtils.getFilesInPath(repository, ticket.name, commit);
for (PathModel file : ticketFiles) {
- String content = JGitUtils.getStringContent(r, commit.getTree(), file.path).trim();
+ String content = JGitUtils.getStringContent(repository, commit.getTree(), file.path)
+ .trim();
if (file.name.equals("TICKET_ID")) {
ticket.id = content;
} else if (file.name.equals("TITLE")) {
--
Gitblit v1.9.1