Skip to content

Commit ff6d4af

Browse files
committed
worker: hide previous comments when a new commit is pushed
1 parent 94f29a8 commit ff6d4af

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

src/bin/server/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ pub struct QueueItem {
1414
pub enum QueueItemKind {
1515
GitHubStatus(rla::github::CommitStatusEvent),
1616
GitHubCheckRun(rla::github::CheckRunEvent),
17+
GitHubPullRequest(rla::github::PullRequestEvent),
1718
}

src/bin/server/service.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ impl RlaService {
100100

101101
QueueItemKind::GitHubCheckRun(payload)
102102
}
103+
"pull_request" => match serde_json::from_slice(body) {
104+
Ok(payload) => QueueItemKind::GitHubPullRequest(payload),
105+
Err(err) => {
106+
error!("Failed to decode 'pull_request' webhook payload: {}", err);
107+
return reply(StatusCode::BAD_REQUEST, "Failed to decode payload\n");
108+
}
109+
},
103110
"issue_comment" => {
104111
debug!("Ignoring 'issue_comment' event.");
105112
return reply(StatusCode::OK, "Event ignored.\n");

src/bin/server/worker.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ impl Worker {
115115
return Ok(());
116116
}
117117
},
118+
QueueItemKind::GitHubPullRequest(ev) => return self.process_pr(ev),
118119
};
119120

120121
span.record("build_id", &build_id);
@@ -325,6 +326,15 @@ impl Worker {
325326

326327
Ok(())
327328
}
329+
330+
fn process_pr(&self, e: &rla::github::PullRequestEvent) -> rla::Result<()> {
331+
// Hide all comments by the bot when a new commit is pushed.
332+
if let rla::github::PullRequestAction::Synchronize = e.action {
333+
self.github
334+
.hide_own_comments(&e.repository.full_name, e.number)?;
335+
}
336+
Ok(())
337+
}
328338
}
329339

330340
/// Keeps track of the recently seen IDs for both the failed build reports and the learned jobs.

src/github.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,32 @@ pub struct Repository {
122122
pub full_name: String,
123123
}
124124

125+
#[derive(Deserialize)]
126+
#[serde(rename_all = "snake_case")]
127+
pub enum PullRequestAction {
128+
Opened,
129+
Edited,
130+
Closed,
131+
Assigned,
132+
Unassigned,
133+
ReviewRequested,
134+
ReviewRequestRemoved,
135+
ReadyForReview,
136+
Labeled,
137+
Unlabeled,
138+
Synchronize,
139+
Locked,
140+
Unlocked,
141+
Reopened,
142+
}
143+
144+
#[derive(Deserialize)]
145+
pub struct PullRequestEvent {
146+
pub action: PullRequestAction,
147+
pub number: u32,
148+
pub repository: Repository,
149+
}
150+
125151
#[derive(Deserialize)]
126152
struct GraphResponse<T> {
127153
data: T,
@@ -213,8 +239,7 @@ impl Client {
213239
}
214240

215241
pub fn hide_own_comments(&self, repo: &str, pull_request_id: u32) -> Result<()> {
216-
const QUERY: &str =
217-
"query($owner: String!, $repo: String!, $pr: Int!, $cursor: String) {
242+
const QUERY: &str = "query($owner: String!, $repo: String!, $pr: Int!, $cursor: String) {
218243
repository(owner: $owner, name: $repo) {
219244
pullRequest(number: $pr) {
220245
comments(first: 100, after: $cursor) {

0 commit comments

Comments
 (0)