Skip to content

Commit df21bb0

Browse files
committed
fix review dismissal and thread comment updating
1 parent e749061 commit df21bb0

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

cpp-linter/src/rest_api/github/serde_structs.rs

+16
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ impl From<Suggestion> for ReviewDiffComment {
3636
}
3737
}
3838

39+
/// A struct to serialize PR review dismissal payloads.
40+
#[derive(Debug, Serialize)]
41+
pub struct ReviewDismissal {
42+
event: String,
43+
message: String,
44+
}
45+
46+
impl Default for ReviewDismissal {
47+
fn default() -> Self {
48+
Self {
49+
event: "DISMISS".to_string(),
50+
message: "outdated review".to_string(),
51+
}
52+
}
53+
}
54+
3955
/// A structure for deserializing a single changed file in a CI event.
4056
#[derive(Debug, Deserialize, PartialEq, Clone)]
4157
pub struct GithubChangedFile {

cpp-linter/src/rest_api/github/specific_api.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use crate::{
1919
};
2020

2121
use super::{
22-
serde_structs::{FullReview, PullRequestInfo, ReviewComment, ReviewDiffComment, ThreadComment},
22+
serde_structs::{
23+
FullReview, PullRequestInfo, ReviewComment, ReviewDiffComment, ReviewDismissal,
24+
ThreadComment,
25+
},
2326
GithubApiClient, RestApiClient,
2427
};
2528

@@ -206,9 +209,14 @@ impl GithubApiClient {
206209
})?,
207210
);
208211
let repo = format!(
209-
"repos/{}/comments",
212+
"repos/{}{}/comments",
210213
// if we got here, then we know it is on a CI runner as self.repo should be known
211-
self.repo.as_ref().expect("Repo name unknown.")
214+
self.repo.as_ref().expect("Repo name unknown."),
215+
if self.event_name == "pull_request" {
216+
"/issues"
217+
} else {
218+
""
219+
},
212220
);
213221
let base_comment_url = self.api_url.join(&repo).unwrap();
214222
while let Some(ref endpoint) = comments_url {
@@ -460,15 +468,9 @@ impl GithubApiClient {
460468
&self.client,
461469
dismiss_url,
462470
Method::PUT,
463-
Some(
464-
serde_json::json!(
465-
{
466-
"message": "outdated suggestion",
467-
"event": "DISMISS"
468-
}
469-
)
470-
.to_string(),
471-
),
471+
Some(serde_json::to_string(
472+
&ReviewDismissal::default(),
473+
)?),
472474
None,
473475
) {
474476
match Self::send_api_request(

0 commit comments

Comments
 (0)