import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.tickets.BranchTicketService;\r
+import com.gitblit.tickets.BranchTicketService.TicketsBranchUpdated;\r
import com.gitblit.utils.ArrayUtils;\r
import com.gitblit.utils.ClientLogger;\r
import com.gitblit.utils.CommitCache;\r
} catch (Exception e) {\r
LOGGER.error(MessageFormat.format("Failed to update {0} pushlog", repository.name), e);\r
}\r
+ \r
+ // check for updates pushed to the BranchTicketService branch\r
+ for (ReceiveCommand cmd : commands) {\r
+ if (Result.OK.equals(cmd.getResult())\r
+ && BranchTicketService.BRANCH.equals(cmd.getRefName())) {\r
+ rp.getRepository().fireEvent(new TicketsBranchUpdated(repository));\r
+ }\r
+ }\r
\r
// run Groovy hook scripts\r
Set<String> scripts = new LinkedHashSet<String>();\r
case CREATE:\r
case UPDATE:\r
case UPDATE_NONFASTFORWARD:\r
- Collection<TicketModel> tickets = processMergedTickets(cmd);\r
- ticketsProcessed += tickets.size();\r
- for (TicketModel ticket : tickets) {\r
- ticketNotifier.queueMailing(ticket);\r
+ if (cmd.getRefName().startsWith(Constants.R_HEADS)) {\r
+ Collection<TicketModel> tickets = processMergedTickets(cmd);\r
+ ticketsProcessed += tickets.size();\r
+ for (TicketModel ticket : tickets) {\r
+ ticketNotifier.queueMailing(ticket);\r
+ }\r
}\r
break;\r
default:\r
import com.gitblit.manager.IRepositoryManager;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
+import com.gitblit.tickets.BranchTicketService;\r
+import com.gitblit.tickets.BranchTicketService.TicketsBranchUpdated;\r
import com.gitblit.utils.JGitUtils;\r
\r
/**\r
FetchResult result = git.fetch().setRemote(mirror.getName()).setDryRun(testing).call();\r
Collection<TrackingRefUpdate> refUpdates = result.getTrackingRefUpdates();\r
if (refUpdates.size() > 0) {\r
+ boolean ticketBranchUpdated = false;\r
for (TrackingRefUpdate ru : refUpdates) {\r
StringBuilder sb = new StringBuilder();\r
sb.append("updated mirror ");\r
sb.append("..");\r
sb.append(ru.getNewObjectId() == null ? "" : ru.getNewObjectId().abbreviate(7).name());\r
logger.info(sb.toString());\r
+ \r
+ if (BranchTicketService.BRANCH.equals(ru.getLocalName())) {\r
+ ticketBranchUpdated = true;\r
+ }\r
+ }\r
+ \r
+ if (ticketBranchUpdated) {\r
+ repository.fireEvent(new TicketsBranchUpdated(model));\r
}\r
}\r
} catch (Exception e) {\r
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;
* @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";
repositoryManager);
lastAssignedId = new ConcurrentHashMap<String, AtomicLong>();
+
+ // register the branch ticket service for repository ref changes
+ Repository.getGlobalListenerList().addRefsChangedListener(this);
}
@Override
protected void close() {
}
+ /**
+ * 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.