subspace-client-github 0.11.0

Subspace Framework GitHub client: REST and GraphQL types and requests. Internal crate; apps depend on `subspace-framework`.
Documentation
//! Read-only Actions requests using the credential verified by PinnedWork.

use serde::de::DeserializeOwned;
use subspace_core::http::Error;

use super::request::{self, PageRequest};
use super::{Deployment, Job, Page, Release, WorkflowRun};
use crate::PinnedWork;

const RUN_PAGES: usize = 3;

// qual:allow(coupling, oi) reason: "These are the Actions REST endpoints for a credential already verified by the client."
impl PinnedWork<'_> {
    // qual:api - The Actions Space's read tool uses these pinned reads.
    pub fn recent_action_runs(&self, repo: &str) -> Result<Page<WorkflowRun>, Error> {
        self.actions_page(PageRequest {
            repo,
            endpoint: "actions/runs",
            key: "workflow_runs",
            query: &[],
            max_pages: RUN_PAGES,
        })
    }

    // qual:api
    pub fn action_run(&self, repo: &str, run_id: u64) -> Result<WorkflowRun, Error> {
        let url = request::action_url(self.client, repo, &format!("actions/runs/{run_id}"), &[])?;
        self.rest_json(&url)
    }

    // qual:api
    pub fn action_jobs(&self, repo: &str, run_id: u64) -> Result<Page<Job>, Error> {
        let (endpoint, query) = request::jobs_endpoint(run_id, 0);
        self.actions_page(PageRequest {
            repo,
            endpoint: &endpoint,
            key: "jobs",
            query,
            max_pages: RUN_PAGES,
        })
    }

    // qual:api
    pub fn action_deployments(&self, repo: &str) -> Result<Page<Deployment>, Error> {
        self.actions_page(PageRequest {
            repo,
            endpoint: "deployments",
            key: "",
            query: &[],
            max_pages: 1,
        })
    }

    // qual:api
    pub fn action_releases(&self, repo: &str) -> Result<Page<Release>, Error> {
        self.actions_page(PageRequest {
            repo,
            endpoint: "releases",
            key: "",
            query: &[],
            max_pages: 1,
        })
    }

    fn actions_page<T: DeserializeOwned>(
        &self,
        request: PageRequest<'_>,
    ) -> Result<Page<T>, Error> {
        request::page_with(self.client, &request, |url| self.get(url, None))
    }
}