Skip to content

The Unified and Autonomous Development Platform

Not perfect add comment

robin shine6662c8fd6789
diff --git a/commons.loader/src/main/java/com/pmease/commons/loader/DefaultPluginManager.java b/commons.loader/src/main/java/com/pmease/commons/loader/DefaultPluginManager.java
index 2c0a4b4732..7fa4bcb9ce 100644
--- a/commons.loader/src/main/java/com/pmease/commons/loader/DefaultPluginManager.java
+++ b/commons.loader/src/main/java/com/pmease/commons/loader/DefaultPluginManager.java
@@ -7,6 +7,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ExecutorService;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -18,6 +19,8 @@ public class DefaultPluginManager implements PluginManager {
// use linked hash map here to keep plugins in order
private final Map<String, Plugin> pluginMap = new LinkedHashMap<String, Plugin>();
+ private final ExecutorService executorService;
+
/**
* Construct plugin map in dependency order. Plugins without dependencies comes first in the
* linked hash map.
@@ -25,7 +28,7 @@ public class DefaultPluginManager implements PluginManager {
* @param plugins
*/
@Inject
- public DefaultPluginManager(final Set<Plugin> plugins) {
+ public DefaultPluginManager(final Set<Plugin> plugins, final ExecutorService executorService) {
for (Plugin plugin: plugins)
pluginMap.put(plugin.getId(), plugin);
@@ -34,6 +37,8 @@ public class DefaultPluginManager implements PluginManager {
pluginMap.remove(plugin.getId());
pluginMap.put(plugin.getId(), plugin);
}
+
+ this.executorService = executorService;
}
@Override
@@ -48,6 +53,8 @@ public class DefaultPluginManager implements PluginManager {
@Override
public void stop() {
+ executorService.shutdown();
+
for (Plugin plugin: pluginMap.values())
plugin.preStop();
List<Plugin> reversed = new ArrayList<Plugin>(pluginMap.values());
diff --git a/commons.loader/src/test/java/com/pmease/commons/loader/AbstractPluginTest.java b/commons.loader/src/test/java/com/pmease/commons/loader/AbstractPluginTest.java
index bdefb0c340..22f309ab7f 100644
--- a/commons.loader/src/test/java/com/pmease/commons/loader/AbstractPluginTest.java
+++ b/commons.loader/src/test/java/com/pmease/commons/loader/AbstractPluginTest.java
@@ -5,6 +5,7 @@ import static org.mockito.Mockito.spy;
import java.util.HashSet;
import java.util.Set;
+import java.util.concurrent.Executors;
import org.junit.Before;
import org.junit.Test;
@@ -62,7 +63,7 @@ public class AbstractPluginTest {
plugins.add(plugin1);
plugins.add(plugin2);
plugins.add(plugin3);
- pluginManager = new DefaultPluginManager(plugins);
+ pluginManager = new DefaultPluginManager(plugins, Executors.newCachedThreadPool());
}
@Test
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
index 62dcb9d892..cc10af01a7 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
@@ -57,6 +57,7 @@ import com.pmease.gitplex.core.manager.impl.DefaultStorageManager;
import com.pmease.gitplex.core.manager.impl.DefaultTeamManager;
import com.pmease.gitplex.core.manager.impl.DefaultUserManager;
import com.pmease.gitplex.core.manager.impl.DefaultVerificationManager;
+import com.pmease.gitplex.core.model.Config;
import com.pmease.gitplex.core.model.ModelLocator;
import com.pmease.gitplex.core.security.SecurityRealm;
import com.pmease.gitplex.core.setting.SpecifiedGit;
@@ -158,10 +159,17 @@ public class CoreModule extends AbstractPluginModule {
contribute(RepositoryListener.class, DefaultPullRequestManager.class);
contribute(PullRequestListener.class, DefaultNotificationManager.class);
contribute(PullRequestListener.class, DefaultPullRequestWatchManager.class);
- contribute(ConfigListener.class, DefaultPullRequestManager.class);
contribute(LifecycleListener.class, DefaultPullRequestManager.class);
contribute(LifecycleListener.class, DefaultUserManager.class);
contribute(LifecycleListener.class, DefaultRepositoryManager.class);
+
+ contribute(ConfigListener.class, new ConfigListener() {
+
+ @Override
+ public void onSave(Config config) {
+ }
+
+ });
}
@Override
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentManager.java
index b3b0afb01c..6d776fcc79 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentManager.java
@@ -16,5 +16,5 @@ public interface CommentManager {
void save(Comment comment, boolean notify);
- void addInline(PullRequest request, BlobIdent blobInfo, BlobIdent compareWith, int line, String content);
+ Comment addInline(PullRequest request, BlobIdent blobInfo, BlobIdent compareWith, int line, String content);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestManager.java
index 06e1bb1bd9..c9cd9b1d75 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestManager.java
@@ -6,14 +6,13 @@ import java.util.List;
import javax.annotation.Nullable;
-import com.pmease.gitplex.core.listeners.ConfigListener;
import com.pmease.gitplex.core.model.IntegrationPreview;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy;
import com.pmease.gitplex.core.model.RepoAndBranch;
import com.pmease.gitplex.core.model.Repository;
-public interface PullRequestManager extends ConfigListener {
+public interface PullRequestManager {
@Nullable
PullRequest findOpen(RepoAndBranch target, RepoAndBranch source);
@@ -84,4 +83,5 @@ public interface PullRequestManager extends ConfigListener {
@Nullable
Date getLastVisitDate(PullRequest request);
+ void checkSanity();
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentManager.java
index 873dd5c707..3aa14c0c7a 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentManager.java
@@ -200,7 +200,7 @@ public class DefaultCommentManager implements CommentManager {
@Transactional
@Override
- public void addInline(PullRequest request, BlobIdent blobInfo, BlobIdent compareWith, int line, String content) {
+ public Comment addInline(PullRequest request, BlobIdent blobInfo, BlobIdent compareWith, int line, String content) {
User user = userManager.getCurrent();
Preconditions.checkNotNull(user);
Comment comment = new Comment();
@@ -213,6 +213,7 @@ public class DefaultCommentManager implements CommentManager {
comment.setCompareWith(compareWith);
comment.setLine(line);
save(comment, true);
+ return comment;
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultNotificationManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultNotificationManager.java
index 60f547d2dd..d1577803fa 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultNotificationManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultNotificationManager.java
@@ -67,7 +67,7 @@ public class DefaultNotificationManager implements NotificationManager {
@Transactional
@Override
public void onUpdated(PullRequestUpdate update) {
- Query query = dao.getSession().createQuery("delete from PullRequestNotification "
+ Query query = dao.getSession().createQuery("delete from Notification "
+ "where request=:request and task=:task");
query.setParameter("request", update.getRequest());
query.setParameter("task", UPDATE);
@@ -85,7 +85,7 @@ public class DefaultNotificationManager implements NotificationManager {
@Transactional
@Override
public void onReviewed(Review review, String comment) {
- Query query = dao.getSession().createQuery("delete from PullRequestNotification "
+ Query query = dao.getSession().createQuery("delete from Notification "
+ "where request=:request and user=:user and task=:task");
query.setParameter("request", review.getUpdate().getRequest());
query.setParameter("user", review.getReviewer());
@@ -99,7 +99,7 @@ public class DefaultNotificationManager implements NotificationManager {
Preconditions.checkNotNull(request.getAssignee());
if (request.getStatus() == PENDING_INTEGRATE) {
- Query query = dao.getSession().createQuery("delete from PullRequestNotification "
+ Query query = dao.getSession().createQuery("delete from Notification "
+ "where request=:request and task=:task and user!=:user");
query.setParameter("request", request);
query.setParameter("task", INTEGRATE);
@@ -117,7 +117,7 @@ public class DefaultNotificationManager implements NotificationManager {
@Transactional
@Override
public void onIntegrated(PullRequest request, User user, String comment) {
- Query query = dao.getSession().createQuery("delete from PullRequestNotification "
+ Query query = dao.getSession().createQuery("delete from Notification "
+ "where request=:request");
query.setParameter("request", request);
query.executeUpdate();
@@ -126,7 +126,7 @@ public class DefaultNotificationManager implements NotificationManager {
@Transactional
@Override
public void onDiscarded(PullRequest request, User user, String comment) {
- Query query = dao.getSession().createQuery("delete from PullRequestNotification "
+ Query query = dao.getSession().createQuery("delete from Notification "
+ "where request=:request");
query.setParameter("request", request);
query.executeUpdate();
@@ -143,7 +143,7 @@ public class DefaultNotificationManager implements NotificationManager {
PullRequest request = invitation.getRequest();
User user = invitation.getReviewer();
if (!invitation.isPreferred()) {
- Query query = dao.getSession().createQuery("delete from PullRequestNotification "
+ Query query = dao.getSession().createQuery("delete from Notification "
+ "where request=:request and user=:user and task=:task");
query.setParameter("request", request);
query.setParameter("user", user);
@@ -184,7 +184,7 @@ public class DefaultNotificationManager implements NotificationManager {
@Transactional
@Override
public void pendingApproval(PullRequest request) {
- Query query = dao.getSession().createQuery("delete from PullRequestNotification "
+ Query query = dao.getSession().createQuery("delete from Notification "
+ "where request=:request and (task=:update or task=:integrate)");
query.setParameter("request", request);
query.setParameter("update", UPDATE);
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
index 713a3794c0..32eea9a500 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
@@ -53,22 +53,20 @@ import com.pmease.gitplex.core.MentionParser;
import com.pmease.gitplex.core.listeners.LifecycleListener;
import com.pmease.gitplex.core.listeners.PullRequestListener;
import com.pmease.gitplex.core.listeners.RepositoryListener;
-import com.pmease.gitplex.core.manager.ConfigManager;
import com.pmease.gitplex.core.manager.CommentManager;
-import com.pmease.gitplex.core.manager.PullRequestManager;
import com.pmease.gitplex.core.manager.NotificationManager;
+import com.pmease.gitplex.core.manager.PullRequestManager;
import com.pmease.gitplex.core.manager.PullRequestUpdateManager;
import com.pmease.gitplex.core.manager.ReviewInvitationManager;
import com.pmease.gitplex.core.manager.StorageManager;
import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.model.Config;
+import com.pmease.gitplex.core.model.Comment;
import com.pmease.gitplex.core.model.IntegrationPolicy;
import com.pmease.gitplex.core.model.IntegrationPreview;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequest.CloseStatus;
import com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy;
import com.pmease.gitplex.core.model.PullRequestActivity;
-import com.pmease.gitplex.core.model.Comment;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.core.model.PullRequestVisit;
import com.pmease.gitplex.core.model.RepoAndBranch;
@@ -83,11 +81,9 @@ public class DefaultPullRequestManager implements PullRequestManager, Repository
private final Dao dao;
- private final ConfigManager configManager;
-
private final PullRequestUpdateManager pullRequestUpdateManager;
- private final CommentManager pullRequestCommentManager;
+ private final CommentManager commentManager;
private final UserManager userManager;
@@ -103,35 +99,36 @@ public class DefaultPullRequestManager implements PullRequestManager, Repository
private final Set<Long> integrationPreviewCalculatingRequestIds = new ConcurrentHashSet<>();
- private ThreadPoolExecutor integrationPreviewExecutor;
-
- @SuppressWarnings("serial")
- private final BlockingDeque<Runnable> integrationPreviewQueue = new LinkedBlockingDeque<Runnable>() {
-
- @Override
- public boolean offer(Runnable e) {
- return super.offerFirst(e);
- }
-
- };
+ private final ThreadPoolExecutor integrationPreviewExecutor;
@Inject
public DefaultPullRequestManager(Dao dao, PullRequestUpdateManager pullRequestUpdateManager,
StorageManager storageManager, ReviewInvitationManager reviewInvitationManager,
UserManager userManager, NotificationManager notificationManager,
- ConfigManager configManager, CommentManager pullRequestCommentManager,
- MarkdownManager markdownManager, UnitOfWork unitOfWork,
- Set<PullRequestListener> pullRequestListeners) {
+ CommentManager commentManager, MarkdownManager markdownManager,
+ UnitOfWork unitOfWork, Set<PullRequestListener> pullRequestListeners) {
this.dao = dao;
this.pullRequestUpdateManager = pullRequestUpdateManager;
this.storageManager = storageManager;
this.reviewInvitationManager = reviewInvitationManager;
- this.pullRequestCommentManager = pullRequestCommentManager;
+ this.commentManager = commentManager;
this.userManager = userManager;
this.unitOfWork = unitOfWork;
- this.configManager = configManager;
this.markdownManager = markdownManager;
this.pullRequestListeners = pullRequestListeners;
+
+ BlockingDeque<Runnable> queue = new LinkedBlockingDeque<Runnable>() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean offer(Runnable e) {
+ return super.offerFirst(e);
+ }
+
+ };
+ int workers = Runtime.getRuntime().availableProcessors();
+ integrationPreviewExecutor = new ThreadPoolExecutor(workers, workers, 0L, TimeUnit.MILLISECONDS, queue);
}
@Transactional
@@ -186,7 +183,7 @@ public class DefaultPullRequestManager implements PullRequestManager, Repository
requestComment.setDate(activity.getDate());
requestComment.setRequest(request);
requestComment.setUser(user);
- pullRequestCommentManager.save(requestComment, false);
+ commentManager.save(requestComment, false);
}
onSourceBranchUpdate(request, false);
@@ -216,7 +213,7 @@ public class DefaultPullRequestManager implements PullRequestManager, Repository
requestComment.setRequest(request);
requestComment.setUser(user);
- pullRequestCommentManager.save(requestComment, false);
+ commentManager.save(requestComment, false);
}
request.setCloseStatus(CloseStatus.DISCARDED);
@@ -292,7 +289,7 @@ public class DefaultPullRequestManager implements PullRequestManager, Repository
requestComment.setDate(activity.getDate());
requestComment.setRequest(request);
requestComment.setUser(user);
- pullRequestCommentManager.save(requestComment, false);
+ commentManager.save(requestComment, false);
}
request.setCloseStatus(CloseStatus.INTEGRATED);
@@ -483,22 +480,6 @@ public class DefaultPullRequestManager implements PullRequestManager, Repository
}
}
- private int getIntegrationPreviewWorkers() {
- Integer workers = configManager.getQosSetting().getIntegrationPreviewWorkers();
- if (workers == null)
- workers = Runtime.getRuntime().availableProcessors();
- return workers;
- }
-
- @Override
- public void onSave(Config config) {
- if (config.getKey() == Config.Key.QOS && integrationPreviewExecutor != null) {
- int integrationPreviewWorkers = getIntegrationPreviewWorkers();
- integrationPreviewExecutor.setCorePoolSize(integrationPreviewWorkers);
- integrationPreviewExecutor.setMaximumPoolSize(integrationPreviewWorkers);
- }
- }
-
@Override
public IntegrationPreview previewIntegration(PullRequest request) {
IntegrationPreview preview = request.getLastIntegrationPreview();
@@ -643,15 +624,11 @@ public class DefaultPullRequestManager implements PullRequestManager, Repository
}
}
- @Override
- public void systemStarting() {
- int previewWorkers = getIntegrationPreviewWorkers();
- integrationPreviewExecutor = new ThreadPoolExecutor(previewWorkers, previewWorkers,
- 0L, TimeUnit.MILLISECONDS, integrationPreviewQueue);
- }
-
@Override
public void systemStarted() {
+ logger.info("Checking pull requests...");
+
+ checkSanity();
}
@Override
@@ -660,8 +637,7 @@ public class DefaultPullRequestManager implements PullRequestManager, Repository
@Override
public void systemStopped() {
- if (integrationPreviewExecutor != null)
- integrationPreviewExecutor.shutdown();
+ integrationPreviewExecutor.shutdown();
}
@Transactional
@@ -771,4 +747,33 @@ public class DefaultPullRequestManager implements PullRequestManager, Repository
return dao.query(criteria);
}
+ @Transactional
+ @Override
+ public void checkSanity() {
+ EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
+ criteria.add(ofOpen());
+ for (PullRequest request: dao.query(criteria)) {
+ if (request.getSource() == null) {
+ discard(request, "Source branch is deleted.");
+ } else {
+ String sourceHead = request.getSource().getHead(false);
+ if (sourceHead == null)
+ discard(request, "Source branch is deleted.");
+ else if (!sourceHead.equals(request.getLatestUpdate().getHeadCommitHash()))
+ onSourceBranchUpdate(request, true);
+ }
+ String targetHead = request.getTarget().getHead(false);
+ if (targetHead == null)
+ discard(request, "Target branch is deleted.");
+ else
+ onTargetBranchUpdate(request);
+ }
+ }
+
+ @Override
+ public void systemStarting() {
+ // TODO Auto-generated method stub
+
+ }
+
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
index 7185ed8b25..50f3dedb7c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
@@ -26,19 +26,19 @@ public class DefaultPullRequestUpdateManager implements PullRequestUpdateManager
private final Set<PullRequestListener> pullRequestListeners;
- private final CommentManager pullRequestCommentManager;
+ private final CommentManager commentManager;
private final UnitOfWork unitOfWork;
@Inject
public DefaultPullRequestUpdateManager(Dao dao, StorageManager storageManager,
Set<PullRequestListener> pullRequestListeners, UnitOfWork unitOfWork,
- CommentManager pullRequestCommentManager) {
+ CommentManager commentManager) {
this.dao = dao;
this.storageManager = storageManager;
this.pullRequestListeners = pullRequestListeners;
this.unitOfWork = unitOfWork;
- this.pullRequestCommentManager = pullRequestCommentManager;
+ this.commentManager = commentManager;
}
@Transactional
@@ -79,7 +79,7 @@ public class DefaultPullRequestUpdateManager implements PullRequestUpdateManager
PullRequest request = dao.load(PullRequest.class, requestId);
for (Comment comment: request.getComments()) {
if (comment.getInlineInfo() != null)
- pullRequestCommentManager.updateInlineInfo(comment);
+ commentManager.updateInlineInfo(comment);
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultRepositoryManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultRepositoryManager.java
index fa63285cda..650c7820b0 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultRepositoryManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultRepositoryManager.java
@@ -214,9 +214,8 @@ public class DefaultRepositoryManager implements RepositoryManager, LifecycleLis
@Transactional
@Override
public void checkSanity() {
- for (Repository repository: dao.query(EntityCriteria.of(Repository.class), 0, 0)) {
+ for (Repository repository: dao.query(EntityCriteria.of(Repository.class), 0, 0))
checkSanity(repository);
- }
}
@Transactional
@@ -248,7 +247,6 @@ public class DefaultRepositoryManager implements RepositoryManager, LifecycleLis
FileUtils.writeFile(gitPostReceiveHookFile, gitPostReceiveHook);
gitPostReceiveHookFile.setExecutable(true);
}
-
}
@Sessional
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultReviewManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultReviewManager.java
index 697d05e63b..8e09a13987 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultReviewManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultReviewManager.java
@@ -36,7 +36,7 @@ public class DefaultReviewManager implements ReviewManager {
private final PullRequestManager pullRequestManager;
- private final CommentManager pullRequestCommentManager;
+ private final CommentManager commentManager;
private final UnitOfWork unitOfWork;
@@ -44,11 +44,11 @@ public class DefaultReviewManager implements ReviewManager {
@Inject
public DefaultReviewManager(Dao dao, PullRequestManager pullRequestManager,
- CommentManager pullRequestCommentManager,
- UnitOfWork unitOfWork, Set<PullRequestListener> pullRequestListeners) {
+ CommentManager commentManager, UnitOfWork unitOfWork,
+ Set<PullRequestListener> pullRequestListeners) {
this.dao = dao;
this.pullRequestManager = pullRequestManager;
- this.pullRequestCommentManager = pullRequestCommentManager;
+ this.commentManager = commentManager;
this.unitOfWork = unitOfWork;
this.pullRequestListeners = pullRequestListeners;
}
@@ -90,7 +90,7 @@ public class DefaultReviewManager implements ReviewManager {
requestComment.setUser(reviewer);
requestComment.setContent(comment);
- pullRequestCommentManager.save(requestComment, false);
+ commentManager.save(requestComment, false);
}
for (PullRequestListener listener: pullRequestListeners)
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
index 96d66afe09..2cc061788d 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
@@ -151,6 +151,7 @@ public class PullRequest extends AbstractEntity {
@ManyToOne(fetch=FetchType.LAZY)
private Repository sourceRepo;
+ @Column(nullable=false)
private String sourceBranch;
@Column(nullable=false)
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/setting/QosSetting.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/setting/QosSetting.java
index 4d41e68bab..bcfc380d75 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/setting/QosSetting.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/setting/QosSetting.java
@@ -2,10 +2,6 @@ package com.pmease.gitplex.core.setting;
import java.io.Serializable;
-import javax.annotation.Nullable;
-
-import org.hibernate.validator.constraints.Range;
-
import com.pmease.commons.editable.annotation.Editable;
/**
@@ -17,18 +13,4 @@ public class QosSetting implements Serializable {
private static final long serialVersionUID = 1L;
- private Integer integrationPreviewWorkers;
-
- @Editable(description="Specify number of workers available to calculate pull request integration previews. "
- + "If leave empty, GitPlex will default this value to number of cores of the machine.")
- @Range(min=1, max=10000)
- @Nullable
- public Integer getIntegrationPreviewWorkers() {
- return integrationPreviewWorkers;
- }
-
- public void setIntegrationPreviewWorkers(Integer integrationPreviewWorkers) {
- this.integrationPreviewWorkers = integrationPreviewWorkers;
- }
-
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/CommentAndPos.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/CommentAndPos.java
index 2535aa5c6a..5ad2c72611 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/CommentAndPos.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/CommentAndPos.java
@@ -13,4 +13,5 @@ class CommentAndPos implements Serializable {
int oldLineNo;
int newLineNo;
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java
index b660d8c210..af76f3092e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java
@@ -94,21 +94,9 @@ public class TextDiffPanel extends Panel {
for (Comment comment: request.getComments()) {
if (comment.getInlineInfo() != null) {
GitPlex.getInstance(CommentManager.class).updateInlineInfo(comment);
- BlobIdent blobIdent = comment.getBlobIdent();
- if (blobIdent.equals(change.getOldBlobIdent())) {
- CommentAndPos commentAndPos = new CommentAndPos();
- commentAndPos.comment = comment;
- commentAndPos.oldLineNo = comment.getLine();
- commentAndPos.newLineNo = -1;
+ CommentAndPos commentAndPos = getCommentAndPos(comment);
+ if (commentAndPos != null)
listOfCommentAndPos.add(commentAndPos);
- }
- if (blobIdent.equals(change.getNewBlobIdent())) {
- CommentAndPos commentAndPos = new CommentAndPos();
- commentAndPos.comment = comment;
- commentAndPos.oldLineNo = -1;
- commentAndPos.newLineNo = comment.getLine();
- listOfCommentAndPos.add(commentAndPos);
- }
}
}
Collections.sort(listOfCommentAndPos, new Comparator<CommentAndPos>() {
@@ -247,16 +235,17 @@ public class TextDiffPanel extends Panel {
lineNo = newLineNo;
}
+ Comment comment;
InheritableThreadLocalData.set(new WebSocketRenderBehavior.PageId(getPage().getPageId()));
try {
- GitPlex.getInstance(CommentManager.class).addInline(
+ comment = GitPlex.getInstance(CommentManager.class).addInline(
requestModel.getObject(), commentAt, compareWith, lineNo, input.getModelObject());
} finally {
InheritableThreadLocalData.clear();
}
- CommentAndPos lastComment = listOfCommentAndPosModel.getObject().get(listOfCommentAndPosModel.getObject().size()-1);
- Component commentRow = newCommentRow(commentRows.newChildId(), lastComment);
+ CommentAndPos commentAndPos = getCommentAndPos(comment);
+ Component commentRow = newCommentRow(commentRows.newChildId(), commentAndPos);
commentRows.add(commentRow);
commentRow.setMarkupId(newCommentForm.getMarkupId());
newCommentForm.remove();
@@ -607,6 +596,25 @@ public class TextDiffPanel extends Panel {
builder.append("</tr>");
}
+ private CommentAndPos getCommentAndPos(Comment comment) {
+ BlobIdent blobIdent = comment.getBlobIdent();
+ if (blobIdent.equals(change.getOldBlobIdent())) {
+ CommentAndPos commentAndPos = new CommentAndPos();
+ commentAndPos.comment = comment;
+ commentAndPos.oldLineNo = comment.getLine();
+ commentAndPos.newLineNo = -1;
+ return commentAndPos;
+ } else if (blobIdent.equals(change.getNewBlobIdent())) {
+ CommentAndPos commentAndPos = new CommentAndPos();
+ commentAndPos.comment = comment;
+ commentAndPos.oldLineNo = -1;
+ commentAndPos.newLineNo = comment.getLine();
+ return commentAndPos;
+ } else {
+ return null;
+ }
+ }
+
private Component newCommentRow(String id, CommentAndPos commentAndPos) {
final Long commentId = commentAndPos.comment.getId();
WebMarkupContainer row = new WebMarkupContainer(id) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.html
index ed21ab1aaf..c588f84bca 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.html
@@ -2,9 +2,19 @@
<div class="source-view autofit clearfix">
<div wicket:id="code" class="code pull-left"></div>
<div wicket:id="outline" class="outline pull-right"></div>
- <div wicket:id="comments" class="comment clearfix" tabindex="0">
- <div wicket:id="avatar" class="avatar pull-left"></div>
- <div wicket:id="detail" class="detail"></div>
+ <form wicket:id="newComments" class="new-comment leave-confirm">
+ <textarea wicket:id="input" rows="10" class="form-control focusable"></textarea>
+ <div wicket:id="feedback"></div>
+ <div class="actions">
+ <button wicket:id="save" class="btn btn-sm btn-primary dirty-aware leave-confirm">Comment on this line</button>
+ <button wicket:id="cancel" class="btn btn-sm btn-default">Close form</button>
+ </div>
+ </form>
+ <div wicket:id="comments" class="comment">
+ <div wicket:id="wrapper" class="clearfix" tabindex="0">
+ <div wicket:id="avatar" class="avatar pull-left"></div>
+ <div wicket:id="detail" class="detail"></div>
+ </div>
</div>
</div>
<div wicket:id="symbols" class="hidden">
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java
index 984d509aa1..34905641f1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java
@@ -13,6 +13,7 @@ import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.attributes.CallbackParameter;
import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.event.Broadcast;
import org.apache.wicket.event.IEvent;
@@ -22,6 +23,7 @@ import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
@@ -30,6 +32,7 @@ import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.model.Model;
import org.apache.wicket.request.IRequestParameters;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;
@@ -37,6 +40,7 @@ import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.wicket.request.resource.JavaScriptResourceReference;
import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.request.resource.ResourceReference;
+import org.apache.wicket.util.time.Duration;
import org.eclipse.jgit.lib.FileMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,9 +58,13 @@ import com.pmease.commons.lang.extractors.Extractor;
import com.pmease.commons.lang.extractors.Extractors;
import com.pmease.commons.lang.extractors.Symbol;
import com.pmease.commons.lang.extractors.TokenPosition;
+import com.pmease.commons.loader.InheritableThreadLocalData;
import com.pmease.commons.wicket.assets.codemirror.CodeMirrorResourceReference;
import com.pmease.commons.wicket.assets.cookies.CookiesResourceReference;
+import com.pmease.commons.wicket.behavior.DirtyIgnoreBehavior;
import com.pmease.commons.wicket.behavior.RunTaskBehavior;
+import com.pmease.commons.wicket.component.feedback.FeedbackPanel;
+import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.manager.CommentManager;
import com.pmease.gitplex.core.model.Comment;
@@ -67,6 +75,7 @@ import com.pmease.gitplex.search.query.BlobQuery;
import com.pmease.gitplex.search.query.SymbolQuery;
import com.pmease.gitplex.search.query.TextQuery;
import com.pmease.gitplex.web.component.avatar.AvatarMode;
+import com.pmease.gitplex.web.component.comment.CommentInput;
import com.pmease.gitplex.web.component.comment.CommentPanel;
import com.pmease.gitplex.web.component.comment.event.CommentRemoved;
import com.pmease.gitplex.web.component.comment.event.CommentResized;
@@ -81,9 +90,11 @@ import com.pmease.gitplex.web.utils.DateUtils;
@SuppressWarnings("serial")
public class SourceViewPanel extends BlobViewPanel {
+ private static final Logger logger = LoggerFactory.getLogger(SourceViewPanel.class);
+
private static final int QUERY_ENTRIES = 20;
- private static final Logger logger = LoggerFactory.getLogger(SourceViewPanel.class);
+ private static final String WRAPPER_ID = "wrapper";
private String symbol = "";
@@ -126,7 +137,13 @@ public class SourceViewPanel extends BlobViewPanel {
private WebMarkupContainer symbolsContainer;
- private RepeatingView commentRows;
+ private RepeatingView newCommentForms;
+
+ private RepeatingView commentWidgets;
+
+ private AbstractDefaultAjaxBehavior addCommentBehavior;
+
+ private AbstractDefaultAjaxBehavior querySymbolBehavior;
public SourceViewPanel(String id, BlobViewContext context) {
super(id, context);
@@ -275,14 +292,16 @@ public class SourceViewPanel extends BlobViewPanel {
});
- commentRows = new RepeatingView("comments");
+ add(newCommentForms = new RepeatingView("newComments"));
+
+ commentWidgets = new RepeatingView("comments");
for (Comment comment: commentsModel.getObject())
- commentRows.add(newCommentRow(commentRows.newChildId(), comment));
+ commentWidgets.add(newCommentWidget(commentWidgets.newChildId(), comment));
- add(commentRows);
+ add(commentWidgets);
- add(new AbstractDefaultAjaxBehavior() {
+ add(querySymbolBehavior = new AbstractDefaultAjaxBehavior() {
@Override
protected void respond(AjaxRequestTarget target) {
@@ -308,44 +327,133 @@ public class SourceViewPanel extends BlobViewPanel {
target.appendJavaScript(script);
}
- @Override
- public void renderHead(Component component, IHeaderResponse response) {
- super.renderHead(component, response);
-
- response.render(JavaScriptHeaderItem.forReference(CookiesResourceReference.INSTANCE));
- response.render(JavaScriptHeaderItem.forReference(CodeMirrorResourceReference.INSTANCE));
-
- response.render(JavaScriptHeaderItem.forReference(
- new JavaScriptResourceReference(SourceViewPanel.class, "source-view.js")));
- response.render(CssHeaderItem.forReference(
- new CssResourceReference(SourceViewPanel.class, "source-view.css")));
-
- String highlightToken;
- try {
- highlightToken = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(context.getTokenPos());
- } catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- ResourceReference ajaxIndicator = new PackageResourceReference(SourceViewPanel.class, "ajax-indicator.gif");
- Blob blob = context.getRepository().getBlob(context.getBlobIdent());
- String script = String.format("gitplex.sourceview.init('%s', '%s', '%s', %s, '%s', %s, %s, %d, %d);",
- codeContainer.getMarkupId(),
- StringEscapeUtils.escapeEcmaScript(blob.getText().getContent()),
- context.getBlobIdent().path,
- highlightToken,
- RequestCycle.get().urlFor(ajaxIndicator, new PageParameters()),
- getCallbackFunction(CallbackParameter.explicit("symbol")),
- getBlameCommits(),
- context.getPullRequest()!=null?context.getPullRequest().getId():-1,
- context.getComment()!=null?context.getComment().getId():-1);
- response.render(OnDomReadyHeaderItem.forScript(script));
- }
-
});
+ if (context.getPullRequest() != null) {
+ add(addCommentBehavior = new AbstractDefaultAjaxBehavior() {
+
+ @Override
+ protected void respond(AjaxRequestTarget target) {
+ IRequestParameters params = RequestCycle.get().getRequest().getQueryParameters();
+ final int lineNo = params.getParameterValue("lineNo").toInt();
+
+ final Form<?> newCommentForm = new Form<Void>(newCommentForms.newChildId());
+ newCommentForm.setOutputMarkupId(true);
+
+ final CommentInput input;
+ newCommentForm.add(input = new CommentInput("input", Model.of("")));
+ input.setRequired(true);
+ newCommentForm.add(new FeedbackPanel("feedback", input).hideAfter(Duration.seconds(5)));
+
+ newCommentForm.add(new AjaxLink<Void>("cancel") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ newCommentForm.remove();
+ String script = String.format("$('#%s').parent()[0].lineWidget.clear();", newCommentForm.getMarkupId());
+ target.appendJavaScript(script);
+ }
+
+ }.add(new DirtyIgnoreBehavior()));
+
+ newCommentForm.add(new AjaxSubmitLink("save") {
+
+ @Override
+ protected void onError(AjaxRequestTarget target, Form<?> form) {
+ super.onError(target, form);
+ target.add(form);
+ }
+
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
+ super.onSubmit(target, form);
+
+ BlobIdent commentAt = context.getBlobIdent();
+ BlobIdent compareWith = context.getBlobIdent();
+
+ Comment comment;
+ InheritableThreadLocalData.set(new WebSocketRenderBehavior.PageId(getPage().getPageId()));
+ try {
+ comment = GitPlex.getInstance(CommentManager.class).addInline(
+ context.getPullRequest(), commentAt, compareWith, lineNo, input.getModelObject());
+ } finally {
+ InheritableThreadLocalData.clear();
+ }
+
+ Component commentWidget = newCommentWidget(commentWidgets.newChildId(), comment);
+ commentWidgets.add(commentWidget);
+
+ Component wrapper = commentWidget.get(WRAPPER_ID);
+ wrapper.setMarkupId(newCommentForm.getMarkupId());
+ newCommentForm.remove();
+ target.add(wrapper);
+
+ String script = String.format(""
+ + "var $comment = $('#%s').parent();"
+ + "$comment.attr('id', '%s'); "
+ + "gitplex.sourceview.commentResized($comment);",
+ wrapper.getMarkupId(), commentWidget.getMarkupId());
+ target.appendJavaScript(script);
+ }
+
+ }.add(new DirtyIgnoreBehavior()));
+
+ newCommentForms.add(newCommentForm);
+
+ String script = String.format("gitplex.sourceview.placeComment('%s', %d, '%s');",
+ codeContainer.getMarkupId(), lineNo, newCommentForm.getMarkupId());
+ target.prependJavaScript(script);
+
+ target.add(newCommentForm);
+ script = String.format("gitplex.sourceview.commentResized($('#%s').parent());",
+ newCommentForm.getMarkupId());
+ target.appendJavaScript(script);
+ }
+
+ });
+ }
setOutputMarkupId(true);
}
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+
+ response.render(JavaScriptHeaderItem.forReference(CookiesResourceReference.INSTANCE));
+ response.render(JavaScriptHeaderItem.forReference(CodeMirrorResourceReference.INSTANCE));
+
+ response.render(JavaScriptHeaderItem.forReference(
+ new JavaScriptResourceReference(SourceViewPanel.class, "source-view.js")));
+ response.render(CssHeaderItem.forReference(
+ new CssResourceReference(SourceViewPanel.class, "source-view.css")));
+
+ String highlightToken;
+ try {
+ highlightToken = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(context.getTokenPos());
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ ResourceReference ajaxIndicator = new PackageResourceReference(SourceViewPanel.class, "ajax-indicator.gif");
+ Blob blob = context.getRepository().getBlob(context.getBlobIdent());
+
+ CharSequence addCommentCallback;
+ if (addCommentBehavior != null)
+ addCommentCallback = addCommentBehavior.getCallbackFunction(CallbackParameter.explicit("lineNo"));
+ else
+ addCommentCallback = "undefined";
+ String script = String.format("gitplex.sourceview.init('%s', '%s', '%s', %s, '%s', %s, %s, %d, %s);",
+ codeContainer.getMarkupId(),
+ StringEscapeUtils.escapeEcmaScript(blob.getText().getContent()),
+ context.getBlobIdent().path,
+ highlightToken,
+ RequestCycle.get().urlFor(ajaxIndicator, new PageParameters()),
+ querySymbolBehavior.getCallbackFunction(CallbackParameter.explicit("symbol")),
+ getBlameCommits(),
+ context.getComment()!=null?context.getComment().getId():-1,
+ addCommentCallback);
+ response.render(OnDomReadyHeaderItem.forScript(script));
+ }
+
public void onBlameChange(AjaxRequestTarget target) {
String script = String.format("gitplex.sourceview.blame('%s', %s);",
codeContainer.getMarkupId(), getBlameCommits());
@@ -379,9 +487,9 @@ public class SourceViewPanel extends BlobViewPanel {
}
}
- private Component newCommentRow(String id, Comment comment) {
+ private Component newCommentWidget(String id, Comment comment) {
final Long commentId = comment.getId();
- WebMarkupContainer row = new WebMarkupContainer(id) {
+ WebMarkupContainer widget = new WebMarkupContainer(id) {
@Override
public void onEvent(IEvent<?> event) {
@@ -389,8 +497,8 @@ public class SourceViewPanel extends BlobViewPanel {
if (event.getPayload() instanceof CommentRemoved) {
CommentRemoved commentRemoved = (CommentRemoved) event.getPayload();
- commentRows.remove(this);
- String script = String.format("gitplex.sourceview.removeComment('%s');", getMarkupId());
+ commentWidgets.remove(this);
+ String script = String.format("document.getElementById('%s').lineWidget.clear();", getMarkupId());
commentRemoved.getTarget().appendJavaScript(script);
send(SourceViewPanel.this, Broadcast.BUBBLE, commentRemoved);
@@ -402,8 +510,13 @@ public class SourceViewPanel extends BlobViewPanel {
}
};
- row.add(new UserLink("avatar", new UserModel(comment.getUser()), AvatarMode.AVATAR));
- row.add(new CommentPanel("detail", new LoadableDetachableModel<Comment>() {
+
+ // after adding a new comment, the comment form will be replaced with this wrapper in stead of whole
+ // comment widget, in order not to break the already stored line widget reference at CodeMirror side
+ WebMarkupContainer wrapper = new WebMarkupContainer(WRAPPER_ID);
+ widget.add(wrapper);
+ wrapper.add(new UserLink("avatar", new UserModel(comment.getUser()), AvatarMode.AVATAR));
+ wrapper.add(new CommentPanel("detail", new LoadableDetachableModel<Comment>() {
@Override
protected Comment load() {
@@ -412,11 +525,11 @@ public class SourceViewPanel extends BlobViewPanel {
}));
- row.add(AttributeAppender.append("data-lineNo", comment.getLine()));
- row.setMarkupId("pullrequest-comment-" + comment.getId());
- row.setOutputMarkupId(true);
+ widget.add(AttributeAppender.append("data-lineNo", comment.getLine()));
+ widget.setMarkupId("pullrequest-comment-" + commentId);
+ widget.setOutputMarkupId(true);
- return row;
+ return widget;
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.css
index a7612619fe..150810d40f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.css
@@ -46,23 +46,35 @@
.CodeMirror-activeline .CodeMirror-annotation {
background: #E8F2FE;
}
-pre+.CodeMirror-linewidget>.comment {
+pre+.CodeMirror-linewidget>.comment>div, pre+.CodeMirror-linewidget>.comment>form {
border-top: 1px solid #DDD;
}
-.CodeMirror-linewidget>.comment {
+.CodeMirror-linewidget>.comment>div, .CodeMirror-linewidget>.comment>form {
border-bottom: 1px solid #DDD;
padding: 12px;
background: white;
}
-.CodeMirror-linewidget>.comment>.detail {
+.CodeMirror-linewidget>.comment>div>.detail {
margin-left: 36px;
font-size: 14px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
-.CodeMirror-linewidget>.comment>.avatar img {
+.CodeMirror-linewidget>.comment>div>.avatar img {
width: 28px;
height: 28px;
}
.source-view>.comment {
display: none;
+}
+.CodeMirror-addcomments {
+ width: 12px;
+}
+.CodeMirror-addcomment>a {
+ font-size: 12px;
+ color: #BBB;
+ background: white;
+}
+.CodeMirror-addcomment>a:hover {
+ color: black;
+ font-size: 14px;
}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.js
index 016750ad2f..0eeb5b7717 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.js
@@ -95,15 +95,17 @@ gitplex.sourceview = {
cm = CodeMirror($code[0], options);
if (addCommentCallback) {
- var gutter = "CodeMirror-addcomment";
+ $code[0].addCommentCallback = addCommentCallback;
+ var gutter = "CodeMirror-addcomments";
var gutters = cm.getOption("gutters").slice();
gutters.push(gutter);
cm.setOption("gutters", gutters);
for (var line=0; line<cm.lineCount(); line++) {
var $ele = $(document.createElement("div"));
- $ele.addClass(gutter);
+ $ele.addClass("CodeMirror-addcomment");
+ $ele.attr("title", "Add inline comment");
var script = "document.getElementById(\"" + codeId + "\").addCommentCallback(" + line + ");";
- $("<a href='javascript: " + script + "'><i class='fa fa-plus'></i></a>").appendTo($ele);
+ $("<a href='javascript: " + script + "'><i class='fa fa-comment-o'></i></a>").appendTo($ele);
cm.setGutterMarker(line, gutter, $ele[0]);
}
}
@@ -194,26 +196,25 @@ gitplex.sourceview = {
placeComment: function(cm, lineNo, comment) {
if (typeof cm === "string")
cm = $("#"+ cm + ">.CodeMirror")[0].CodeMirror;
- comment.lineWidget = cm.addLineWidget(lineNo, comment);
+ if (typeof comment === "string")
+ comment = $("<div class='comment'><div id='" + comment + "'></div></div>")[0];
+ comment.lineWidget = cm.addLineWidget(lineNo, comment, {coverGutter: true});
},
- removeComment: function(commentId) {
- document.getElementById(commentId).lineWidget.clear();
- },
-
- commentResized: function(commentId) {
- var $comment = $("#" + commentId);
+ commentResized: function($comment) {
+ if (typeof $comment === "string")
+ $comment = $("#" + $comment);
$comment[0].lineWidget.changed();
- var $detail = $comment.find(">.detail");
- $detail.on("mouseup resized", function() {
+ var $wrapper = $comment.find(">div");
+ $wrapper.on("mouseup resized", function() {
$comment[0].lineWidget.changed();
});
- $detail.on("fullscreen", function() {
+ $wrapper.on("fullscreen", function() {
// full screen mode is abnormal if we do not do this
- $("body").append($detail);
+ $("body").append($wrapper);
});
- $detail.on("exitFullscreen", function() {
- $comment.append($detail);
+ $wrapper.on("exitFullscreen", function() {
+ $comment.append($wrapper);
$comment[0].lineWidget.changed();
});
},
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
index e596a5faa3..7fed516190 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
@@ -52,6 +52,7 @@ import com.pmease.commons.wicket.behavior.modal.ModalBehavior;
import com.pmease.commons.wicket.behavior.modal.ModalPanel;
import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior;
import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.listeners.RepositoryListener;
import com.pmease.gitplex.core.model.Comment;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Repository;
@@ -436,7 +437,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
private void onAddOrEditFile(AjaxRequestTarget target) {
ObjectId commitId = getRepository().getObjectId(blobIdent.revision);
- String refName = Git.REFS_HEADS + blobIdent.revision;
+ final String refName = Git.REFS_HEADS + blobIdent.revision;
final AtomicReference<String> newPathRef = new AtomicReference<>(blobIdent.isTree()?null:blobIdent.path);
@@ -452,6 +453,9 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
BlobIdent committed = new BlobIdent(
blobIdent.revision, newPathRef.get(), FileMode.REGULAR_FILE.getBits());
onSelect(target, committed, null);
+
+ for (RepositoryListener listener: GitPlex.getExtensions(RepositoryListener.class))
+ listener.onRefUpdate(getRepository(), refName, newCommitId.name());
}
@Override
@@ -795,7 +799,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
public void onDelete(AjaxRequestTarget target) {
ObjectId commitId = getRepository().getObjectId(blobIdent.revision);
- String refName = Git.REFS_HEADS + blobIdent.revision;
+ final String refName = Git.REFS_HEADS + blobIdent.revision;
CancelListener cancelListener = new CancelListener() {
@@ -828,6 +832,10 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
BlobIdent parentBlobIdent = new BlobIdent(blobIdent.revision, parentPath,
FileMode.TREE.getBits());
onSelect(target, parentBlobIdent, null);
+
+ for (RepositoryListener listener: GitPlex.getExtensions(RepositoryListener.class))
+ listener.onRefUpdate(getRepository(), refName, newCommitId.name());
+
} catch (IOException e) {
throw new RuntimeException(e);
}