Skip to content

Commit f03dc46

Browse files
committed
Enable converting config Source to GitProvider
1 parent 3e4a495 commit f03dc46

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

src/config.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::GitProvider;
12
use figment::{
23
providers::{Format, Serialized, Toml},
34
Figment,
@@ -110,6 +111,15 @@ struct Source {
110111
url: String,
111112
}
112113

114+
impl From<Source> for GitProvider {
115+
fn from(source: Source) -> Self {
116+
match source.provider {
117+
GitProviderType::Github => GitProvider::github(source.url.parse().unwrap()),
118+
GitProviderType::Gitlab => GitProvider::gitlab(source.url.parse().unwrap()),
119+
}
120+
}
121+
}
122+
113123
#[cfg(test)]
114124
mod tests {
115125
use super::*;

src/provider/core.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{github::Github, gitlab::Gitlab};
22
use crate::SshPublicKey;
3-
use reqwest::Client;
3+
use reqwest::{Client, Url};
44

55
/// A Git provider.
66
#[derive(Debug)]
@@ -10,6 +10,14 @@ pub enum GitProvider {
1010
}
1111

1212
impl GitProvider {
13+
pub fn github(url: Url) -> Self {
14+
Self::Github(Github::new(url))
15+
}
16+
17+
pub fn gitlab(url: Url) -> Self {
18+
Self::Gitlab(Gitlab::new(url))
19+
}
20+
1321
/// Get the public keys of a user by their username.
1422
async fn get_keys_by_username(
1523
&self,

src/provider/github.rs

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ impl Github {
1111
const VERSION: &'static str = "2022-11-28";
1212
const ACCEPT_HEADER: &'static str = "application/vnd.github+json";
1313

14+
pub fn new(base_url: Url) -> Self {
15+
Self { base_url }
16+
}
17+
1418
/// Get the signing keys of a user by their username.
1519
///
1620
/// # API documentation

src/provider/gitlab.rs

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ impl Gitlab {
1212
const VERSION: &'static str = "v4";
1313
const ACCEPT_HEADER: &'static str = "application/json";
1414

15+
pub fn new(base_url: Url) -> Self {
16+
Self { base_url }
17+
}
18+
1519
/// Get the signing keys of a user by their username.
1620
///
1721
/// # API documentation

0 commit comments

Comments
 (0)