gitea_sdk/api/pulls/
mod.rs

1pub mod create;
2pub mod edit;
3pub mod get;
4pub mod list;
5pub mod pinned;
6pub mod reviews;
7
8pub struct Pulls {
9    pub(crate) owner: String,
10    pub(crate) repo: String,
11}
12
13impl Pulls {
14    /// Create a [Pull Request](crate::model::pulls::PullRequest) in a repository.
15    ///
16    /// # Example
17    /// ```
18    /// # use gitea_sdk::{Client, Auth};
19    /// # async fn create_pr() {
20    /// let client = Client::new(
21    ///     "https://gitea.example.com",
22    ///     Auth::Token("your-token")
23    /// );
24    /// let pr = client
25    ///     .pulls("owner", "repo")
26    ///     .create("my-branch", "main", "My PR")
27    ///     .body("This is my PR")
28    ///     .send(&client)
29    ///     .await
30    ///     .unwrap();
31    /// # }
32    /// ```
33    /// This will create a pull request with the title "My PR" and body "This is my PR" from the
34    /// branch "my-branch" to the branch "main" in the repository "owner/repo".
35    pub fn create(
36        &self,
37        head: impl ToString,
38        base: impl ToString,
39        title: impl ToString,
40    ) -> create::CreatePullRequestBuilder {
41        create::CreatePullRequestBuilder::new(&self.owner, &self.repo, head, base, title)
42    }
43
44    /// Edit a [Pull Request](crate::model::pulls::PullRequest) in a repository.
45    ///
46    /// # Example
47    /// ```
48    /// # use gitea_sdk::{Client, Auth};
49    /// # async fn edit_pr() {
50    /// let client = Client::new(
51    ///     "https://gitea.example.com",
52    ///     Auth::Token("your-token")
53    /// );
54    /// client
55    ///     .pulls("owner", "repo")
56    ///     .edit(1)
57    ///     .title("My PR")
58    ///     .body("This is my PR")
59    ///     .send(&client)
60    ///     .await
61    ///     .unwrap();
62    /// # }
63    /// ```
64    /// This will edit the pull request with the ID 1 in the repository "owner/repo" to have the
65    /// title "My PR" and body "This is my PR".
66    pub fn edit(&self, id: i64) -> edit::EditPullRequestBuilder {
67        edit::EditPullRequestBuilder::new(&self.owner, &self.repo, id)
68    }
69
70    /// Get a [Pull Request](crate::model::pulls::PullRequest) by its head and base branches.
71    ///
72    /// # Example
73    /// ```
74    /// # use gitea_sdk::{Client, Auth};
75    /// # async fn get_pr_by_branches() {
76    /// let client = Client::new(
77    ///     "https://gitea.example.com",
78    ///     Auth::Token("your-token")
79    /// );
80    /// let pr = client
81    ///     .pulls("owner", "repo")
82    ///     .get_by_branches("my-branch", "main")
83    ///     .send(&client)
84    ///     .await
85    ///     .unwrap();
86    /// # }
87    /// ```
88    /// This will get the pull request from the branch "my-branch" to the branch "main" in the
89    /// repository "owner/repo".
90    pub fn get_by_branches(
91        &self,
92        head: impl ToString,
93        base: impl ToString,
94    ) -> get::GetPullRequestByBranchesBuilder {
95        get::GetPullRequestByBranchesBuilder::new(&self.owner, &self.repo, head, base)
96    }
97
98    /// Get a [Pull Request](crate::model::pulls::PullRequest) by its ID.
99    ///
100    /// # Example
101    /// ```
102    /// # use gitea_sdk::{Client, Auth};
103    /// # async fn get_pr_by_id() {
104    /// let client = Client::new(
105    ///     "https://gitea.example.com",
106    ///     Auth::Token("your-token")
107    /// );
108    /// let pr = client
109    ///     .pulls("owner", "repo")
110    ///     .get(1)
111    ///     .send(&client)
112    ///     .await
113    ///     .unwrap();
114    /// # }
115    /// ```
116    /// This will get the pull request with the ID 1 in the repository "owner/repo".
117    pub fn get(&self, id: i64) -> get::GetPullRequestByIdBuilder {
118        get::GetPullRequestByIdBuilder::new(&self.owner, &self.repo, id)
119    }
120
121    /// List a repository's [Pull Requests](crate::model::pulls::PullRequest).
122    ///
123    /// # Example
124    ///
125    /// ```
126    /// # use gitea_sdk::{Client, Auth, model::issues::State};
127    /// # async fn list_prs() {
128    /// let client = Client::new(
129    ///     "https://gitea.example.com",
130    ///     Auth::Token("your-token")
131    /// );
132    /// let issues = client
133    ///   .pulls("owner", "repo")
134    ///   .list()
135    ///   .state(State::Open)
136    ///    .send(&client)
137    ///   .await
138    ///   .unwrap();
139    /// # }
140    /// ```
141    /// This will get all open issues in the repository "owner/repo".
142    pub fn list(&self) -> list::ListPullRequestsBuilder {
143        list::ListPullRequestsBuilder::new(&self.owner, &self.repo)
144    }
145
146    /// Get a list of pinned [Pull Requests](crate::model::pulls::PullRequest) in a repository.
147    ///
148    /// # Example
149    /// ```
150    /// # use gitea_sdk::{Client, Auth};
151    /// # async fn pinned_prs() {
152    /// let client = Client::new(
153    ///     "https://gitea.example.com",
154    ///     Auth::Token("your-token")
155    /// );
156    /// let pinned_prs = client
157    ///     .pulls("owner", "repo")
158    ///     .pinned()
159    ///     .send(&client)
160    ///     .await
161    ///     .unwrap();
162    /// # }
163    /// ```
164    /// This will get all pinned pull requests in the repository "owner/repo".
165    pub fn pinned(&self) -> pinned::PinnedPullRequestsBuilder {
166        pinned::PinnedPullRequestsBuilder::new(&self.owner, &self.repo)
167    }
168
169    pub fn reviews(&self) -> reviews::Reviews {
170        reviews::Reviews::new(&self.owner, &self.repo)
171    }
172}