-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce a type for CodebaseName #996
Changes from all commits
0e385f0
3c26d44
275e6a4
5e3e2bd
84fc070
b84df65
476ca23
2068473
419f13c
0480b77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,16 @@ import com.sourcegraph.cody.CodyToolWindowFactory | |
import com.sourcegraph.cody.api.SourcegraphApiRequestExecutor | ||
import com.sourcegraph.cody.api.SourcegraphApiRequests | ||
import com.sourcegraph.cody.history.HistoryService | ||
import com.sourcegraph.cody.history.state.ChatState | ||
import com.sourcegraph.cody.history.state.EnhancedContextState | ||
import com.sourcegraph.cody.history.state.LLMState | ||
import com.sourcegraph.cody.initialization.Activity | ||
import com.sourcegraph.config.AccessTokenStorage | ||
import com.sourcegraph.config.CodyApplicationService | ||
import com.sourcegraph.config.CodyProjectService | ||
import com.sourcegraph.config.ConfigUtil | ||
import com.sourcegraph.config.UserLevelConfig | ||
import com.sourcegraph.vcs.convertGitCloneURLToCodebaseNameOrError | ||
import java.util.concurrent.CompletableFuture | ||
|
||
class SettingsMigration : Activity { | ||
|
@@ -35,6 +38,9 @@ class SettingsMigration : Activity { | |
migrateAccounts(project) | ||
} | ||
RunOnceUtil.runOnceForProject(project, "CodyHistoryLlmMigration") { migrateLlms(project) } | ||
RunOnceUtil.runOnceForProject(project, "CodyConvertUrlToCodebaseName") { | ||
migrateUrlsToCodebaseNames(project) | ||
} | ||
RunOnceUtil.runOnceForApp("CodyApplicationSettingsMigration") { migrateApplicationSettings() } | ||
RunOnceUtil.runOnceForApp("ToggleCodyToolWindowAfterMigration") { | ||
toggleCodyToolbarWindow(project) | ||
|
@@ -105,6 +111,19 @@ class SettingsMigration : Activity { | |
} | ||
} | ||
|
||
private fun migrateUrlsToCodebaseNames(project: Project) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a test for that.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
val enhancedContextState = | ||
HistoryService.getInstance(project).state.defaultEnhancedContext ?: return | ||
|
||
migrateUrlsToCodebaseNames(enhancedContextState) | ||
|
||
HistoryService.getInstance(project) | ||
.state | ||
.chats | ||
.mapNotNull(ChatState::enhancedContext) | ||
.forEach(Companion::migrateUrlsToCodebaseNames) | ||
} | ||
|
||
private val modelToProviderAndTitle = | ||
mapOf( | ||
"Claude 2 by Anthropic" to Triple("anthropic/claude-2", "Anthropic", "claude 2"), | ||
|
@@ -391,5 +410,23 @@ class SettingsMigration : Activity { | |
|
||
companion object { | ||
private val LOG = logger<SettingsMigration>() | ||
|
||
fun migrateUrlsToCodebaseNames(enhancedContextState: EnhancedContextState) { | ||
val remoteRepositories = | ||
enhancedContextState.remoteRepositories | ||
.onEach { remoteRepositoryState -> | ||
runCatching { | ||
remoteRepositoryState.remoteUrl?.let { remoteUrl -> | ||
convertGitCloneURLToCodebaseNameOrError(remoteUrl) | ||
} | ||
} | ||
.getOrNull() | ||
?.let { remoteRepositoryState.codebaseName = it.value } | ||
} | ||
.filter { it.codebaseName != null } | ||
.distinctBy { it.codebaseName } | ||
.toMutableList() | ||
enhancedContextState.remoteRepositories = remoteRepositories | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import com.intellij.util.Alarm | |
import com.sourcegraph.cody.config.DialogValidationUtils | ||
import com.sourcegraph.cody.context.RemoteRepoUtils | ||
import com.sourcegraph.common.CodyBundle | ||
import com.sourcegraph.vcs.CodebaseName | ||
import com.sourcegraph.vcs.convertGitCloneURLToCodebaseNameOrError | ||
import java.awt.GridBagConstraints | ||
import java.awt.GridBagLayout | ||
|
@@ -23,7 +24,7 @@ import org.jetbrains.annotations.NotNull | |
class AddRepositoryDialog( | ||
private val project: Project, | ||
private val remoteContextNode: ContextTreeRemoteRootNode, | ||
private val addAction: (String) -> Unit | ||
private val addAction: (CodebaseName) -> Unit | ||
) : DialogWrapper(project) { | ||
|
||
private val repoUrlInputField = TextFieldWithAutoCompletion.create(project, listOf(), false, null) | ||
|
@@ -36,20 +37,20 @@ class AddRepositoryDialog( | |
} | ||
|
||
override fun doValidateAll(): List<ValidationInfo> { | ||
val text = repoUrlInputField.text.lowercase() | ||
|
||
fun validateNonEmpty() = | ||
DialogValidationUtils.custom( | ||
repoUrlInputField, | ||
CodyBundle.getString("context-panel.add-repo-dialog.error-empty-url")) { | ||
repoUrlInputField.text.isNotBlank() | ||
text.isNotBlank() | ||
} | ||
|
||
fun validateValidUrl() = | ||
DialogValidationUtils.custom( | ||
repoUrlInputField, | ||
CodyBundle.getString("context-panel.add-repo-dialog.error-invalid-url")) { | ||
val url = | ||
if (repoUrlInputField.text.startsWith("http")) repoUrlInputField.text | ||
else "http://" + repoUrlInputField.text | ||
val url = if (text.startsWith("http")) text else "http://$text" | ||
runCatching { URL(url) }.isSuccess | ||
} | ||
|
||
|
@@ -58,8 +59,7 @@ class AddRepositoryDialog( | |
repoUrlInputField, | ||
CodyBundle.getString("context-panel.add-repo-dialog.error-no-repo")) { | ||
val codebaseName = | ||
runCatching { convertGitCloneURLToCodebaseNameOrError(repoUrlInputField.text) } | ||
.getOrNull() | ||
runCatching { convertGitCloneURLToCodebaseNameOrError(text) }.getOrNull() | ||
codebaseName ?: return@custom false | ||
val repo = | ||
RemoteRepoUtils.getRepository(project, codebaseName) | ||
|
@@ -73,13 +73,12 @@ class AddRepositoryDialog( | |
repoUrlInputField, | ||
CodyBundle.getString("context-panel.add-repo-dialog.error-repo-already-added")) { | ||
val codebaseName = | ||
runCatching { convertGitCloneURLToCodebaseNameOrError(repoUrlInputField.text) } | ||
.getOrNull() | ||
runCatching { convertGitCloneURLToCodebaseNameOrError(text) }.getOrNull() | ||
remoteContextNode | ||
.children() | ||
.toList() | ||
.filterIsInstance<ContextTreeRemoteRepoNode>() | ||
.none { it.codebaseName == codebaseName?.lowercase() } | ||
.none { it.codebaseName == codebaseName } | ||
} | ||
|
||
return listOfNotNull( | ||
|
@@ -94,7 +93,9 @@ class AddRepositoryDialog( | |
} | ||
|
||
override fun doOKAction() { | ||
addAction(repoUrlInputField.text.lowercase()) | ||
runCatching { convertGitCloneURLToCodebaseNameOrError(repoUrlInputField.text.lowercase()) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move that conversion to lowercase inside |
||
.getOrNull() | ||
?.let { codebaseName -> addAction(codebaseName) } | ||
close(OK_EXIT_CODE, true) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the
value
always some kind of the url?If yes, maybe we can make the name more descriptive?
If no, maybe it warrants a comment what value we can expect there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
CodebaseName
is the description hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codebase name does not suggest url-like-string at all to me.
And it's not defined anywhere what it really means.
Anyway, it's just my point of view, there is nothing wrong with the code per se.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I'd say that's a good sign - it will be harder to confuse it with URL 😅