jinxapi_github/v1_1_4/request/
code_scanning_get_analysis.rs

1//! Get a code scanning analysis for a repository
2//! 
3//! Gets a specified code scanning analysis for a repository.
4//! You must use an access token with the `security_events` scope to use this endpoint with private repos,
5//! the `public_repo` scope also grants permission to read security events on public repos only.
6//! GitHub Apps must have the `security_events` read permission to use this endpoint.
7//! 
8//! The default JSON response contains fields that describe the analysis.
9//! This includes the Git reference and commit SHA to which the analysis relates,
10//! the datetime of the analysis, the name of the code scanning tool,
11//! and the number of alerts.
12//! 
13//! The `rules_count` field in the default response give the number of rules
14//! that were run in the analysis.
15//! For very old analyses this data is not available,
16//! and `0` is returned in this field.
17//! 
18//! If you use the Accept header `application/sarif+json`,
19//! the response contains the analysis data that was uploaded.
20//! This is formatted as
21//! [SARIF version 2.1.0](https://docs.oasis-open.org/sarif/sarif/v2.1.0/cs01/sarif-v2.1.0-cs01.html).
22//! 
23//! [API method documentation](https://docs.github.com/rest/reference/code-scanning#get-a-code-scanning-analysis-for-a-repository)
24
25
26fn url_string(
27    base_url: &str,
28    p_owner: &str,
29    p_repo: &str,
30    p_analysis_id: i64,
31) -> Result<String, crate::v1_1_4::ApiError> {
32    let trimmed = if base_url.is_empty() {
33        "https://api.github.com"
34    } else {
35        base_url.trim_end_matches('/')
36    };
37    let mut url = String::with_capacity(trimmed.len() + 51);
38    url.push_str(trimmed);
39    url.push_str("/repos/");
40    ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
41    url.push('/');
42    ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
43    url.push_str("/code-scanning/analyses/");
44    ::querylizer::Simple::extend(&mut url, &p_analysis_id, false, &::querylizer::encode_path)?;
45    Ok(url)
46}
47
48#[cfg(feature = "hyper")]
49pub fn http_builder(
50    base_url: &str,
51    p_owner: &str,
52    p_repo: &str,
53    p_analysis_id: i64,
54    h_user_agent: &str,
55    h_accept: ::std::option::Option<&str>,
56) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
57    let url = url_string(
58        base_url,
59        p_owner,
60        p_repo,
61        p_analysis_id,
62    )?;
63    let mut builder = ::http::request::Request::get(url);
64    builder = builder.header(
65        "User-Agent",
66        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
67    );
68    if let Some(value) = &h_accept {
69        builder = builder.header(
70            "Accept",
71            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
72        );
73    }
74    Ok(builder)
75}
76
77#[cfg(feature = "hyper")]
78#[inline]
79pub fn hyper_request(
80    builder: ::http::request::Builder,
81) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError> {
82    Ok(builder.body(::hyper::Body::empty())?)
83}
84
85#[cfg(feature = "reqwest")]
86pub fn reqwest_builder(
87    base_url: &str,
88    p_owner: &str,
89    p_repo: &str,
90    p_analysis_id: i64,
91    h_user_agent: &str,
92    h_accept: ::std::option::Option<&str>,
93) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
94    let url = url_string(
95        base_url,
96        p_owner,
97        p_repo,
98        p_analysis_id,
99    )?;
100    let reqwest_url = ::reqwest::Url::parse(&url)?;
101    let mut request = ::reqwest::Request::new(::reqwest::Method::GET, reqwest_url);
102    let headers = request.headers_mut();
103    headers.append(
104        "User-Agent",
105        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
106    );
107    if let Some(value) = &h_accept {
108        headers.append(
109            "Accept",
110            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
111        );
112    }
113    Ok(request)
114}
115
116#[cfg(feature = "reqwest")]
117#[inline(always)]
118pub fn reqwest_request(
119    builder: ::reqwest::Request,
120) -> Result<::reqwest::Request, crate::v1_1_4::ApiError>
121{
122    Ok(builder)
123}
124
125#[cfg(feature = "reqwest-blocking")]
126pub fn reqwest_blocking_builder(
127    base_url: &str,
128    p_owner: &str,
129    p_repo: &str,
130    p_analysis_id: i64,
131    h_user_agent: &str,
132    h_accept: ::std::option::Option<&str>,
133) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
134    let url = url_string(
135        base_url,
136        p_owner,
137        p_repo,
138        p_analysis_id,
139    )?;
140    let reqwest_url = ::reqwest::Url::parse(&url)?;
141    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::GET, reqwest_url);
142    let headers = request.headers_mut();
143    headers.append(
144        "User-Agent",
145        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
146    );
147    if let Some(value) = &h_accept {
148        headers.append(
149            "Accept",
150            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
151        );
152    }
153    Ok(request)
154}
155
156#[cfg(feature = "reqwest-blocking")]
157#[inline(always)]
158pub fn reqwest_blocking_request(
159    builder: ::reqwest::blocking::Request,
160) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError>
161{
162    Ok(builder)
163}