Skip to content

Commit

Permalink
refactor(issues): Disable functionality missing from CLI
Browse files Browse the repository at this point in the history
- Disable editing issue comments
- Disable removing issue reactions
- Move changing issue title/description to CLI (not working yet!)

Signed-off-by: jchrist <[email protected]>
  • Loading branch information
JChrist committed Dec 9, 2024
1 parent f4b0645 commit f752931
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,22 @@ public JComponent createCommentSection(List<RadDiscussion> discussionList) {
verticalPanel.add(replyPanel);
panel.addToBottom(verticalPanel);
var panelHandle = new EditablePanelHandler.PanelBuilder(radIssue.project, panel,
RadicleBundle.message("save"), new SingleValueModel<>(com.body), (field) -> {
RadicleBundle.message("save"), new SingleValueModel<>(com.body), f -> true).build();

Check warning on line 135 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/issues/overview/IssueComponent.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.intellij.collaboration.ui.SingleValueModel' is declared in unstable package 'com.intellij.collaboration.ui' marked with @ApiStatus.Experimental

Check warning on line 135 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/issues/overview/IssueComponent.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'SingleValueModel(T)' is declared in unstable package 'com.intellij.collaboration.ui' marked with @ApiStatus.Experimental
// TODO: disabling editing issue comment
/*(field) -> {
var edited = api.editIssueComment(radIssue, field.getText(), com.id, field.getEmbedList());
final boolean success = edited != null;
if (success) {
issueModel.setValue(radIssue);
}
return success;
}).build();
var contentPanel = panelHandle.panel;
}*/
var actionsPanel = CollaborationToolsUIUtilKt.HorizontalListPanel(CodeReviewCommentUIUtil.Actions.HORIZONTAL_GAP);

Check warning on line 145 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/issues/overview/IssueComponent.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'HORIZONTAL_GAP' is declared in unstable package 'com.intellij.collaboration.ui.codereview.comment' marked with @ApiStatus.Experimental

Check warning on line 145 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/issues/overview/IssueComponent.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.intellij.collaboration.ui.CollaborationToolsUIUtilKt' is declared in unstable package 'com.intellij.collaboration.ui' marked with @ApiStatus.Experimental

Check warning on line 145 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/issues/overview/IssueComponent.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.intellij.collaboration.ui.codereview.comment.CodeReviewCommentUIUtil.Actions' is declared in unstable package 'com.intellij.collaboration.ui.codereview.comment' marked with @ApiStatus.Experimental

Check warning on line 145 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/issues/overview/IssueComponent.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'HorizontalListPanel(int)' is declared in unstable package 'com.intellij.collaboration.ui' marked with @ApiStatus.Experimental

Check warning on line 145 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/issues/overview/IssueComponent.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.intellij.collaboration.ui.codereview.comment.CodeReviewCommentUIUtil' is declared in unstable package 'com.intellij.collaboration.ui.codereview.comment' marked with @ApiStatus.Experimental
actionsPanel.add(CodeReviewCommentUIUtil.INSTANCE.createEditButton(e -> {
/* actionsPanel.add(CodeReviewCommentUIUtil.INSTANCE.createEditButton(e -> {

Check notice on line 146 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/issues/overview/IssueComponent.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Commented out code

Commented out code (4 lines)
panelHandle.showAndFocusEditor();
return null;
}));
})); */
var contentPanel = panelHandle.panel;
mainPanel.add(createTimeLineItem(contentPanel, actionsPanel, com.author.generateLabelText(), com.timestamp));
}
return mainPanel;
Expand Down Expand Up @@ -193,10 +195,7 @@ private JComponent getHeader() {
RadicleBundle.message("issue.change.title"),
new SingleValueModel<>(radIssue.title), (field) -> {

Check warning on line 196 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/issues/overview/IssueComponent.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.intellij.collaboration.ui.SingleValueModel' is declared in unstable package 'com.intellij.collaboration.ui' marked with @ApiStatus.Experimental

Check warning on line 196 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/issues/overview/IssueComponent.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'SingleValueModel(T)' is declared in unstable package 'com.intellij.collaboration.ui' marked with @ApiStatus.Experimental
// TODO: this will not work
// var edited = cli.changeIssueTitleDescription(radIssue, field.getText(), radIssue.getDescription());
var issue = new RadIssue(radIssue);
issue.title = field.getText();
var edited = api.changeIssueTitle(issue);
var edited = cli.changeIssueTitleDescription(radIssue, field.getText(), radIssue.getDescription());
final boolean success = edited != null;
if (success) {
issueModel.setValue(edited);

Check warning on line 201 in src/main/java/network/radicle/jetbrains/radiclejetbrainsplugin/issues/overview/IssueComponent.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'setValue(T)' is declared in unstable package 'com.intellij.collaboration.ui' marked with @ApiStatus.Experimental
Expand Down Expand Up @@ -271,7 +270,8 @@ public RadIssue addEmoji(Emoji emoji, String discussionId) {

@Override
public RadIssue removeEmoji(String emojiUnicode, String discussionId) {
return api.issueCommentReact(radIssue, discussionId, emojiUnicode, false);
//return api.issueCommentReact(radIssue, discussionId, emojiUnicode, false);
return cli.issueCommentReact(radIssue, discussionId, emojiUnicode, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package network.radicle.jetbrains.radiclejetbrainsplugin.services;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
Expand All @@ -11,7 +10,6 @@
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.serviceContainer.NonInjectable;
import git4idea.repo.GitRepository;
import network.radicle.jetbrains.radiclejetbrainsplugin.RadicleBundle;
import network.radicle.jetbrains.radiclejetbrainsplugin.actions.rad.RadSelf;
import network.radicle.jetbrains.radiclejetbrainsplugin.config.RadicleProjectSettingsHandler;
Expand Down Expand Up @@ -93,55 +91,6 @@ public SeedNodeInfo checkApi(SeedNode node, boolean showNotif) {
}
}

public RadIssue editIssueComment(RadIssue issue, String comment, String id, List<Embed> embedList) {
var session = createAuthenticatedSession();
if (session == null) {
return null;
}
try {
var issueReq = new HttpPatch(getHttpNodeUrl() + "/api/v1/projects/" + issue.projectId + "/issues/" + issue.id);
issueReq.setHeader("Authorization", "Bearer " + session.sessionId);
var patchIssueData = Map.of("type", "comment.edit", "id", id, "body", comment, "replyTo", issue.id, "embeds", embedList);
var json = MAPPER.writeValueAsString(patchIssueData);
issueReq.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
var resp = makeRequest(issueReq, RadicleBundle.message("commentEditError"), RadicleBundle.message("commentDescError"));
if (!resp.isSuccess()) {
logger.warn("error editing comment: {} to issue:{} resp:{}", comment, issue, resp);
return null;
}
return issue;
} catch (Exception e) {
logger.warn("error editing issue comment: {}", issue, e);
}
return null;
}

public String createPatch(String title, String description, List<String> labels, String baseOid, String patchOid, GitRepository repo, String projectId) {
var session = createAuthenticatedSession();
if (session == null) {
return null;
}
try {
var patchReq = new HttpPost(getHttpNodeUrl() + "/api/v1/projects/" + projectId + "/patches");
patchReq.setHeader("Authorization", "Bearer " + session.sessionId);
var patchIssueData = Map.of("title", title, "description", description, "oid", patchOid, "target", baseOid, "labels", labels);
var json = MAPPER.writeValueAsString(patchIssueData);
patchReq.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
var resp = makeRequest(patchReq, RadicleBundle.message("createPatchError"));
if (!resp.isSuccess()) {
logger.warn("error creating new patch title:{} description:{} base_oid:{} patch_oid:{} repo:{} projectId:{}",
title, description, baseOid, patchOid, repo, projectId);
return null;
}
var map = (Map<String, String>) MAPPER.readValue(resp.body, new TypeReference<>() { });
return map.get("id");
} catch (Exception e) {
logger.warn("exception creating new patch title:{} description:{} base_oid:{} patch_oid:{} repo:{} projectId:{}",
title, description, baseOid, patchOid, repo, projectId, e);
}
return null;
}

public RadPatch deleteRevisionComment(RadPatch patch, String revId, String commentId) {
var session = createAuthenticatedSession();
if (session == null) {
Expand Down Expand Up @@ -189,53 +138,6 @@ public RadPatch patchCommentReact(RadPatch patch, String commendId, String revId
return null;
}

public RadIssue issueCommentReact(RadIssue issue, String discussionId, String reaction, boolean active) {
var session = createAuthenticatedSession();
if (session == null) {
return null;
}
try {
var issueReq = new HttpPatch(getHttpNodeUrl() + "/api/v1/projects/" + issue.projectId + "/issues/" + issue.id);
issueReq.setHeader("Authorization", "Bearer " + session.sessionId);
var issueData = Map.of("type", "comment.react", "id", discussionId, "reaction", reaction, "active", active);
var json = MAPPER.writeValueAsString(issueData);
issueReq.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
var resp = makeRequest(issueReq, RadicleBundle.message("reactionError"));
if (!resp.isSuccess()) {
logger.warn("error reacting to discussion:{} resp:{}", discussionId, resp);
return null;
}
return issue;
} catch (Exception e) {
logger.warn("error reacting to discussion: {}", discussionId, e);
}

return null;
}

public RadIssue changeIssueTitle(RadIssue issue) {
var session = createAuthenticatedSession();
if (session == null) {
return null;
}
try {
var issueReq = new HttpPatch(getHttpNodeUrl() + "/api/v1/projects/" + issue.projectId + "/issues/" + issue.id);
issueReq.setHeader("Authorization", "Bearer " + session.sessionId);
var patchEditData = Map.of("type", "edit", "title", issue.title);
var json = MAPPER.writeValueAsString(patchEditData);
issueReq.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
var resp = makeRequest(issueReq, RadicleBundle.message("issueTitleError"));
if (!resp.isSuccess()) {
logger.warn("received invalid response with status:{} and body:{} while editing patch: {}",
resp.status, resp.body, issue);
}
return issue;
} catch (Exception e) {
logger.warn("error changing issue title: {}", issue, e);
}
return null;
}

public RadPatch changePatchComment(String revisionId, String commentId, String body, RadPatch patch, List<Embed> embedList) {
var session = createAuthenticatedSession();
if (session == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ public ProcessOutput editPatchTitleDescription(GitRepository repo, String patchI
}

public ProcessOutput editIssueTitleDescription(GitRepository repo, String issueId, String title, String description) {
// TODO: this is not going to work, as `rad issue edit` does not support `--message`
return executeCommandFromFile(repo, List.of("issue", "edit", issueId, "--message",
ExecUtil.escapeUnixShellArgument(Strings.nullToEmpty(title) + "\n\n" + Strings.nullToEmpty(description))));
// TODO: this is not going to work, as `rad issue edit` does not support `--title` and `--description` yet
return executeCommandFromFile(repo, List.of("issue", "edit", issueId, "--title", ExecUtil.escapeUnixShellArgument(Strings.nullToEmpty(title)),
"--description", ExecUtil.escapeUnixShellArgument(Strings.nullToEmpty(description))));
}

public ProcessOutput addRemovePatchLabels(GitRepository root, String patchId, List<String> addedLabels, List<String> deletedLabels) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package network.radicle.jetbrains.radiclejetbrainsplugin;

import com.google.common.base.Strings;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.notification.Notification;
import com.intellij.notification.Notifications;
Expand Down Expand Up @@ -34,7 +35,6 @@
import network.radicle.jetbrains.radiclejetbrainsplugin.services.RadicleProjectApi;
import network.radicle.jetbrains.radiclejetbrainsplugin.services.auth.AuthService;
import org.apache.http.impl.client.CloseableHttpClient;
import org.assertj.core.util.Strings;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -241,11 +241,8 @@ public void replaceCliService(String head) {
var cliService = new RadicleCliService(myProject) {
@Override
public RadProject getRadRepo(GitRepository repo) {
if (Strings.isNullOrEmpty(head)) {
return new RadProject(RAD_PROJECT_ID, "test", "", "", PatchListPanelTest.getTestProjects().get(0).delegates);
} else {
return new RadProject(RAD_PROJECT_ID, "TestProject", "", "main", head, PatchListPanelTest.getTestProjects().get(0).delegates);
}
return new RadProject(RAD_PROJECT_ID, "TestProject", "TestProjectDescr", "main",
Strings.nullToEmpty(head), PatchListPanelTest.getTestProjects().get(0).delegates);
}
};
ServiceContainerUtil.replaceService(myProject, RadicleCliService.class, cliService, this.getTestRootDisposable());
Expand Down
Loading

0 comments on commit f752931

Please sign in to comment.