@@ -161,6 +161,122 @@ pub fn pull_request_request_reviewers(
161161 Ok ( ( ) )
162162}
163163
164+ /// The review action to submit as part of a pull request review.
165+ ///
166+ /// GitHub requires a non-empty `body` alongside `RequestChanges` and `Comment`;
167+ /// it is optional for `Approve`.
168+ #[ derive( Debug , Serialize , Deserialize , Clone , Copy , PartialEq , Eq ) ]
169+ pub enum PullRequestReviewEvent {
170+ /// Approve the pull request.
171+ #[ serde( rename = "APPROVE" ) ]
172+ Approve ,
173+ /// Request changes on the pull request. Requires a `body`.
174+ #[ serde( rename = "REQUEST_CHANGES" ) ]
175+ RequestChanges ,
176+ /// Leave a review comment without approving or requesting changes. Requires a `body`.
177+ #[ serde( rename = "COMMENT" ) ]
178+ Comment ,
179+ }
180+
181+ /// Request to submit a review on a pull request.
182+ #[ derive( Serialize , Deserialize ) ]
183+ pub struct SubmitPullRequestReviewRequest {
184+ /// The account owner of the repository. The name is not case sensitive.
185+ pub owner : String ,
186+ /// The name of the repository without the `.git` extension. The name is not case sensitive.
187+ pub repo : String ,
188+ /// The number of the pull request to review.
189+ pub number : u32 ,
190+ /// The review action to submit.
191+ pub event : PullRequestReviewEvent ,
192+ /// A comment to leave alongside the review. Required unless `event` is `Approve`.
193+ pub body : Option < String > ,
194+ }
195+
196+ /// Submits a review on a pull request.
197+ ///
198+ /// See the [GitHub API docs](https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-request)
199+ /// for more details.
200+ ///
201+ /// ## Arguments
202+ /// * `client_id` - Selects which configured GitHub client to use (supports multiple clients).
203+ /// * `owner` - The account or organization that owns the repository.
204+ /// * `repo` - The name of the repository.
205+ /// * `number` - The number of the pull request to review.
206+ /// * `event` - The review action to submit.
207+ /// * `body` - A comment to leave alongside the review. Required unless `event` is `Approve`.
208+ ///
209+ /// ## Returns
210+ /// * `Ok(())` if the review was successfully submitted, or
211+ /// * `Err(PlaidFunctionError)` if the request fails.
212+ pub fn submit_pull_request_review (
213+ client_id : impl Display ,
214+ owner : impl Display ,
215+ repo : impl Display ,
216+ number : u32 ,
217+ event : PullRequestReviewEvent ,
218+ body : Option < impl Display > ,
219+ ) -> Result < ( ) , PlaidFunctionError > {
220+ extern "C" {
221+ new_host_function ! ( github, submit_pull_request_review) ;
222+ }
223+
224+ let request = SubmitPullRequestReviewRequest {
225+ owner : owner. to_string ( ) ,
226+ repo : repo. to_string ( ) ,
227+ number,
228+ event,
229+ body : body. map ( |b| b. to_string ( ) ) ,
230+ } ;
231+
232+ let wrapped = GithubApiWrapper {
233+ client_id : client_id. to_string ( ) ,
234+ params : request,
235+ } ;
236+ let request = serde_json:: to_string ( & wrapped) . unwrap ( ) ;
237+
238+ let res = unsafe {
239+ github_submit_pull_request_review ( request. as_bytes ( ) . as_ptr ( ) , request. as_bytes ( ) . len ( ) )
240+ } ;
241+
242+ // There was an error with the Plaid system. Maybe the API is not
243+ // configured.
244+ if res < 0 {
245+ return Err ( res. into ( ) ) ;
246+ }
247+
248+ Ok ( ( ) )
249+ }
250+
251+ /// Approves a pull request by submitting an `APPROVE` review on it.
252+ ///
253+ /// ## Arguments
254+ /// * `client_id` - Selects which configured GitHub client to use (supports multiple clients).
255+ /// * `owner` - The account or organization that owns the repository.
256+ /// * `repo` - The name of the repository.
257+ /// * `number` - The number of the pull request to approve.
258+ /// * `body` - An optional comment to leave alongside the approval.
259+ ///
260+ /// ## Returns
261+ /// * `Ok(())` if the review was successfully submitted, or
262+ /// * `Err(PlaidFunctionError)` if the request fails.
263+ pub fn approve_pull_request (
264+ client_id : impl Display ,
265+ owner : impl Display ,
266+ repo : impl Display ,
267+ number : u32 ,
268+ body : Option < impl Display > ,
269+ ) -> Result < ( ) , PlaidFunctionError > {
270+ submit_pull_request_review (
271+ client_id,
272+ owner,
273+ repo,
274+ number,
275+ PullRequestReviewEvent :: Approve ,
276+ body,
277+ )
278+ }
279+
164280/// Request to fetch pull requests from a repository.
165281///
166282/// Represents the top-level parameters needed to query pull requests
0 commit comments