-
Notifications
You must be signed in to change notification settings - Fork 52
Github enterprise support #158
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -74,7 +74,27 @@ pub async fn init() -> Result<()> { | |
| return Err(Error::new("Cannot continue without an access token.")); | ||
| } | ||
|
|
||
| let github_api_domain = dialoguer::Input::<String>::new() | ||
| .with_prompt("Github API domain (override for Github Enterprise)") | ||
| .with_initial_text( | ||
| config | ||
| .get_string("spr.githubApiDomain") | ||
| .ok() | ||
| .unwrap_or_else(|| "api.github.com".to_string()), | ||
| ) | ||
| .interact_text()?; | ||
|
|
||
| config.set_str("spr.githubApiDomain", &github_api_domain)?; | ||
|
|
||
| let api_base_url; | ||
| if github_api_domain == "api.github.com" { | ||
| api_base_url = "https://api.github.com/v3/".into() | ||
|
Contributor
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 should be without the
Contributor
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. @andrewhamon can you check if this is correct? I haven't tested this PR personally yet, but it looks like this is the non-enterprise case, so we obviously need to not break that too :) |
||
| } else { | ||
| api_base_url = format!("https://{github_api_domain}/api/v3/"); | ||
| }; | ||
|
|
||
| let octocrab = octocrab::OctocrabBuilder::new() | ||
| .base_url(api_base_url)? | ||
| .personal_token(pat.clone()) | ||
| .build()?; | ||
| let github_user = octocrab.current().user().await?; | ||
|
|
@@ -121,7 +141,7 @@ pub async fn init() -> Result<()> { | |
|
|
||
| let url = repo.find_remote(&remote)?.url().map(String::from); | ||
| let regex = | ||
| lazy_regex::regex!(r#"github\.com[/:]([\w\-\.]+/[\w\-\.]+?)(.git)?$"#); | ||
| lazy_regex::regex!(r#"[^/]+[/:]([\w\-\.]+/[\w\-\.]+?)(.git)?$"#); | ||
| let github_repo = config | ||
| .get_string("spr.githubRepository") | ||
| .ok() | ||
|
|
||
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.
It seems we're special-casing
api.github.comconsistently, almost using it as a sentinel value, as opposed to actually using the value itself. (i.e., every place we readspr.githubApiDomainwe check forapi.github.comand then do something different if that is the value, as opposed to using that value itself.)So instead, can we make this an
Option<string>, withNonemeaning "the default non-enterprise", andSome<x>meaning "usexas the enterprise base URL" -- since we are special-casingapi.github.com100% of the time anyway? That seems more consistent with what is actually going on here.