-
Notifications
You must be signed in to change notification settings - Fork 18
Feat: add simpler interface to install from Github repo with rv add owner/repo
#414
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
Open
JosephBARBIERDARNAL
wants to merge
6
commits into
A2-ai:main
Choose a base branch
from
JosephBARBIERDARNAL:install-pkg-github
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6c05bde
add simple interface to install from Github repo, or other urls #404
JosephBARBIERDARNAL a8e6bb0
run sync after writing to config
JosephBARBIERDARNAL 731fb73
run sync after writing to config
JosephBARBIERDARNAL 5437953
remove colon
JosephBARBIERDARNAL 89165d2
normalize owner/repo specs into branch/tag, and drop reference field
JosephBARBIERDARNAL 1a9c28d
Merge branch 'main' into install-pkg-github
Keats File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,4 +13,6 @@ from*/ | |
| logs/ | ||
| dist/ | ||
| global-cache/ | ||
| drift-reviews/ | ||
| drift-reviews/ | ||
|
|
||
| temp-pkg | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ use std::str::FromStr; | |
|
|
||
| use crate::SystemInfo; | ||
| use crate::consts::LOCKFILE_NAME; | ||
| use crate::dependency_edit::DEFAULT_GIT_SHORTHAND_BASE_URL; | ||
| use crate::git::url::GitUrl; | ||
| use crate::lockfile::Source; | ||
| use crate::package::{Version, deserialize_version, serialize_version}; | ||
|
|
@@ -84,6 +85,8 @@ pub enum ConfigDependency { | |
| commit: Option<String>, | ||
| tag: Option<String>, | ||
| branch: Option<String>, | ||
| #[serde(default)] | ||
| reference: Option<String>, | ||
| directory: Option<String>, | ||
| name: String, | ||
| #[serde(default)] | ||
|
|
@@ -176,13 +179,15 @@ impl ConfigDependency { | |
| directory, | ||
| tag, | ||
| branch, | ||
| reference, | ||
| .. | ||
| } => Source::Git { | ||
| git, | ||
| sha, | ||
| directory, | ||
| tag, | ||
| branch, | ||
| reference, | ||
| }, | ||
| _ => unreachable!(), | ||
| } | ||
|
|
@@ -351,6 +356,10 @@ pub(crate) struct Project { | |
| /// Package-specific configure.args with system targeting | ||
| #[serde(default)] | ||
| pub configure_args: HashMap<String, Vec<ConfigureArgsRule>>, | ||
| /// Base URL used by `rv add <owner>/<repo>` shorthand. | ||
| /// Defaults to https://github.com when not specified. | ||
| #[serde(default)] | ||
| git_shorthand_base_url: Option<String>, | ||
| } | ||
|
|
||
| // That's the way to do it with serde :/ | ||
|
|
@@ -424,17 +433,46 @@ impl Config { | |
| tag, | ||
| branch, | ||
| commit, | ||
| reference, | ||
| .. | ||
| } => match (tag.is_some(), branch.is_some(), commit.is_some()) { | ||
| (true, false, false) | (false, true, false) | (false, false, true) => (), | ||
| } => match ( | ||
| tag.is_some(), | ||
| branch.is_some(), | ||
| commit.is_some(), | ||
| reference.is_some(), | ||
| ) { | ||
| (true, false, false, false) | ||
| | (false, true, false, false) | ||
| | (false, false, true, false) | ||
| | (false, false, false, true) => (), | ||
| _ => { | ||
| errors.push(format!("A git dependency `{git}` requires ons and only one of tag/branch/commit set. ")); | ||
| errors.push(format!( | ||
| "A git dependency `{git}` requires one and only one of tag/branch/commit/reference set." | ||
| )); | ||
| } | ||
| }, | ||
| _ => (), | ||
| } | ||
| } | ||
|
|
||
| if let Some(base_url) = self.project.git_shorthand_base_url.as_deref() { | ||
| let base_url = base_url.trim(); | ||
| if base_url.is_empty() { | ||
| errors.push("`project.git_shorthand_base_url` cannot be empty.".to_string()); | ||
| } else { | ||
| let probe_url = if base_url.ends_with(':') { | ||
| format!("{base_url}owner/repo") | ||
| } else { | ||
| format!("{}/owner/repo", base_url.trim_end_matches('/')) | ||
| }; | ||
|
Collaborator
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. is that the same for gitlab/gitea? |
||
| if let Err(e) = GitUrl::try_from(probe_url.as_str()) { | ||
| errors.push(format!( | ||
| "Invalid `project.git_shorthand_base_url` `{base_url}`: {e}" | ||
| )); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if !errors.is_empty() { | ||
| return Err(ConfigLoadError { | ||
| path: Path::new(".").into(), | ||
|
|
@@ -509,6 +547,13 @@ impl Config { | |
| pub fn configure_args(&self) -> &HashMap<String, Vec<ConfigureArgsRule>> { | ||
| &self.project.configure_args | ||
| } | ||
|
|
||
| pub fn git_shorthand_base_url(&self) -> &str { | ||
| self.project | ||
| .git_shorthand_base_url | ||
| .as_deref() | ||
| .unwrap_or(DEFAULT_GIT_SHORTHAND_BASE_URL) | ||
| } | ||
| } | ||
|
|
||
| impl FromStr for Config { | ||
|
|
@@ -582,4 +627,71 @@ repositories = [] | |
| deserialized.r_version().original | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn git_dependency_allows_reference_field() { | ||
| let toml_str = r#" | ||
| [project] | ||
| name = "test" | ||
| r_version = "4.4" | ||
| repositories = [] | ||
| dependencies = [ | ||
| { name = "cli", git = "https://github.com/r-lib/cli", reference = "main" } | ||
| ] | ||
| "#; | ||
| let config = Config::from_str(toml_str).unwrap(); | ||
| match &config.dependencies()[0] { | ||
| ConfigDependency::Git { reference, .. } => { | ||
| assert_eq!(reference.as_deref(), Some("main")); | ||
| } | ||
| _ => panic!("Expected a git dependency"), | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn git_shorthand_base_url_defaults_and_overrides() { | ||
| let default_toml = r#" | ||
| [project] | ||
| name = "test" | ||
| r_version = "4.4" | ||
| repositories = [] | ||
| "#; | ||
| let default_config = Config::from_str(default_toml).unwrap(); | ||
| assert_eq!( | ||
| default_config.git_shorthand_base_url(), | ||
| crate::dependency_edit::DEFAULT_GIT_SHORTHAND_BASE_URL | ||
| ); | ||
|
|
||
| let custom_toml = r#" | ||
| [project] | ||
| name = "test" | ||
| r_version = "4.4" | ||
| repositories = [] | ||
| git_shorthand_base_url = "https://git.example.com/scm" | ||
| "#; | ||
| let custom_config = Config::from_str(custom_toml).unwrap(); | ||
| assert_eq!( | ||
| custom_config.git_shorthand_base_url(), | ||
| "https://git.example.com/scm" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn invalid_git_shorthand_base_url_errors() { | ||
| let toml_str = r#" | ||
| [project] | ||
| name = "test" | ||
| r_version = "4.4" | ||
| repositories = [] | ||
| git_shorthand_base_url = "git.example.com" | ||
| "#; | ||
| let err = Config::from_str(toml_str).unwrap_err(); | ||
| assert!( | ||
| err.source | ||
| .to_string() | ||
| .contains("Invalid `project.git_shorthand_base_url`"), | ||
| "unexpected error: {}", | ||
| err.source | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.