Skip to content

Commit 9ec147d

Browse files
authored
Update Copilot sign-up URL based on verification domain (#44085)
Use the url crate to extract the domain from the verification URI and construct the appropriate Copilot sign-up URL for GitHub or GitHub Enterprise. Release Notes: - Improved github enterprise (ghe) copilot sign in
1 parent 9c32c29 commit 9ec147d

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/copilot/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ui.workspace = true
5252
util.workspace = true
5353
workspace.workspace = true
5454
itertools.workspace = true
55+
url.workspace = true
5556

5657
[target.'cfg(windows)'.dependencies]
5758
async-std = { version = "1.12.0", features = ["unstable"] }

crates/copilot/src/sign_in.rs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use gpui::{
66
Subscription, Window, WindowBounds, WindowOptions, div, point,
77
};
88
use ui::{ButtonLike, CommonAnimationExt, ConfiguredApiCard, Vector, VectorName, prelude::*};
9+
use url::Url;
910
use util::ResultExt as _;
1011
use workspace::{Toast, Workspace, notifications::NotificationId};
1112

@@ -152,6 +153,7 @@ pub struct CopilotCodeVerification {
152153
focus_handle: FocusHandle,
153154
copilot: Entity<Copilot>,
154155
_subscription: Subscription,
156+
sign_up_url: Option<String>,
155157
}
156158

157159
impl Focusable for CopilotCodeVerification {
@@ -183,11 +185,22 @@ impl CopilotCodeVerification {
183185
.detach();
184186

185187
let status = copilot.read(cx).status();
188+
// Determine sign-up URL based on verification_uri domain if available
189+
let sign_up_url = if let Status::SigningIn {
190+
prompt: Some(ref prompt),
191+
} = status
192+
{
193+
// Extract domain from verification_uri to construct sign-up URL
194+
Self::get_sign_up_url_from_verification(&prompt.verification_uri)
195+
} else {
196+
None
197+
};
186198
Self {
187199
status,
188200
connect_clicked: false,
189201
focus_handle: cx.focus_handle(),
190202
copilot: copilot.clone(),
203+
sign_up_url,
191204
_subscription: cx.observe(copilot, |this, copilot, cx| {
192205
let status = copilot.read(cx).status();
193206
match status {
@@ -201,10 +214,30 @@ impl CopilotCodeVerification {
201214
}
202215

203216
pub fn set_status(&mut self, status: Status, cx: &mut Context<Self>) {
217+
// Update sign-up URL if we have a new verification URI
218+
if let Status::SigningIn {
219+
prompt: Some(ref prompt),
220+
} = status
221+
{
222+
self.sign_up_url = Self::get_sign_up_url_from_verification(&prompt.verification_uri);
223+
}
204224
self.status = status;
205225
cx.notify();
206226
}
207227

228+
fn get_sign_up_url_from_verification(verification_uri: &str) -> Option<String> {
229+
// Extract domain from verification URI using url crate
230+
if let Ok(url) = Url::parse(verification_uri)
231+
&& let Some(host) = url.host_str()
232+
&& !host.contains("github.com")
233+
{
234+
// For GHE, construct URL from domain
235+
Some(format!("https://{}/features/copilot", host))
236+
} else {
237+
None
238+
}
239+
}
240+
208241
fn render_device_code(data: &PromptUserDeviceFlow, cx: &mut Context<Self>) -> impl IntoElement {
209242
let copied = cx
210243
.read_from_clipboard()
@@ -302,7 +335,12 @@ impl CopilotCodeVerification {
302335
)
303336
}
304337

305-
fn render_unauthorized_modal(cx: &mut Context<Self>) -> impl Element {
338+
fn render_unauthorized_modal(&self, cx: &mut Context<Self>) -> impl Element {
339+
let sign_up_url = self
340+
.sign_up_url
341+
.as_deref()
342+
.unwrap_or(COPILOT_SIGN_UP_URL)
343+
.to_owned();
306344
let description = "Enable Copilot by connecting your existing license once you have subscribed or renewed your subscription.";
307345

308346
v_flex()
@@ -319,7 +357,7 @@ impl CopilotCodeVerification {
319357
.full_width()
320358
.style(ButtonStyle::Outlined)
321359
.size(ButtonSize::Medium)
322-
.on_click(|_, _, cx| cx.open_url(COPILOT_SIGN_UP_URL)),
360+
.on_click(move |_, _, cx| cx.open_url(&sign_up_url)),
323361
)
324362
.child(
325363
Button::new("copilot-subscribe-cancel-button", "Cancel")
@@ -374,7 +412,7 @@ impl Render for CopilotCodeVerification {
374412
} => Self::render_prompting_modal(self.connect_clicked, prompt, cx).into_any_element(),
375413
Status::Unauthorized => {
376414
self.connect_clicked = false;
377-
Self::render_unauthorized_modal(cx).into_any_element()
415+
self.render_unauthorized_modal(cx).into_any_element()
378416
}
379417
Status::Authorized => {
380418
self.connect_clicked = false;

0 commit comments

Comments
 (0)