job: move blacklist processing to request

This commit is contained in:
Antoine Martin 2021-03-30 22:00:59 +02:00
parent 8e7e0e9a84
commit ff90b5fb2d
3 changed files with 16 additions and 9 deletions

View file

@ -190,13 +190,6 @@ impl Job {
}
pub(crate) fn run(&mut self, homedir: &Path, config: &GlobalSettings) -> anyhow::Result<()> {
if config
.blacklist
.iter()
.any(|re| re.is_match(&self.repo.full_name))
{
return Ok(());
}
let local_path = homedir.join(&self.repo.full_name);
assert!(local_path.is_absolute());
self.local_path = Some(local_path);

View file

@ -29,7 +29,19 @@ struct JobSender(Mutex<Sender<Job>>);
struct Secret(String);
#[post("/", data = "<payload>")]
fn gitea_webhook(payload: SignedJson<GiteaWebHook>, sender: State<JobSender>) -> Status {
fn gitea_webhook(
payload: SignedJson<GiteaWebHook>,
sender: State<JobSender>,
config: State<GlobalSettings>,
) -> Status {
if config
.blacklist
.iter()
.any(|re| re.is_match(&payload.repository.full_name))
{
return Status::Ok;
}
{
let sender = sender.0.lock().unwrap();
let repo = &payload.repository;
@ -74,6 +86,7 @@ fn main() -> anyhow::Result<()> {
.expect("please provide a secret, otherwise anyone can send you a malicious webhook");
let config = parse_config(homedir.clone())?;
let config_state = config.clone();
thread::spawn(move || {
repo_updater(receiver, homedir, config);
@ -83,6 +96,7 @@ fn main() -> anyhow::Result<()> {
.mount("/", routes![gitea_webhook])
.manage(JobSender(Mutex::new(sender)))
.manage(Secret(secret))
.manage(config_state)
.launch();
Ok(())

View file

@ -2,7 +2,7 @@ use serde::Deserialize;
pub(crate) type RepoUrl = String; // FIXME: probably needs a better type than this
#[derive(Default, Deserialize)]
#[derive(Clone, Default, Deserialize)]
pub(crate) struct GlobalSettings {
/// List of remote stems to use when no `.lohr` file is found
#[serde(default)]