openapi_github/apis/
search_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 [`search_slash_code`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum SearchSlashCodeError {
22    Status403(models::BasicError),
23    Status422(models::ValidationError),
24    Status503(models::SecretScanningListAlertsForEnterprise503Response),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`search_slash_commits`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum SearchSlashCommitsError {
32    UnknownValue(serde_json::Value),
33}
34
35/// struct for typed errors of method [`search_slash_issues_and_pull_requests`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum SearchSlashIssuesAndPullRequestsError {
39    Status403(models::BasicError),
40    Status422(models::ValidationError),
41    Status503(models::SecretScanningListAlertsForEnterprise503Response),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`search_slash_labels`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum SearchSlashLabelsError {
49    Status403(models::BasicError),
50    Status404(models::BasicError),
51    Status422(models::ValidationError),
52    UnknownValue(serde_json::Value),
53}
54
55/// struct for typed errors of method [`search_slash_repos`]
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum SearchSlashReposError {
59    Status422(models::ValidationError),
60    Status503(models::SecretScanningListAlertsForEnterprise503Response),
61    UnknownValue(serde_json::Value),
62}
63
64/// struct for typed errors of method [`search_slash_topics`]
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum SearchSlashTopicsError {
68    UnknownValue(serde_json::Value),
69}
70
71/// struct for typed errors of method [`search_slash_users`]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum SearchSlashUsersError {
75    Status422(models::ValidationError),
76    Status503(models::SecretScanningListAlertsForEnterprise503Response),
77    UnknownValue(serde_json::Value),
78}
79
80
81/// Searches for query terms inside of a file. This method returns up to 100 results [per page](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api).  When searching for code, you can get text match metadata for the file **content** and file **path** fields when you pass the `text-match` media type. For more details about how to receive highlighted search results, see [Text match metadata](https://docs.github.com/rest/search/search#text-match-metadata).  For example, if you want to find the definition of the `addClass` function inside [jQuery](https://github.com/jquery/jquery) repository, your query would look something like this:  `q=addClass+in:file+language:js+repo:jquery/jquery`  This query searches for the keyword `addClass` within a file's contents. The query limits the search to files where the language is JavaScript in the `jquery/jquery` repository.  Considerations for code search:  Due to the complexity of searching code, there are a few restrictions on how searches are performed:  *   Only the _default branch_ is considered. In most cases, this will be the `master` branch. *   Only files smaller than 384 KB are searchable. *   You must always include at least one search term when searching source code. For example, searching for [`language:go`](https://github.com/search?utf8=%E2%9C%93&q=language%3Ago&type=Code) is not valid, while [`amazing language:go`](https://github.com/search?utf8=%E2%9C%93&q=amazing+language%3Ago&type=Code) is.  This endpoint requires you to authenticate and limits you to 10 requests per minute.
82pub async fn search_slash_code(configuration: &configuration::Configuration, q: &str, sort: Option<&str>, order: Option<&str>, per_page: Option<i32>, page: Option<i32>) -> Result<models::SearchCode200Response, Error<SearchSlashCodeError>> {
83    let local_var_configuration = configuration;
84
85    let local_var_client = &local_var_configuration.client;
86
87    let local_var_uri_str = format!("{}/search/code", local_var_configuration.base_path);
88    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
89
90    local_var_req_builder = local_var_req_builder.query(&[("q", &q.to_string())]);
91    if let Some(ref local_var_str) = sort {
92        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
93    }
94    if let Some(ref local_var_str) = order {
95        local_var_req_builder = local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
96    }
97    if let Some(ref local_var_str) = per_page {
98        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
99    }
100    if let Some(ref local_var_str) = page {
101        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
102    }
103    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
104        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
105    }
106
107    let local_var_req = local_var_req_builder.build()?;
108    let local_var_resp = local_var_client.execute(local_var_req).await?;
109
110    let local_var_status = local_var_resp.status();
111    let local_var_content = local_var_resp.text().await?;
112
113    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
114        serde_json::from_str(&local_var_content).map_err(Error::from)
115    } else {
116        let local_var_entity: Option<SearchSlashCodeError> = serde_json::from_str(&local_var_content).ok();
117        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
118        Err(Error::ResponseError(local_var_error))
119    }
120}
121
122/// Find commits via various criteria on the default branch (usually `main`). This method returns up to 100 results [per page](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api).  When searching for commits, you can get text match metadata for the **message** field when you provide the `text-match` media type. For more details about how to receive highlighted search results, see [Text match metadata](https://docs.github.com/rest/search/search#text-match-metadata).  For example, if you want to find commits related to CSS in the [octocat/Spoon-Knife](https://github.com/octocat/Spoon-Knife) repository. Your query would look something like this:  `q=repo:octocat/Spoon-Knife+css`
123pub async fn search_slash_commits(configuration: &configuration::Configuration, q: &str, sort: Option<&str>, order: Option<&str>, per_page: Option<i32>, page: Option<i32>) -> Result<models::SearchCommits200Response, Error<SearchSlashCommitsError>> {
124    let local_var_configuration = configuration;
125
126    let local_var_client = &local_var_configuration.client;
127
128    let local_var_uri_str = format!("{}/search/commits", local_var_configuration.base_path);
129    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
130
131    local_var_req_builder = local_var_req_builder.query(&[("q", &q.to_string())]);
132    if let Some(ref local_var_str) = sort {
133        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
134    }
135    if let Some(ref local_var_str) = order {
136        local_var_req_builder = local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
137    }
138    if let Some(ref local_var_str) = per_page {
139        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
140    }
141    if let Some(ref local_var_str) = page {
142        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
143    }
144    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
145        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
146    }
147
148    let local_var_req = local_var_req_builder.build()?;
149    let local_var_resp = local_var_client.execute(local_var_req).await?;
150
151    let local_var_status = local_var_resp.status();
152    let local_var_content = local_var_resp.text().await?;
153
154    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
155        serde_json::from_str(&local_var_content).map_err(Error::from)
156    } else {
157        let local_var_entity: Option<SearchSlashCommitsError> = serde_json::from_str(&local_var_content).ok();
158        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
159        Err(Error::ResponseError(local_var_error))
160    }
161}
162
163/// Find issues by state and keyword. This method returns up to 100 results [per page](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api).  When searching for issues, you can get text match metadata for the issue **title**, issue **body**, and issue **comment body** fields when you pass the `text-match` media type. For more details about how to receive highlighted search results, see [Text match metadata](https://docs.github.com/rest/search/search#text-match-metadata).  For example, if you want to find the oldest unresolved Python bugs on Windows. Your query might look something like this.  `q=windows+label:bug+language:python+state:open&sort=created&order=asc`  This query searches for the keyword `windows`, within any open issue that is labeled as `bug`. The search runs across repositories whose primary language is Python. The results are sorted by creation date in ascending order, which means the oldest issues appear first in the search results.  **Note:** For requests made by GitHub Apps with a user access token, you can't retrieve a combination of issues and pull requests in a single query. Requests that don't include the `is:issue` or `is:pull-request` qualifier will receive an HTTP `422 Unprocessable Entity` response. To get results for both issues and pull requests, you must send separate queries for issues and pull requests. For more information about the `is` qualifier, see \"[Searching only issues or pull requests](https://docs.github.com/github/searching-for-information-on-github/searching-issues-and-pull-requests#search-only-issues-or-pull-requests).\"
164pub async fn search_slash_issues_and_pull_requests(configuration: &configuration::Configuration, q: &str, sort: Option<&str>, order: Option<&str>, per_page: Option<i32>, page: Option<i32>) -> Result<models::SearchIssuesAndPullRequests200Response, Error<SearchSlashIssuesAndPullRequestsError>> {
165    let local_var_configuration = configuration;
166
167    let local_var_client = &local_var_configuration.client;
168
169    let local_var_uri_str = format!("{}/search/issues", local_var_configuration.base_path);
170    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
171
172    local_var_req_builder = local_var_req_builder.query(&[("q", &q.to_string())]);
173    if let Some(ref local_var_str) = sort {
174        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
175    }
176    if let Some(ref local_var_str) = order {
177        local_var_req_builder = local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
178    }
179    if let Some(ref local_var_str) = per_page {
180        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
181    }
182    if let Some(ref local_var_str) = page {
183        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
184    }
185    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
186        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
187    }
188
189    let local_var_req = local_var_req_builder.build()?;
190    let local_var_resp = local_var_client.execute(local_var_req).await?;
191
192    let local_var_status = local_var_resp.status();
193    let local_var_content = local_var_resp.text().await?;
194
195    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
196        serde_json::from_str(&local_var_content).map_err(Error::from)
197    } else {
198        let local_var_entity: Option<SearchSlashIssuesAndPullRequestsError> = serde_json::from_str(&local_var_content).ok();
199        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
200        Err(Error::ResponseError(local_var_error))
201    }
202}
203
204/// Find labels in a repository with names or descriptions that match search keywords. Returns up to 100 results [per page](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api).  When searching for labels, you can get text match metadata for the label **name** and **description** fields when you pass the `text-match` media type. For more details about how to receive highlighted search results, see [Text match metadata](https://docs.github.com/rest/search/search#text-match-metadata).  For example, if you want to find labels in the `linguist` repository that match `bug`, `defect`, or `enhancement`. Your query might look like this:  `q=bug+defect+enhancement&repository_id=64778136`  The labels that best match the query appear first in the search results.
205pub async fn search_slash_labels(configuration: &configuration::Configuration, repository_id: i32, q: &str, sort: Option<&str>, order: Option<&str>, per_page: Option<i32>, page: Option<i32>) -> Result<models::SearchLabels200Response, Error<SearchSlashLabelsError>> {
206    let local_var_configuration = configuration;
207
208    let local_var_client = &local_var_configuration.client;
209
210    let local_var_uri_str = format!("{}/search/labels", local_var_configuration.base_path);
211    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
212
213    local_var_req_builder = local_var_req_builder.query(&[("repository_id", &repository_id.to_string())]);
214    local_var_req_builder = local_var_req_builder.query(&[("q", &q.to_string())]);
215    if let Some(ref local_var_str) = sort {
216        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
217    }
218    if let Some(ref local_var_str) = order {
219        local_var_req_builder = local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
220    }
221    if let Some(ref local_var_str) = per_page {
222        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
223    }
224    if let Some(ref local_var_str) = page {
225        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
226    }
227    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
228        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
229    }
230
231    let local_var_req = local_var_req_builder.build()?;
232    let local_var_resp = local_var_client.execute(local_var_req).await?;
233
234    let local_var_status = local_var_resp.status();
235    let local_var_content = local_var_resp.text().await?;
236
237    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
238        serde_json::from_str(&local_var_content).map_err(Error::from)
239    } else {
240        let local_var_entity: Option<SearchSlashLabelsError> = serde_json::from_str(&local_var_content).ok();
241        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
242        Err(Error::ResponseError(local_var_error))
243    }
244}
245
246/// Find repositories via various criteria. This method returns up to 100 results [per page](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api).  When searching for repositories, you can get text match metadata for the **name** and **description** fields when you pass the `text-match` media type. For more details about how to receive highlighted search results, see [Text match metadata](https://docs.github.com/rest/search/search#text-match-metadata).  For example, if you want to search for popular Tetris repositories written in assembly code, your query might look like this:  `q=tetris+language:assembly&sort=stars&order=desc`  This query searches for repositories with the word `tetris` in the name, the description, or the README. The results are limited to repositories where the primary language is assembly. The results are sorted by stars in descending order, so that the most popular repositories appear first in the search results.
247pub async fn search_slash_repos(configuration: &configuration::Configuration, q: &str, sort: Option<&str>, order: Option<&str>, per_page: Option<i32>, page: Option<i32>) -> Result<models::SearchRepos200Response, Error<SearchSlashReposError>> {
248    let local_var_configuration = configuration;
249
250    let local_var_client = &local_var_configuration.client;
251
252    let local_var_uri_str = format!("{}/search/repositories", local_var_configuration.base_path);
253    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
254
255    local_var_req_builder = local_var_req_builder.query(&[("q", &q.to_string())]);
256    if let Some(ref local_var_str) = sort {
257        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
258    }
259    if let Some(ref local_var_str) = order {
260        local_var_req_builder = local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
261    }
262    if let Some(ref local_var_str) = per_page {
263        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
264    }
265    if let Some(ref local_var_str) = page {
266        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
267    }
268    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
269        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
270    }
271
272    let local_var_req = local_var_req_builder.build()?;
273    let local_var_resp = local_var_client.execute(local_var_req).await?;
274
275    let local_var_status = local_var_resp.status();
276    let local_var_content = local_var_resp.text().await?;
277
278    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
279        serde_json::from_str(&local_var_content).map_err(Error::from)
280    } else {
281        let local_var_entity: Option<SearchSlashReposError> = serde_json::from_str(&local_var_content).ok();
282        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
283        Err(Error::ResponseError(local_var_error))
284    }
285}
286
287/// Find topics via various criteria. Results are sorted by best match. This method returns up to 100 results [per page](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api). See \"[Searching topics](https://docs.github.com/articles/searching-topics/)\" for a detailed list of qualifiers.  When searching for topics, you can get text match metadata for the topic's **short\\_description**, **description**, **name**, or **display\\_name** field when you pass the `text-match` media type. For more details about how to receive highlighted search results, see [Text match metadata](https://docs.github.com/rest/search/search#text-match-metadata).  For example, if you want to search for topics related to Ruby that are featured on https://github.com/topics. Your query might look like this:  `q=ruby+is:featured`  This query searches for topics with the keyword `ruby` and limits the results to find only topics that are featured. The topics that are the best match for the query appear first in the search results.
288pub async fn search_slash_topics(configuration: &configuration::Configuration, q: &str, per_page: Option<i32>, page: Option<i32>) -> Result<models::SearchTopics200Response, Error<SearchSlashTopicsError>> {
289    let local_var_configuration = configuration;
290
291    let local_var_client = &local_var_configuration.client;
292
293    let local_var_uri_str = format!("{}/search/topics", local_var_configuration.base_path);
294    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
295
296    local_var_req_builder = local_var_req_builder.query(&[("q", &q.to_string())]);
297    if let Some(ref local_var_str) = per_page {
298        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
299    }
300    if let Some(ref local_var_str) = page {
301        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
302    }
303    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
304        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
305    }
306
307    let local_var_req = local_var_req_builder.build()?;
308    let local_var_resp = local_var_client.execute(local_var_req).await?;
309
310    let local_var_status = local_var_resp.status();
311    let local_var_content = local_var_resp.text().await?;
312
313    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
314        serde_json::from_str(&local_var_content).map_err(Error::from)
315    } else {
316        let local_var_entity: Option<SearchSlashTopicsError> = serde_json::from_str(&local_var_content).ok();
317        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
318        Err(Error::ResponseError(local_var_error))
319    }
320}
321
322/// Find users via various criteria. This method returns up to 100 results [per page](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api).  When searching for users, you can get text match metadata for the issue **login**, public **email**, and **name** fields when you pass the `text-match` media type. For more details about highlighting search results, see [Text match metadata](https://docs.github.com/rest/search/search#text-match-metadata). For more details about how to receive highlighted search results, see [Text match metadata](https://docs.github.com/rest/search/search#text-match-metadata).  For example, if you're looking for a list of popular users, you might try this query:  `q=tom+repos:%3E42+followers:%3E1000`  This query searches for users with the name `tom`. The results are restricted to users with more than 42 repositories and over 1,000 followers.  This endpoint does not accept authentication and will only include publicly visible users. As an alternative, you can use the GraphQL API. The GraphQL API requires authentication and will return private users, including Enterprise Managed Users (EMUs), that you are authorized to view. For more information, see \"[GraphQL Queries](https://docs.github.com/graphql/reference/queries#search).\"
323pub async fn search_slash_users(configuration: &configuration::Configuration, q: &str, sort: Option<&str>, order: Option<&str>, per_page: Option<i32>, page: Option<i32>) -> Result<models::SearchUsers200Response, Error<SearchSlashUsersError>> {
324    let local_var_configuration = configuration;
325
326    let local_var_client = &local_var_configuration.client;
327
328    let local_var_uri_str = format!("{}/search/users", local_var_configuration.base_path);
329    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
330
331    local_var_req_builder = local_var_req_builder.query(&[("q", &q.to_string())]);
332    if let Some(ref local_var_str) = sort {
333        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
334    }
335    if let Some(ref local_var_str) = order {
336        local_var_req_builder = local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
337    }
338    if let Some(ref local_var_str) = per_page {
339        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
340    }
341    if let Some(ref local_var_str) = page {
342        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
343    }
344    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
345        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
346    }
347
348    let local_var_req = local_var_req_builder.build()?;
349    let local_var_resp = local_var_client.execute(local_var_req).await?;
350
351    let local_var_status = local_var_resp.status();
352    let local_var_content = local_var_resp.text().await?;
353
354    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
355        serde_json::from_str(&local_var_content).map_err(Error::from)
356    } else {
357        let local_var_entity: Option<SearchSlashUsersError> = serde_json::from_str(&local_var_content).ok();
358        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
359        Err(Error::ResponseError(local_var_error))
360    }
361}
362