Skip to content

Commit

Permalink
Add tests and build workflow, bump sinceVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
carlrobertoh committed May 1, 2023
1 parent a7927ee commit 4ceca4e
Show file tree
Hide file tree
Showing 16 changed files with 418 additions and 52 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build

on:
push:
branches: [ master ]
pull_request:
branches: [ '**' ]

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Fetch Sources
uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Run Tests
run: ./gradlew check

- name: Collect Tests Result
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: tests-result
path: ${{ github.workspace }}/build/reports/tests

- name: Run Plugin Verification tasks
run: ./gradlew runPluginVerifier
77 changes: 48 additions & 29 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,49 +1,68 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
id("java")
id("org.jetbrains.intellij") version "1.13.3"
id("java")
id("org.jetbrains.intellij") version "1.13.3"
}

group = "ee.carlrobert"
version = "1.10.5"

repositories {
mavenCentral()
mavenCentral()
}

intellij {
version.set("2022.2")
type.set("IC")
plugins.set(listOf())
version.set("2022.2")
type.set("IC")
plugins.set(listOf())
}

dependencies {
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.14.2")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2")
implementation("com.fifesoft:rsyntaxtextarea:3.3.2")
implementation("com.vladsch.flexmark:flexmark-all:0.64.0")
implementation("org.apache.commons:commons-text:1.10.0")
implementation("ee.carlrobert:openai-client:1.0.14")
implementation("com.knuddels:jtokkit:0.2.0")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.14.2")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2")
implementation("com.fifesoft:rsyntaxtextarea:3.3.2")
implementation("com.vladsch.flexmark:flexmark-all:0.64.0")
implementation("org.apache.commons:commons-text:1.10.0")
implementation("ee.carlrobert:openai-client:1.0.14")
implementation("com.knuddels:jtokkit:0.2.0")

testImplementation("org.assertj:assertj-core:3.24.2")
testImplementation("org.awaitility:awaitility:4.2.0")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.6.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.1")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.6.1")
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

tasks {
patchPluginXml {
sinceBuild.set("213")
untilBuild.set("231.*")
}

signPlugin {
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
privateKey.set(System.getenv("PRIVATE_KEY"))
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
}

publishPlugin {
token.set(System.getenv("PUBLISH_TOKEN"))
}
}

