Skip to main content

subspace_client_github/actions/
pinned.rs

1//! Read-only Actions requests using the credential verified by PinnedWork.
2
3use serde::de::DeserializeOwned;
4use subspace_core::http::Error;
5
6use super::request::{self, PageRequest};
7use super::{Deployment, Job, Page, Release, WorkflowRun};
8use crate::PinnedWork;
9
10const RUN_PAGES: usize = 3;
11
12// qual:allow(coupling, oi) reason: "These are the Actions REST endpoints for a credential already verified by the client."
13impl PinnedWork<'_> {
14    // qual:api - The Actions Space's read tool uses these pinned reads.
15    pub fn recent_action_runs(&self, repo: &str) -> Result<Page<WorkflowRun>, Error> {
16        self.actions_page(PageRequest {
17            repo,
18            endpoint: "actions/runs",
19            key: "workflow_runs",
20            query: &[],
21            max_pages: RUN_PAGES,
22        })
23    }
24
25    // qual:api
26    pub fn action_run(&self, repo: &str, run_id: u64) -> Result<WorkflowRun, Error> {
27        let url = request::action_url(self.client, repo, &format!("actions/runs/{run_id}"), &[])?;
28        self.rest_json(&url)
29    }
30
31    // qual:api
32    pub fn action_jobs(&self, repo: &str, run_id: u64) -> Result<Page<Job>, Error> {
33        let (endpoint, query) = request::jobs_endpoint(run_id, 0);
34        self.actions_page(PageRequest {
35            repo,
36            endpoint: &endpoint,
37            key: "jobs",
38            query,
39            max_pages: RUN_PAGES,
40        })
41    }
42
43    // qual:api
44    pub fn action_deployments(&self, repo: &str) -> Result<Page<Deployment>, Error> {
45        self.actions_page(PageRequest {
46            repo,
47            endpoint: "deployments",
48            key: "",
49            query: &[],
50            max_pages: 1,
51        })
52    }
53
54    // qual:api
55    pub fn action_releases(&self, repo: &str) -> Result<Page<Release>, Error> {
56        self.actions_page(PageRequest {
57            repo,
58            endpoint: "releases",
59            key: "",
60            query: &[],
61            max_pages: 1,
62        })
63    }
64
65    fn actions_page<T: DeserializeOwned>(
66        &self,
67        request: PageRequest<'_>,
68    ) -> Result<Page<T>, Error> {
69        request::page_with(self.client, &request, |url| self.get(url, None))
70    }
71}