Added contact to register call
ci/woodpecker/push/woodpecker Pipeline failed Details

This commit is contained in:
Martin Slot 2022-12-07 08:47:37 +01:00
parent a5d4044ec8
commit dbb63f269e
4 changed files with 43 additions and 15 deletions

View File

@ -21,6 +21,7 @@ pub enum ArgumentParserError {
NameError,
UrlError,
VersionError,
ContactError,
CommandMissingError,
}
@ -36,6 +37,7 @@ pub enum Action {
vcsType: VcsType,
name: String,
version: String,
contact: String,
},
Request,
List,
@ -62,13 +64,14 @@ impl ArgumentParser {
Command::new("current").subcommand(
Command::new("github")
.arg(arg!([name]))
.arg(arg!([version])),
.arg(arg!([version]))
.arg(arg!([contact])),
),
),
)
.get_matches_from(parameters);
// TODO: This should be rethought. Right now it covers all, but it is a pain to more VcsTypes possible
// TODO: This should be rethought. Right now it covers all, but it is a pain to add more VcsTypes
match matches.subcommand() {
Some(("list", sub_matches)) => Ok(Action::List),
Some(("request", sub_matches)) => Ok(Action::Request),
@ -77,6 +80,7 @@ impl ArgumentParser {
Some(("github", sub_matches)) => {
let name = sub_matches.get_one::<String>("name");
let version = sub_matches.get_one::<String>("version");
let contact = sub_matches.get_one::<String>("contact");
let name = match name {
Some(n) => n,
@ -88,9 +92,15 @@ impl ArgumentParser {
None => return Err(ArgumentParserError::VersionError),
};
let contact = match contact {
Some(c) => c,
None => return Err(ArgumentParserError::ContactError),
};
Ok(Action::RegisterCurrent {
version: version.to_string(),
name: name.to_string(),
contact: contact.to_string(),
vcsType: VcsType::Github,
})
}

View File

@ -77,11 +77,12 @@ impl<'a> Application<'a> {
});
};
let register_current = |name, version, vcs_type| {
let register_current = |name, version, vcs_type, contact| {
self.register_current_handler.execute(CurrentRequest {
name,
version,
vcs_type,
contact,
})
};

View File

@ -21,8 +21,12 @@ pub struct CurrentGateway<'a> {
impl<'a> RegisterCurrentHandler<'a> {
pub fn execute(&self, request: CurrentRequest) {
self.current_gateway
.upsert_current(request.name, request.version, request.vcs_type);
self.current_gateway.upsert_current(
request.name,
request.version,
request.vcs_type,
request.contact,
);
}
}
@ -31,7 +35,13 @@ impl<'a> CurrentGateway<'a> {
CurrentGateway { settings }
}
pub fn upsert_current(&self, name: String, version: String, vcs_type: VcsType) {
pub fn upsert_current(
&self,
name: String,
version: String,
vcs_type: VcsType,
contact: String,
) {
let connection = self.settings.database.get_connection();
// TODO: this should be wrapped somewhere else, because it is going to be used a lot of places. I think there must be some rustic way of doing this
@ -42,11 +52,13 @@ impl<'a> CurrentGateway<'a> {
let mut statement = connection
.prepare(
"INSERT INTO Currents (name, version, vcs_type) VALUES(?1,?2,?3) ON CONFLICT(name, vcs_type) DO UPDATE SET version = ?2",
"INSERT INTO Currents (name, version, vcs_type, contact) VALUES(?1,?2,?3,?4) ON CONFLICT(name, vcs_type) DO UPDATE SET version = ?2, contact = ?4",
)
.unwrap();
statement.execute([&name, &version, &vcs_type]).unwrap();
statement
.execute([&name, &version, &vcs_type, &contact])
.unwrap();
}
}
@ -57,6 +69,7 @@ pub mod models {
pub name: String,
pub version: String,
pub vcs_type: VcsType,
pub contact: String,
}
pub struct Current {

View File

@ -3,7 +3,7 @@ use crate::configuration::{Action, VcsType};
pub struct Router<A, F, L, R>
where
A: Fn(String, String, String, VcsType),
F: Fn(String, String, VcsType),
F: Fn(String, String, VcsType, String),
L: Fn(),
R: Fn(),
{
@ -16,7 +16,7 @@ where
impl<A, F, L, R> Router<A, F, L, R>
where
A: Fn(String, String, String, VcsType),
F: Fn(String, String, VcsType),
F: Fn(String, String, VcsType, String),
L: Fn(),
R: Fn(),
{
@ -42,7 +42,8 @@ where
name,
version,
vcsType,
} => (self.register_current)(name, version, vcsType),
contact,
} => (self.register_current)(name, version, vcsType, contact),
_ => {}
}
}
@ -65,7 +66,7 @@ mod tests {
assert_eq!(Github, vcs_type);
};
let current = |name, version, vcs_type| {};
let current = |name, version, vcs_type, contact| {};
let list = || {};
let request = || {};
@ -84,10 +85,11 @@ mod tests {
fn register_current_is_called_with_correct_parameters() {
let add = |name, owner_name, repo_name, vcs_type| {};
let current = |name, version, vcs_type| {
let current = |name, version, vcs_type, contact| {
assert_eq!("name", name);
assert_eq!("version", version);
assert_eq!(Github, vcs_type);
assert_eq!("contact", contact);
};
let list = || {};
@ -99,6 +101,7 @@ mod tests {
name: String::from("name"),
version: String::from("version"),
vcsType: Github,
contact: String::from("contact"),
});
}
@ -113,7 +116,7 @@ mod tests {
is_add_called.set(true);
};
let current = |name, version, vcs_type| is_current_called.set(true);
let current = |name, version, vcs_type, contact| is_current_called.set(true);
let list = || {
is_list_called.set(true);
@ -128,6 +131,7 @@ mod tests {
name: String::from("name"),
version: String::from("version"),
vcsType: Github,
contact: String::from("contact"),
});
assert!(!is_add_called.get());
@ -147,7 +151,7 @@ mod tests {
is_add_called.set(true);
};
let current = |name, version, vcs_type| is_current_called.set(true);
let current = |name, version, vcs_type, contact| is_current_called.set(true);
let list = || {
is_list_called.set(true);