Skip to content

Commit eff9e48

Browse files
committed
fixup! feat: Implement quick review command
1 parent 8caeb49 commit eff9e48

File tree

4 files changed

+59
-18
lines changed

4 files changed

+59
-18
lines changed

plugin-core/src/main/java/appland/actions/QuickReviewAction.java

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package appland.actions;
22

3+
import appland.AppMapBundle;
4+
import appland.notifications.AppMapNotifications;
35
import appland.webviews.navie.NavieEditorProvider;
46
import appland.webviews.navie.NaviePromptSuggestion;
57
import com.intellij.icons.AllIcons;
68
import com.intellij.ide.util.PropertiesComponent;
9+
import com.intellij.notification.Notification;
10+
import com.intellij.notification.NotificationType;
11+
import com.intellij.notification.Notifications;
712
import com.intellij.openapi.actionSystem.ActionUpdateThread;
813
import com.intellij.openapi.actionSystem.AnAction;
914
import com.intellij.openapi.actionSystem.AnActionEvent;
@@ -43,23 +48,33 @@ public class QuickReviewAction extends AnAction implements DumbAware {
4348
return ActionUpdateThread.BGT;
4449
}
4550

51+
@Override
52+
public void update(@NotNull AnActionEvent e) {
53+
super.update(e);
54+
e.getPresentation().setEnabled(e.getProject() != null);
55+
}
56+
4657
@Override
4758
public void actionPerformed(@NotNull AnActionEvent e) {
4859
var project = e.getProject();
49-
if (project == null) {
50-
return;
51-
}
60+
assert (project != null);
5261

5362
var repositoryManager = GitRepositoryManager.getInstance(project);
5463
var repositories = repositoryManager.getRepositories();
5564
if (repositories.isEmpty()) {
65+
Notifications.Bus.notify(new Notification(
66+
AppMapNotifications.GENERIC_NOTIFICATIONS_ID,
67+
AppMapBundle.get("action.appmap.quickReview.noRepositories.title"),
68+
AppMapBundle.get("action.appmap.quickReview.noRepositories.message"),
69+
NotificationType.INFORMATION
70+
), project);
5671
return;
5772
}
5873

5974
// For now, we'll just use the first repository
6075
var repository = repositories.get(0);
6176

62-
new Task.Backgroundable(project, "Fetching Git Refs", true) {
77+
new Task.Backgroundable(project, AppMapBundle.get("action.appmap.quickReview.fetchingRefs.progressTitle"), true) {
6378
private List<GitRef> refs;
6479
private boolean dirty = false;
6580

@@ -69,7 +84,7 @@ public void run(@NotNull ProgressIndicator indicator) {
6984
refs = getItems(project, repository);
7085
dirty = isDirty();
7186
} catch (VcsException ex) {
72-
throw new RuntimeException("Failed to fetch Git refs", ex);
87+
throw new RuntimeException(ex);
7388
}
7489
}
7590

@@ -86,6 +101,18 @@ private boolean isDirty() {
86101
}
87102
}
88103

104+
@Override
105+
public void onThrowable(@NotNull Throwable error) {
106+
new Notification(
107+
AppMapNotifications.GENERIC_NOTIFICATIONS_ID,
108+
AppMapBundle.get("action.appmap.quickReview.fetchingRefs.error"),
109+
error.getMessage() != null
110+
? error.getMessage() + "<br><br><code>" + error.toString() + "</code>"
111+
: error.toString(),
112+
NotificationType.ERROR
113+
).notify(project);
114+
}
115+
89116
@Override
90117
public void onSuccess() {
91118
if (refs == null || refs.isEmpty()) {
@@ -100,9 +127,10 @@ public void onSuccess() {
100127
/* only show HEAD if the repository is dirty */
101128
.filter(gitRef -> dirty || !gitRef.commit.equals(head))
102129
.peek(gitRef -> {
103-
if (gitRef.commit.equals(head)) gitRef.description = "review uncommitted changes";
130+
if (gitRef.commit.equals(head))
131+
gitRef.description = AppMapBundle.get("action.appmap.quickReview.reviewUncommittedChanges");
104132
if (gitRef.label.equals(lastPickedRef)) {
105-
gitRef.description = "last picked ⋅ " + gitRef.description;
133+
gitRef.description = AppMapBundle.get("action.appmap.quickReview.lastPickedPrefix") + " ⋅ " + gitRef.description;
106134
seenLastPicked.set(true);
107135
}
108136
})
@@ -116,19 +144,21 @@ public void onSuccess() {
116144
var popup = JBPopupFactory.getInstance()
117145
.createPopupChooserBuilder(refs)
118146
.setRenderer(new GitRefCellRenderer())
119-
.setTitle("Select base for review")
120-
.setMovable(false)
121-
.setResizable(false)
147+
.setTitle(AppMapBundle.get("action.appmap.quickReview.selectBase.title"))
148+
.setNamerForFiltering(GitRef::toString)
149+
.setMovable(true)
150+
.setResizable(true)
151+
.setDimensionServiceKey("appmap.quickReviewPopup")
122152
.setRequestFocus(true)
123153
.setItemChosenCallback((selectedValue) -> {
124154
if (selectedValue != null) {
125155
PropertiesComponent.getInstance().setValue(LAST_PICKED_REF_KEY, selectedValue.label);
126156
NavieEditorProvider.openEditorWithPrompt(project, new NaviePromptSuggestion(
127-
"Quick Review",
157+
AppMapBundle.get("action.appmap.quickReview.text"),
128158
String.format("@review /base=%s", selectedValue.label)));
129159
}
130160
}).createPopup();
131-
popup.showCenteredInCurrentWindow(project);
161+
popup.showInBestPositionFor(e.getDataContext());
132162
}
133163
}.queue();
134164
}
@@ -241,8 +271,11 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
241271
var component = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
242272
if (value instanceof GitRef) {
243273
var ref = (GitRef) value;
274+
var description = ref.description != null ? ref.description : "";
275+
// sometimes description is very long, truncate it then
276+
if (description.length() > 100) description = description.substring(0, 100) + "...";
244277
component.setText("<html><b>" + ref.label + "</b> " +
245-
"<small>" + ref.description + "</small></html>");
278+
"<small>" + description + "</small></html>");
246279
component.setIcon(ref.getIcon());
247280
}
248281
return component;
@@ -252,7 +285,7 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
252285
// HACK: platform version 241 does not define GitCommand.FOR_EACH_REF
253286
// and the final GitCommand constructors are private, so we need to replace
254287
// the command in GitLineHandler with a custom one.
255-
class GitCommandLineHandler extends GitLineHandler {
288+
private static class GitCommandLineHandler extends GitLineHandler {
256289
public GitCommandLineHandler(@Nullable Project project, @NotNull VirtualFile directory, @NotNull String command) {
257290
super(project, directory, GitCommand.LOG);
258291
var paramsList = this.myCommandLine.getParametersList();

plugin-core/src/main/java/appland/toolwindow/navie/NaviePanel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ protected void setupPanel() {
6868
button.addActionListener(e -> {
6969
var manager = ActionManager.getInstance();
7070
var action = manager.getAction(QuickReviewAction.ACTION_ID);
71-
if (action != null) {
72-
manager.tryToExecute(action, null, this, ActionPlaces.TOOLWINDOW_CONTENT, true);
73-
}
71+
assert (action != null);
72+
manager.tryToExecute(action, null, this, ActionPlaces.TOOLWINDOW_CONTENT, true);
7473
});
7574
return button;
7675
}

plugin-core/src/main/resources/META-INF/appmap-core.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
<reference ref="stopAppMapRemoteRecording"/>
210210
<separator/>
211211
<reference ref="appmap.generateOpenAPI"/>
212-
<action id="appmap.quickReview" class="appland.actions.QuickReviewAction" text="Quick Review" description="Start a new review with AppMap Navie" icon="AllIcons.Actions.Preview"/>
212+
<action id="appmap.quickReview" class="appland.actions.QuickReviewAction" icon="AllIcons.Actions.Preview"/>
213213
<reference ref="appmap.openNavie"/>
214214
<reference ref="appmap.navie.openThread"/>
215215
<reference ref="appmap.navie.chooseAndPinContextFile"/>

plugin-core/src/main/resources/messages/appland.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ action.stopAppMapRemoteRecording.fileChooserTitle=Choose AppMap Location
9393
action.stopAppMapRemoteRecording.progressTitle=Stopping recording...
9494
action.stopAppMapRemoteRecording.locationProgress.title=Stop Remote Recording
9595
action.stopAppMapRemoteRecording.locationProgress.progressTitle=Locating AppMap storage location...
96+
action.appmap.quickReview.text=Quick Review
97+
action.appmap.quickReview.description=Start a new review with AppMap Navie
98+
action.appmap.quickReview.noRepositories.title=No Git Repositories Found
99+
action.appmap.quickReview.noRepositories.message=No Git repositories found in the current project. Please ensure that your project is a Git repository.
100+
action.appmap.quickReview.fetchingRefs.progressTitle=Fetching Git Refs
101+
action.appmap.quickReview.fetchingRefs.error=Failed to fetch Git refs
102+
action.appmap.quickReview.reviewUncommittedChanges=review uncommitted changes
103+
action.appmap.quickReview.lastPickedPrefix=last picked
104+
action.appmap.quickReview.selectBase.title=Select base for review
96105

97106
errorReporter.actionText=Report on GitHub
98107

0 commit comments

Comments
 (0)