github source v1
This commit is contained in:
parent
71f89dde9c
commit
caf870d05e
50 changed files with 4139 additions and 131 deletions
|
|
@ -1,55 +1,13 @@
|
|||
use crate::domain::source::SourceKind;
|
||||
use crate::domain::source::SourceRef;
|
||||
use crate::source::input::classify_input;
|
||||
|
||||
pub fn resolve_query(query: &str) -> Result<SourceRef, ResolveQueryError> {
|
||||
if query.starts_with("file://") {
|
||||
return Ok(SourceRef {
|
||||
kind: SourceKind::File,
|
||||
locator: query.to_owned(),
|
||||
});
|
||||
}
|
||||
|
||||
if query.starts_with("https://gitlab.com/") || query.starts_with("http://gitlab.com/") {
|
||||
return Ok(SourceRef {
|
||||
kind: SourceKind::GitLab,
|
||||
locator: query.to_owned(),
|
||||
});
|
||||
}
|
||||
|
||||
if query.starts_with("https://") || query.starts_with("http://") {
|
||||
return Ok(SourceRef {
|
||||
kind: SourceKind::DirectUrl,
|
||||
locator: query.to_owned(),
|
||||
});
|
||||
}
|
||||
|
||||
if is_github_shorthand(query) {
|
||||
return Ok(SourceRef {
|
||||
kind: SourceKind::GitHub,
|
||||
locator: query.to_owned(),
|
||||
});
|
||||
}
|
||||
|
||||
Err(ResolveQueryError::Unsupported)
|
||||
classify_input(query)
|
||||
.map(|input| input.into_source_ref())
|
||||
.map_err(|_| ResolveQueryError::Unsupported)
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum ResolveQueryError {
|
||||
Unsupported,
|
||||
}
|
||||
|
||||
fn is_github_shorthand(query: &str) -> bool {
|
||||
let mut parts = query.split('/');
|
||||
let Some(owner) = parts.next() else {
|
||||
return false;
|
||||
};
|
||||
let Some(repo) = parts.next() else {
|
||||
return false;
|
||||
};
|
||||
|
||||
if parts.next().is_some() {
|
||||
return false;
|
||||
}
|
||||
|
||||
!owner.is_empty() && !repo.is_empty() && !owner.contains(':') && !repo.contains(':')
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue