jinxapi_github/v1_1_4/request/
code_scanning_delete_analysis.rs

1//! Delete a code scanning analysis from a repository
2//! 
3//! Deletes a specified code scanning analysis from a repository. For
4//! private repositories, you must use an access token with the `repo` scope. For public repositories,
5//! you must use an access token with `public_repo` scope.
6//! GitHub Apps must have the `security_events` write permission to use this endpoint.
7//! 
8//! You can delete one analysis at a time.
9//! To delete a series of analyses, start with the most recent analysis and work backwards.
10//! Conceptually, the process is similar to the undo function in a text editor.
11//! 
12//! When you list the analyses for a repository,
13//! one or more will be identified as deletable in the response:
14//! 
15//! ```text
16//! "deletable": true
17//! ```
18//! 
19//! An analysis is deletable when it's the most recent in a set of analyses.
20//! Typically, a repository will have multiple sets of analyses
21//! for each enabled code scanning tool,
22//! where a set is determined by a unique combination of analysis values:
23//! 
24//! * `ref`
25//! * `tool`
26//! * `analysis_key`
27//! * `environment`
28//! 
29//! If you attempt to delete an analysis that is not the most recent in a set,
30//! you'll get a 400 response with the message:
31//! 
32//! ```text
33//! Analysis specified is not deletable.
34//! ```
35//! 
36//! The response from a successful `DELETE` operation provides you with
37//! two alternative URLs for deleting the next analysis in the set:
38//! `next_analysis_url` and `confirm_delete_url`.
39//! Use the `next_analysis_url` URL if you want to avoid accidentally deleting the final analysis
40//! in a set. This is a useful option if you want to preserve at least one analysis
41//! for the specified tool in your repository.
42//! Use the `confirm_delete_url` URL if you are content to remove all analyses for a tool.
43//! When you delete the last analysis in a set, the value of `next_analysis_url` and `confirm_delete_url`
44//! in the 200 response is `null`.
45//! 
46//! As an example of the deletion process,
47//! let's imagine that you added a workflow that configured a particular code scanning tool
48//! to analyze the code in a repository. This tool has added 15 analyses:
49//! 10 on the default branch, and another 5 on a topic branch.
50//! You therefore have two separate sets of analyses for this tool.
51//! You've now decided that you want to remove all of the analyses for the tool.
52//! To do this you must make 15 separate deletion requests.
53//! To start, you must find an analysis that's identified as deletable.
54//! Each set of analyses always has one that's identified as deletable.
55//! Having found the deletable analysis for one of the two sets,
56//! delete this analysis and then continue deleting the next analysis in the set until they're all deleted.
57//! Then repeat the process for the second set.
58//! The procedure therefore consists of a nested loop:
59//! 
60//! **Outer loop**:
61//! * List the analyses for the repository, filtered by tool.
62//! * Parse this list to find a deletable analysis. If found:
63//! 
64//!   **Inner loop**:
65//!   * Delete the identified analysis.
66//!   * Parse the response for the value of `confirm_delete_url` and, if found, use this in the next iteration.
67//! 
68//! The above process assumes that you want to remove all trace of the tool's analyses from the GitHub user interface, for the specified repository, and it therefore uses the `confirm_delete_url` value. Alternatively, you could use the `next_analysis_url` value, which would leave the last analysis in each set undeleted to avoid removing a tool's analysis entirely.
69//! 
70//! [API method documentation](https://docs.github.com/rest/reference/code-scanning#delete-a-code-scanning-analysis-from-a-repository)
71
72
73fn url_string(
74    base_url: &str,
75    p_owner: &str,
76    p_repo: &str,
77    p_analysis_id: i64,
78    q_confirm_delete: ::std::option::Option<::std::option::Option<&str>>,
79) -> Result<String, crate::v1_1_4::ApiError> {
80    let trimmed = if base_url.is_empty() {
81        "https://api.github.com"
82    } else {
83        base_url.trim_end_matches('/')
84    };
85    let mut url = String::with_capacity(trimmed.len() + 51);
86    url.push_str(trimmed);
87    url.push_str("/repos/");
88    ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
89    url.push('/');
90    ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
91    url.push_str("/code-scanning/analyses/");
92    ::querylizer::Simple::extend(&mut url, &p_analysis_id, false, &::querylizer::encode_path)?;
93    if let Some(value) = &q_confirm_delete {
94        url.push('?');
95        ::querylizer::Form::extend(&mut url, "confirm_delete", value, false, &::querylizer::encode_query)?;
96    }
97    Ok(url)
98}
99
100#[cfg(feature = "hyper")]
101pub fn http_builder(
102    base_url: &str,
103    p_owner: &str,
104    p_repo: &str,
105    p_analysis_id: i64,
106    q_confirm_delete: ::std::option::Option<::std::option::Option<&str>>,
107    h_user_agent: &str,
108    h_accept: ::std::option::Option<&str>,
109) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
110    let url = url_string(
111        base_url,
112        p_owner,
113        p_repo,
114        p_analysis_id,
115        q_confirm_delete,
116    )?;
117    let mut builder = ::http::request::Request::delete(url);
118    builder = builder.header(
119        "User-Agent",
120        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
121    );
122    if let Some(value) = &h_accept {
123        builder = builder.header(
124            "Accept",
125            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
126        );
127    }
128    Ok(builder)
129}
130
131#[cfg(feature = "hyper")]
132#[inline]
133pub fn hyper_request(
134    builder: ::http::request::Builder,
135) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError> {
136    Ok(builder.body(::hyper::Body::empty())?)
137}
138
139#[cfg(feature = "reqwest")]
140pub fn reqwest_builder(
141    base_url: &str,
142    p_owner: &str,
143    p_repo: &str,
144    p_analysis_id: i64,
145    q_confirm_delete: ::std::option::Option<::std::option::Option<&str>>,
146    h_user_agent: &str,
147    h_accept: ::std::option::Option<&str>,
148) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
149    let url = url_string(
150        base_url,
151        p_owner,
152        p_repo,
153        p_analysis_id,
154        q_confirm_delete,
155    )?;
156    let reqwest_url = ::reqwest::Url::parse(&url)?;
157    let mut request = ::reqwest::Request::new(::reqwest::Method::DELETE, reqwest_url);
158    let headers = request.headers_mut();
159    headers.append(
160        "User-Agent",
161        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
162    );
163    if let Some(value) = &h_accept {
164        headers.append(
165            "Accept",
166            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
167        );
168    }
169    Ok(request)
170}
171
172#[cfg(feature = "reqwest")]
173#[inline(always)]
174pub fn reqwest_request(
175    builder: ::reqwest::Request,
176) -> Result<::reqwest::Request, crate::v1_1_4::ApiError>
177{
178    Ok(builder)
179}
180
181#[cfg(feature = "reqwest-blocking")]
182pub fn reqwest_blocking_builder(
183    base_url: &str,
184    p_owner: &str,
185    p_repo: &str,
186    p_analysis_id: i64,
187    q_confirm_delete: ::std::option::Option<::std::option::Option<&str>>,
188    h_user_agent: &str,
189    h_accept: ::std::option::Option<&str>,
190) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
191    let url = url_string(
192        base_url,
193        p_owner,
194        p_repo,
195        p_analysis_id,
196        q_confirm_delete,
197    )?;
198    let reqwest_url = ::reqwest::Url::parse(&url)?;
199    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::DELETE, reqwest_url);
200    let headers = request.headers_mut();
201    headers.append(
202        "User-Agent",
203        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
204    );
205    if let Some(value) = &h_accept {
206        headers.append(
207            "Accept",
208            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
209        );
210    }
211    Ok(request)
212}
213
214#[cfg(feature = "reqwest-blocking")]
215#[inline(always)]
216pub fn reqwest_blocking_request(
217    builder: ::reqwest::blocking::Request,
218) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError>
219{
220    Ok(builder)
221}