gitea_sdk/api/search/repos.rs
1use build_it::Builder;
2use serde::{Deserialize, Serialize};
3
4use crate::error::Result;
5use crate::model::repos::Repository;
6
7/// Options for searching repositories.
8/// All fields are optional.
9#[derive(Default, Debug, Clone, Serialize, Builder)]
10#[build_it(into)]
11pub struct SearchRepositoriesBuilder {
12 /// Keyword to search for
13 #[serde(rename = "q")]
14 pub query: Option<String>,
15 /// Limit search to repositories with keyword as topic
16 pub topic: Option<bool>,
17 /// Include search of keyword within repository description
18 #[serde(rename = "includeDesc")]
19 pub include_desc: Option<bool>,
20 /// Search only for repos that the user with the given id owns or contributes to
21 pub uid: Option<i64>,
22 /// Repo owner to prioritize in the results
23 pub priority_owner_id: Option<i64>,
24 /// Search only for repos that belong to the given team id
25 pub team_id: Option<i64>,
26 /// Search only for repos that the user with the given id has starred
27 #[serde(rename = "starredBy")]
28 pub starred_by: Option<i64>,
29 /// Include private repositories this user has access to (defaults to true)
30 pub private: Option<bool>,
31 /// Show only pubic, private or all repositories (defaults to all)
32 pub is_private: Option<bool>,
33 /// Include template repositories this user has access to (defaults to true)
34 pub template: Option<bool>,
35 /// Show only archived, non-archived or all repositories (defaults to all)
36 pub archived: Option<bool>,
37 /// Type of repository to search for. Supported values are "fork", "source", "mirror" and "collaborative"
38 pub mode: Option<String>,
39 /// If uid is given, search only for repos that the user owns
40 pub exclusive: Option<bool>,
41 /// Sort repos by attribute. Supported values are "alpha", "created", "updated", "size", and "id". Default is "alpha"
42 pub sort: Option<String>,
43 /// Sort order, either "asc" (ascending) or "desc" (descending). Default is "asc", ignored if "sort" is not specified.
44 pub order: Option<String>,
45 /// Page number of results to return (1-based)
46 pub page: Option<i32>,
47 /// Page size of results
48 pub limit: Option<i32>,
49}
50
51impl SearchRepositoriesBuilder {
52 pub fn new() -> Self {
53 Self::default()
54 }
55 pub async fn send(&self, client: &crate::Client) -> Result<Vec<Repository>> {
56 let req = client.get("repos/search".to_string()).query(self).build()?;
57 #[derive(Deserialize)]
58 struct Response {
59 #[allow(dead_code)]
60 ok: bool,
61 data: Vec<Repository>,
62 }
63 let res = client.make_request(req).await?;
64 Ok(client.parse_response::<Response>(res).await?.data)
65 }
66}