Skip to main content

interprex_test/
jobs.rs

1use async_trait::async_trait;
2use interprex::{DispatchInputs, JobsProvider, Repository, Result, RunId, WorkflowRun};
3
4use crate::state::{FakeProvider, missing};
5
6#[async_trait]
7impl JobsProvider for FakeProvider {
8    async fn dispatch(
9        &self,
10        repository: &Repository,
11        workflow: &str,
12        git_ref: &str,
13        inputs: &DispatchInputs,
14    ) -> Result<()> {
15        self.state.write().await.dispatches.push((
16            repository.clone(),
17            workflow.to_owned(),
18            git_ref.to_owned(),
19            inputs.clone(),
20        ));
21        Ok(())
22    }
23
24    async fn run(&self, repository: &Repository, run_id: RunId) -> Result<WorkflowRun> {
25        self.state
26            .read()
27            .await
28            .runs
29            .get(&(repository.clone(), run_id))
30            .cloned()
31            .ok_or_else(|| missing(format!("workflow run {run_id:?} in {repository}")))
32    }
33
34    async fn cancel_run(&self, repository: &Repository, run_id: RunId) -> Result<()> {
35        self.state
36            .write()
37            .await
38            .cancelled_runs
39            .push((repository.clone(), run_id));
40        Ok(())
41    }
42}