-
Notifications
You must be signed in to change notification settings - Fork 23
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
Fix Sourcegraph actions (search selection, open selection, etc) #325
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.sourcegraph.vcs | ||
|
||
import java.net.URL | ||
|
||
fun convertGitCloneURLToCodebaseNameOrError(cloneURL: String): String { | ||
|
||
// Handle common Git SSH URL format | ||
val matchResult = Regex("""^[\w-]+@([^:]+):([\w-]+)/([\w-]+)(\.git)?$""").find(cloneURL) | ||
if (matchResult != null) { | ||
val (host, owner, repo) = matchResult.destructured | ||
return "$host/$owner/$repo" | ||
} | ||
|
||
val uri = URL(cloneURL) | ||
|
||
// Handle Azure DevOps URLs | ||
if (uri.host?.contains("dev.azure") == true && uri.path.isNotEmpty()) { | ||
return "${uri.host}${uri.path.replace("/_git", "")}" | ||
} | ||
|
||
// Handle GitHub URLs | ||
if (uri.protocol?.startsWith("github") == true || uri.toString().startsWith("github")) { | ||
return "github.com/${uri.path.replace(".git", "")}" | ||
} | ||
|
||
// Handle GitLab URLs | ||
if (uri.protocol?.startsWith("gitlab") == true || uri.toString().startsWith("gitlab")) { | ||
return "gitlab.com/${uri.path.replace(".git", "")}" | ||
} | ||
|
||
// Handle HTTPS URLs | ||
if (uri.protocol?.startsWith("http") == true && uri.host != null && uri.path.isNotEmpty()) { | ||
return "${uri.host}${uri.path.replace(".git", "")}" | ||
} | ||
|
||
// Generic URL | ||
if (uri.host != null && uri.path.isNotEmpty()) { | ||
return "${uri.host}${uri.path.replace(".git", "")}" | ||
} | ||
|
||
return "" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.sourcegraph.vcs; | ||
|
||
import static com.sourcegraph.vcs.ConvertUtilKt.convertGitCloneURLToCodebaseNameOrError; | ||
|
||
import com.intellij.dvcs.repo.Repository; | ||
import com.intellij.dvcs.repo.VcsRepositoryManager; | ||
import com.intellij.openapi.diagnostic.Logger; | ||
|
@@ -11,12 +13,14 @@ | |
import com.sourcegraph.cody.agent.protocol.CloneURL; | ||
import com.sourcegraph.cody.config.CodyProjectSettings; | ||
import com.sourcegraph.common.ErrorNotification; | ||
import com.sourcegraph.config.ConfigUtil; | ||
import git4idea.GitVcs; | ||
import git4idea.repo.GitRepository; | ||
import java.io.File; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.jetbrains.idea.perforce.perforce.PerforceAuthenticationException; | ||
|
@@ -147,15 +151,22 @@ private static String doReplacements( | |
|
||
if (vcsType == VCSType.GIT && repository != null) { | ||
String cloneURL = GitUtil.getRemoteRepoUrl((GitRepository) repository, project); | ||
String codebaseName = | ||
CodyAgentService.getAgent(project) | ||
.thenCompose( | ||
agent -> | ||
agent.getServer().convertGitCloneURLToCodebaseName(new CloneURL(cloneURL))) | ||
.join(); | ||
String codebaseName = null; | ||
|
||
if (ConfigUtil.isCodyEnabled()) { | ||
codebaseName = | ||
CodyAgentService.getAgent(project) | ||
.thenCompose( | ||
agent -> | ||
agent.getServer().convertGitCloneURLToCodebaseName(new CloneURL(cloneURL))) | ||
.completeOnTimeout(/* value= */ null, /* timeout= */ 4, TimeUnit.SECONDS) | ||
.get(); | ||
} | ||
Comment on lines
+156
to
+164
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. Let's try to use agent only with Cody enabled. Also let's complete on timeout. |
||
|
||
if (codebaseName == null) { | ||
throw new Exception( | ||
"Failed to convert git clone URL to codebase name for cloneURL: " + cloneURL); | ||
logger.warn( | ||
"Failed to convert git clone URL to codebase name for cloneURL via agent: " + cloneURL); | ||
codebaseName = convertGitCloneURLToCodebaseNameOrError(cloneURL); | ||
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. This is a fallback... |
||
} | ||
return codebaseName; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,7 +156,7 @@ class CodyToolWindowContent(private val project: Project) : UpdatableChat { | |
SUBSCRIPTION_TAB_INDEX) | ||
} | ||
subscriptionPanel.update(data.isCurrentUserPro) | ||
} else { | ||
} else if (SUBSCRIPTION_TAB_INDEX < tabbedPane.tabCount) { | ||
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. unrel to the sourcegraph actions issue - minor fix ( |
||
tabbedPane.remove(SUBSCRIPTION_TAB_INDEX) | ||
} | ||
} | ||
|
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.
copied from the agent and translated (TS -> Kotlin)