openapi_github/apis/
dependency_graph_api.rs

1/*
2 * GitHub's official OpenAPI spec + Octokit extension
3 *
4 * OpenAPI specs from https://github.com/github/rest-api-description with the 'x-octokit' extension required by the Octokit SDKs
5 *
6 * The version of the OpenAPI document: 16.6.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`dependency_graph_slash_create_repository_snapshot`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DependencyGraphSlashCreateRepositorySnapshotError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`dependency_graph_slash_diff_range`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DependencyGraphSlashDiffRangeError {
29    Status403(models::BasicError),
30    Status404(models::BasicError),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`dependency_graph_slash_export_sbom`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum DependencyGraphSlashExportSbomError {
38    Status403(models::BasicError),
39    Status404(models::BasicError),
40    UnknownValue(serde_json::Value),
41}
42
43
44/// Create a new snapshot of a repository's dependencies.  The authenticated user must have access to the repository.  OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint.
45pub async fn dependency_graph_slash_create_repository_snapshot(configuration: &configuration::Configuration, owner: &str, repo: &str, snapshot: models::Snapshot) -> Result<models::DependencyGraphCreateRepositorySnapshot201Response, Error<DependencyGraphSlashCreateRepositorySnapshotError>> {
46    let local_var_configuration = configuration;
47
48    let local_var_client = &local_var_configuration.client;
49
50    let local_var_uri_str = format!("{}/repos/{owner}/{repo}/dependency-graph/snapshots", local_var_configuration.base_path, owner=crate::apis::urlencode(owner), repo=crate::apis::urlencode(repo));
51    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
52
53    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
54        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
55    }
56    local_var_req_builder = local_var_req_builder.json(&snapshot);
57
58    let local_var_req = local_var_req_builder.build()?;
59    let local_var_resp = local_var_client.execute(local_var_req).await?;
60
61    let local_var_status = local_var_resp.status();
62    let local_var_content = local_var_resp.text().await?;
63
64    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
65        serde_json::from_str(&local_var_content).map_err(Error::from)
66    } else {
67        let local_var_entity: Option<DependencyGraphSlashCreateRepositorySnapshotError> = serde_json::from_str(&local_var_content).ok();
68        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
69        Err(Error::ResponseError(local_var_error))
70    }
71}
72
73/// Gets the diff of the dependency changes between two commits of a repository, based on the changes to the dependency manifests made in those commits.
74pub async fn dependency_graph_slash_diff_range(configuration: &configuration::Configuration, owner: &str, repo: &str, basehead: &str, name: Option<&str>) -> Result<Vec<models::DependencyGraphDiffInner>, Error<DependencyGraphSlashDiffRangeError>> {
75    let local_var_configuration = configuration;
76
77    let local_var_client = &local_var_configuration.client;
78
79    let local_var_uri_str = format!("{}/repos/{owner}/{repo}/dependency-graph/compare/{basehead}", local_var_configuration.base_path, owner=crate::apis::urlencode(owner), repo=crate::apis::urlencode(repo), basehead=crate::apis::urlencode(basehead));
80    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
81
82    if let Some(ref local_var_str) = name {
83        local_var_req_builder = local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
84    }
85    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
86        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
87    }
88
89    let local_var_req = local_var_req_builder.build()?;
90    let local_var_resp = local_var_client.execute(local_var_req).await?;
91
92    let local_var_status = local_var_resp.status();
93    let local_var_content = local_var_resp.text().await?;
94
95    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
96        serde_json::from_str(&local_var_content).map_err(Error::from)
97    } else {
98        let local_var_entity: Option<DependencyGraphSlashDiffRangeError> = serde_json::from_str(&local_var_content).ok();
99        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
100        Err(Error::ResponseError(local_var_error))
101    }
102}
103
104/// Exports the software bill of materials (SBOM) for a repository in SPDX JSON format.
105pub async fn dependency_graph_slash_export_sbom(configuration: &configuration::Configuration, owner: &str, repo: &str) -> Result<models::DependencyGraphSpdxSbom, Error<DependencyGraphSlashExportSbomError>> {
106    let local_var_configuration = configuration;
107
108    let local_var_client = &local_var_configuration.client;
109
110    let local_var_uri_str = format!("{}/repos/{owner}/{repo}/dependency-graph/sbom", local_var_configuration.base_path, owner=crate::apis::urlencode(owner), repo=crate::apis::urlencode(repo));
111    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
112
113    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
114        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
115    }
116
117    let local_var_req = local_var_req_builder.build()?;
118    let local_var_resp = local_var_client.execute(local_var_req).await?;
119
120    let local_var_status = local_var_resp.status();
121    let local_var_content = local_var_resp.text().await?;
122
123    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
124        serde_json::from_str(&local_var_content).map_err(Error::from)
125    } else {
126        let local_var_entity: Option<DependencyGraphSlashExportSbomError> = serde_json::from_str(&local_var_content).ok();
127        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
128        Err(Error::ResponseError(local_var_error))
129    }
130}
131