gitea_sdk/api/issues/mod.rs
1pub mod comments;
2pub mod create;
3pub mod delete;
4pub mod edit;
5pub mod get;
6pub mod list;
7
8pub struct Issues {
9 pub(crate) owner: String,
10 pub(crate) repo: String,
11}
12
13impl Issues {
14 /// Create an issue.
15 /// If using deadline only the date will be taken into account, and time of day ignored.
16 /// The only required field in the [CreateIssueOption] is `title`. All other fields are
17 /// optional.
18 /// This method will return the created issue.
19 ///
20 /// # Example
21 /// ```
22 /// # use gitea_sdk::{Client, Auth};
23 /// # async fn create_issue() {
24 /// let client = Client::new(
25 /// "https://gitea.example.com",
26 /// Auth::Token("your-token")
27 /// );
28 /// let issue = client
29 /// .issues("owner", "repo")
30 /// .create("my-new-issue")
31 /// .send(&client)
32 /// .await
33 /// .unwrap();
34 /// # }
35 /// ```
36 /// This will create a new issue with the title "my-new-issue" in the repository "owner/repo".
37 pub fn create(&self, title: impl ToString) -> create::CreateIssueBuilder {
38 create::CreateIssueBuilder::new(&self.owner, &self.repo, title)
39 }
40 /// Delete an issue.
41 /// This will delete the issue with the given issue number.
42 /// WARNING: This is irreversible and will not ask for confirmation. Use with caution.
43 ///
44 /// This method will return a 204 status code if the issue was successfully deleted.
45 /// If the issue does not exist, this method will return a 404 status code.
46 /// If the user is not authorized to delete the issue, this method will return a 403 status
47 /// code.
48 ///
49 /// # Example
50 ///
51 /// ```rust
52 /// # use gitea_sdk::{Client, Auth};
53 /// # async fn delete_issue() {
54 /// let client = Client::new(
55 /// "https://gitea.example.com",
56 /// Auth::Token("your-token")
57 /// );
58 /// client
59 /// .issues("owner", "repo")
60 /// .delete(1)
61 /// .send(&client)
62 /// .await
63 /// .unwrap();
64 /// # }
65 /// ```
66 /// This will delete the issue #1 in the repository "owner/repo".
67 pub fn delete(&self, issue_number: i64) -> delete::DeleteIssueBuilder {
68 delete::DeleteIssueBuilder::new(&self.owner, &self.repo, issue_number)
69 }
70
71 /// Get an issue.
72 /// This will return the issue with the given issue number.
73 ///
74 /// # Example
75 /// ```rust
76 /// # use gitea_sdk::{Client, Auth};
77 /// # async fn get_issue() {
78 /// let client = Client::new(
79 /// "https://gitea.example.com",
80 /// Auth::Token("your-token")
81 /// );
82 /// let issue = client
83 /// .issues("owner", "repo")
84 /// .get(1)
85 /// .send(&client)
86 /// .await
87 /// .unwrap();
88 /// # }
89 /// ```
90 /// This will get the issue #1 in the repository "owner/repo".
91 pub fn get(&self, issue_number: i64) -> get::GetIssueBuilder {
92 get::GetIssueBuilder::new(&self.owner, &self.repo, issue_number)
93 }
94
95 /// Edit an issue.
96 ///
97 /// # Example
98 /// ```rust
99 /// # use gitea_sdk::{Client, Auth};
100 /// # async fn edit_issue() {
101 /// let client = Client::new(
102 /// "https://gitea.example.com",
103 /// Auth::Token("your-token")
104 /// );
105 /// client
106 /// .issues("owner", "repo")
107 /// .edit(1)
108 /// .title("new-title")
109 /// .send(&client)
110 /// .await
111 /// .unwrap();
112 /// # }
113 /// ```
114 pub fn edit(&self, issue_number: i64) -> edit::EditIssueBuilder {
115 edit::EditIssueBuilder::new(&self.owner, &self.repo, issue_number)
116 }
117
118 /// List a repository's issues.
119 /// The [GetIssuesOption] struct provides a number of optional fields to filter the results,
120 /// but all fields are entirely optional.
121 /// If you don't set any fields, you will get the most recent issues for the repository.
122 ///
123 ///
124 /// # Example
125 ///
126 /// ```rust
127 /// # use gitea_sdk::{Client, Auth, model::issues::State};
128 /// # async fn get_issues() {
129 /// let client = Client::new(
130 /// "https://gitea.example.com",
131 /// Auth::Token("your-token")
132 /// );
133 /// let issues = client
134 /// .issues("owner", "repo")
135 /// .list()
136 /// .state(State::Open)
137 /// .send(&client)
138 /// .await
139 /// .unwrap();
140 /// # }
141 /// ```
142 /// This will get all open issues in the repository "owner/repo".
143 pub fn list(&self) -> list::ListIssuesBuilder {
144 list::ListIssuesBuilder::new(&self.owner, &self.repo)
145 }
146
147 /// Miscellaneous methods for comments on issues.
148 ///
149 /// # Example
150 /// ```
151 /// # use gitea_sdk::{Client, Auth};
152 /// # async fn list_comments() {
153 /// let client = Client::new(
154 /// "https://gitea.example.com",
155 /// Auth::Token("your-token")
156 /// );
157 /// let comments = client
158 /// .issues("owner", "repo")
159 /// .comments();
160 /// }
161 /// ```
162 pub fn comments(&self) -> comments::Comments {
163 comments::Comments {
164 owner: self.owner.clone(),
165 repo: self.repo.clone(),
166 }
167 }
168}