summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/tickets/BranchTicketService.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gmail.com>2014-03-05 21:50:16 -0500
committerJames Moger <james.moger@gmail.com>2014-03-05 21:50:16 -0500
commite462bbf2974d33f1a5a0b2a808e150aa0e22d6f4 (patch)
tree9bf1f678197967c9b9fce399386cbb4cc10810fb /src/main/java/com/gitblit/tickets/BranchTicketService.java
parentf0950d6f8d663612574a436c99cf098322e825f0 (diff)
downloadgitblit-e462bbf2974d33f1a5a0b2a808e150aa0e22d6f4.tar.gz
gitblit-e462bbf2974d33f1a5a0b2a808e150aa0e22d6f4.zip
Fire an event on received ticket branch updates to trigger reindex
It would be useful to be able to push a complete repository with a refs/gitblit/tickets branch and have Gitblit index all those tickets. Additionally, it would be nice for the mirroring service to recognize an incoming update to this ref and fire an event that can be processed by the BranchTicketService, if so configured, to reindex the tickets.
Diffstat (limited to 'src/main/java/com/gitblit/tickets/BranchTicketService.java')
-rw-r--r--src/main/java/com/gitblit/tickets/BranchTicketService.java35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/main/java/com/gitblit/tickets/BranchTicketService.java b/src/main/java/com/gitblit/tickets/BranchTicketService.java
index 14ed8094..60dca276 100644
--- a/src/main/java/com/gitblit/tickets/BranchTicketService.java
+++ b/src/main/java/com/gitblit/tickets/BranchTicketService.java
@@ -36,6 +36,8 @@ import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheEntry;
+import org.eclipse.jgit.events.RefsChangedEvent;
+import org.eclipse.jgit.events.RefsChangedListener;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.FileMode;
@@ -74,8 +76,20 @@ import com.gitblit.utils.StringUtils;
* @author James Moger
*
*/
-public class BranchTicketService extends ITicketService {
+public class BranchTicketService extends ITicketService implements RefsChangedListener {
+ /**
+ * The event fired by other classes to allow this service to index tickets.
+ */
+ public static class TicketsBranchUpdated extends RefsChangedEvent {
+
+ public final RepositoryModel model;
+
+ public TicketsBranchUpdated(RepositoryModel model) {
+ this.model = model;
+ }
+ }
+
public static final String BRANCH = "refs/gitblit/tickets";
private static final String JOURNAL = "journal.json";
@@ -97,6 +111,9 @@ public class BranchTicketService extends ITicketService {
repositoryManager);
lastAssignedId = new ConcurrentHashMap<String, AtomicLong>();
+
+ // register the branch ticket service for repository ref changes
+ Repository.getGlobalListenerList().addRefsChangedListener(this);
}
@Override
@@ -121,6 +138,22 @@ public class BranchTicketService extends ITicketService {
}
/**
+ * Listen for refs changed events and reindex that repository.
+ */
+ @Override
+ public void onRefsChanged(RefsChangedEvent event) {
+ if (!(event instanceof TicketsBranchUpdated)) {
+ return;
+ }
+ RepositoryModel repository = ((TicketsBranchUpdated) event).model;
+ try {
+ reindex(repository);
+ } catch (Exception e) {
+ log.error("failed to reindex " + repository.name, e);
+ }
+ }
+
+ /**
* Returns a RefModel for the refs/gitblit/tickets branch in the repository.
* If the branch can not be found, null is returned.
*