tasks {
patchPluginXml {
sinceBuild.set("211")
untilBuild.set("231.*")
}

signPlugin {
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
privateKey.set(System.getenv("PRIVATE_KEY"))
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
}

publishPlugin {
token.set(System.getenv("PUBLISH_TOKEN"))
}
test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PluginStartupActivity implements StartupActivity {
public void runActivity(@NotNull Project project) {
ActionsUtil.refreshActions(ConfigurationState.getInstance().tableData);
var settings = SettingsState.getInstance();
if (settings.apiKey != null && settings.useOpenAIAccountName) {
if (!settings.apiKey.isEmpty() && settings.useOpenAIAccountName) {
ClientProvider.getDashboardClient()
.getSubscriptionAsync(subscription ->
settings.displayName = subscription.getAccountName());
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/ee/carlrobert/codegpt/client/ClientProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ private static OpenAIClient.Builder getClientBuilder() {
var proxyHost = advancedSettings.proxyHost;
var proxyPort = advancedSettings.proxyPort;
if (!proxyHost.isEmpty() && proxyPort != 0) {
builder.setProxy(new Proxy(advancedSettings.proxyType, new InetSocketAddress(proxyHost, proxyPort)));
builder.setProxy(
new Proxy(advancedSettings.proxyType, new InetSocketAddress(proxyHost, proxyPort)));
if (advancedSettings.isProxyAuthSelected) {
builder.setProxyAuthenticator(new ProxyAuthenticator(advancedSettings.proxyUsername, advancedSettings.proxyPassword));
builder.setProxyAuthenticator(
new ProxyAuthenticator(advancedSettings.proxyUsername, advancedSettings.proxyPassword));
}
}

if (!advancedSettings.host.isEmpty()) {
builder.setHost(advancedSettings.host);
}

return builder;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/ee/carlrobert/codegpt/client/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ public void onError(ErrorDetails errorDetails) {
}

private void saveConversation(String response) {
var conversationsState = ConversationsState.getInstance();
var conversationMessages = conversation.getMessages();

if (isRetry && !conversationMessages.isEmpty()) {
conversationMessages.remove(conversationMessages.size() - 1);
}

message.setResponse(response);
conversationsState.saveConversation(conversation);
conversation.addMessage(message);
ConversationsState.getInstance().saveConversation(conversation);
}
}
10 changes: 5 additions & 5 deletions src/main/java/ee/carlrobert/codegpt/client/RequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ protected void process(List<String> chunks) {
}
};
swingWorker.execute();

}

public void cancel() {
Expand All @@ -63,10 +62,11 @@ private EventSource startCall(Message message, EventListener eventListener) {

if (settings.isChatCompletionOptionSelected) {
return ClientProvider.getChatCompletionClient(settings).stream(
requestProvider.buildChatCompletionRequest(settings.chatCompletionBaseModel),
eventListener);
requestProvider.buildChatCompletionRequest(settings.chatCompletionBaseModel),
eventListener);
}
return ClientProvider.getTextCompletionClient(settings).stream(
requestProvider.buildTextCompletionRequest(settings.textCompletionBaseModel),
eventListener); }
requestProvider.buildTextCompletionRequest(settings.textCompletionBaseModel),
eventListener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,24 @@ public void clearAll() {
currentConversation = null;
}

public Optional<Conversation> getNextConversation() {
public Optional<Conversation> getPreviousConversation() {
return tryGetNextOrPreviousConversation(true);
}

public Optional<Conversation> getPreviousConversation() {
public Optional<Conversation> getNextConversation() {
return tryGetNextOrPreviousConversation(false);
}

private Optional<Conversation> tryGetNextOrPreviousConversation(boolean isNext) {
private Optional<Conversation> tryGetNextOrPreviousConversation(boolean isPrevious) {
if (currentConversation != null) {
var sortedConversations = getSortedConversations();
for (int i = 0; i < sortedConversations.size(); i++) {
var conversation = sortedConversations.get(i);
if (conversation != null && conversation.getId().equals(currentConversation.getId())) {
var nextIndex = isNext ? i + 1 : i - 1;
if (isNext ? nextIndex < sortedConversations.size() : nextIndex != -1) {
return Optional.of(sortedConversations.get(nextIndex));
// higher index indicates older conversation
var previousIndex = isPrevious ? i + 1 : i - 1;
if (isPrevious ? previousIndex < sortedConversations.size() : previousIndex != -1) {
return Optional.of(sortedConversations.get(previousIndex));
}
}
}
Expand All @@ -147,9 +148,9 @@ private Optional<Conversation> tryGetNextOrPreviousConversation(boolean isNext)
}

public void deleteSelectedConversation() {
var nextConversation = getNextConversation();
var nextConversation = getPreviousConversation();
if (nextConversation.isEmpty()) {
nextConversation = getPreviousConversation();
nextConversation = getNextConversation();
}

var iterator = conversationsContainer.getConversationsMapping()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public class Message {
private final String prompt;
private String response;

public Message(String prompt, String response) {
this(prompt);
this.response = response;
}

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public Message(@JsonProperty("prompt") String prompt) {
this.id = UUID.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)
public class AdvancedSettingsState implements PersistentStateComponent<AdvancedSettingsState> {

public String host = "";
public String proxyHost = "";
public int proxyPort;
public Proxy.Type proxyType = Proxy.Type.SOCKS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public void handleMessage(String response, String fullMessage) {

public void handleComplete() {
stop();
conversation.addMessage(message);
}

public void handleTokensExceeded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public void update(@NotNull AnActionEvent event) {

@Override
protected Optional<Conversation> getConversation() {
return ConversationsState.getInstance().getNextConversation();
return ConversationsState.getInstance().getPreviousConversation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public void update(@NotNull AnActionEvent event) {

@Override
protected Optional<Conversation> getConversation() {
return ConversationsState.getInstance().getPreviousConversation();
return ConversationsState.getInstance().getNextConversation();
}
}
3 changes: 2 additions & 1 deletion src/main/java/ee/carlrobert/codegpt/util/ThemeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public static String getBackgroundColorRGB() {
}

public static String getFontColorRGB() {
return getRGB(EditorColorsManager.getInstance().getSchemeForCurrentUITheme().getDefaultForeground());
return getRGB(
EditorColorsManager.getInstance().getSchemeForCurrentUITheme().getDefaultForeground());
}

public static String getSeparatorColorRGB() {
Expand Down
Loading

0 comments on commit 4ceca4e

Please sign in to comment.