1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
use super::OrgHandler;
use crate::models::code_scannings::{AiScanSetting, CodeScanningAlert, UpdateAiScan};
use crate::params::{self, Direction};
use crate::{Page, Result};
/// A client to GitHub's organization Code Scanning API.
///
/// Created with [`OrgHandler::code_scanning`].
pub struct OrgCodeScanningHandler<'octo, 'b> {
handler: &'b OrgHandler<'octo>,
}
impl<'octo, 'b> OrgCodeScanningHandler<'octo, 'b> {
pub(crate) fn new(handler: &'b OrgHandler<'octo>) -> Self {
Self { handler }
}
/// List code scanning alerts for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/code-scanning/code-scanning?apiVersion=2022-11-28#list-code-scanning-alerts-for-an-organization)
///
/// # Examples
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// let alerts = octocrab
/// .orgs("owner")
/// .code_scanning()
/// .list()
/// .per_page(10)
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn list(&self) -> ListOrgCodeScanningAlertsBuilder<'octo, 'b, '_> {
ListOrgCodeScanningAlertsBuilder::new(self)
}
/// Alias for [`Self::list`].
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/code-scanning/code-scanning?apiVersion=2022-11-28#list-code-scanning-alerts-for-an-organization)
///
/// # Examples
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// let alerts = octocrab
/// .orgs("owner")
/// .code_scanning()
/// .list_alerts()
/// .per_page(10)
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn list_alerts(&self) -> ListOrgCodeScanningAlertsBuilder<'octo, 'b, '_> {
self.list()
}
/// Get the AI Scan setting for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/code-scanning/code-scanning?apiVersion=2022-11-28#get-the-ai-scan-setting-for-an-organization)
///
/// # Examples
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// let ai_scan = octocrab.orgs("owner").code_scanning().get_ai_scan().await?;
/// # Ok(())
/// # }
/// ```
pub async fn get_ai_scan(&self) -> Result<AiScanSetting> {
let route = format!("/orgs/{}/code-scanning/ai-scan", self.handler.owner);
self.handler.crab.get(route, None::<&()>).await
}
/// Update the AI Scan setting for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/code-scanning/code-scanning?apiVersion=2022-11-28#update-the-ai-scan-setting-for-an-organization)
///
/// # Examples
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// use octocrab::models::code_scannings::UpdateAiScan;
///
/// let body = UpdateAiScan {
/// pr_scan: Some("enabled".to_string()),
/// };
/// let ai_scan = octocrab
/// .orgs("owner")
/// .code_scanning()
/// .update_ai_scan(&body)
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn update_ai_scan(&self, body: &UpdateAiScan) -> Result<AiScanSetting> {
let route = format!("/orgs/{}/code-scanning/ai-scan", self.handler.owner);
self.handler.crab.patch(route, Some(body)).await
}
}
/// Builder for listing organization code scanning alerts.
#[derive(serde::Serialize)]
pub struct ListOrgCodeScanningAlertsBuilder<'octo, 'b, 'c> {
#[serde(skip)]
handler: &'c OrgCodeScanningHandler<'octo, 'b>,
#[serde(skip_serializing_if = "Option::is_none")]
tool_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
tool_guid: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
before: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
after: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
page: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
per_page: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
direction: Option<Direction>,
#[serde(skip_serializing_if = "Option::is_none")]
state: Option<params::State>,
#[serde(skip_serializing_if = "Option::is_none")]
sort: Option<params::code_scannings::Sort>,
#[serde(skip_serializing_if = "Option::is_none")]
severity: Option<params::code_scannings::Severity>,
}
impl<'octo, 'b, 'c> ListOrgCodeScanningAlertsBuilder<'octo, 'b, 'c> {
pub(crate) fn new(handler: &'c OrgCodeScanningHandler<'octo, 'b>) -> Self {
Self {
handler,
tool_name: None,
tool_guid: None,
before: None,
after: None,
page: None,
per_page: None,
direction: None,
state: None,
sort: None,
severity: None,
}
}
/// Filter by the name of the tool used to generate the code scanning analysis.
pub fn tool_name(mut self, tool_name: impl Into<String>) -> Self {
self.tool_name = Some(tool_name.into());
self
}
/// Filter by the GUID of the tool used to generate the code scanning analysis.
pub fn tool_guid(mut self, tool_guid: impl Into<String>) -> Self {
self.tool_guid = Some(tool_guid.into());
self
}
/// Cursor for pagination (before).
pub fn before(mut self, before: impl Into<String>) -> Self {
self.before = Some(before.into());
self
}
/// Cursor for pagination (after).
pub fn after(mut self, after: impl Into<String>) -> Self {
self.after = Some(after.into());
self
}
/// Page number of the results to fetch.
pub fn page(mut self, page: impl Into<u32>) -> Self {
self.page = Some(page.into());
self
}
/// Results per page (max 100).
pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
self.per_page = Some(per_page.into());
self
}
/// The direction to sort the results by.
pub fn direction(mut self, direction: impl Into<Direction>) -> Self {
self.direction = Some(direction.into());
self
}
/// Filter by the state of the code scanning alert.
pub fn state(mut self, state: impl Into<params::State>) -> Self {
self.state = Some(state.into());
self
}
/// The property to sort the results by.
pub fn sort(mut self, sort: impl Into<params::code_scannings::Sort>) -> Self {
self.sort = Some(sort.into());
self
}
/// Filter by the severity of the code scanning alert.
pub fn severity(mut self, severity: impl Into<params::code_scannings::Severity>) -> Self {
self.severity = Some(severity.into());
self
}
/// Sends the request to list code scanning alerts.
pub async fn send(self) -> Result<Page<CodeScanningAlert>> {
let route = format!("/orgs/{}/code-scanning/alerts", self.handler.handler.owner);
self.handler.handler.crab.get(route, Some(&self)).await
}
}