Skip to content

Commit 4c7ed6e

Browse files
committed
feat: remove pull request event types
1 parent 0b86802 commit 4c7ed6e

File tree

1 file changed

+8
-147
lines changed

1 file changed

+8
-147
lines changed

issue-bot/src/routes.rs

Lines changed: 8 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,6 @@ impl Display for CommentActionType {
5151
}
5252
}
5353

54-
#[derive(Debug, Deserialize, Serialize)]
55-
#[serde(rename_all = "snake_case")]
56-
enum ReviewActionType {
57-
Dismissed,
58-
Edited,
59-
Submitted,
60-
}
61-
impl ReviewActionType {
62-
fn to_action(&self) -> Action {
63-
match self {
64-
Self::Submitted => Action::Created,
65-
Self::Edited => Action::Edited,
66-
Self::Dismissed => unreachable!("ReviewActionType::to_action called with Dismissed"),
67-
}
68-
}
69-
}
70-
71-
impl Display for ReviewActionType {
72-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73-
self.serialize(f)
74-
}
75-
}
76-
7754
#[derive(Debug, Deserialize, Serialize)]
7855
#[serde(rename_all = "snake_case")]
7956
enum IssueActionType {
@@ -101,39 +78,19 @@ impl Display for IssueActionType {
10178
}
10279
}
10380

104-
#[derive(Debug, Deserialize, Serialize)]
105-
#[serde(rename_all = "snake_case")]
106-
enum PullRequestActionType {
107-
Opened,
108-
Edited,
109-
/// We don't care about other action types
110-
#[serde(other)]
111-
Ignored,
112-
}
113-
114-
impl PullRequestActionType {
115-
fn to_action(&self) -> Action {
116-
match self {
117-
Self::Opened => Action::Created,
118-
Self::Edited => Action::Edited,
119-
Self::Ignored => unreachable!("PullRequestActionType::to_action called with Ignored"),
120-
}
121-
}
122-
}
123-
124-
impl Display for PullRequestActionType {
125-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
126-
self.serialize(f)
127-
}
128-
}
129-
13081
#[derive(Debug, Deserialize, Serialize)]
13182
struct Comment {
13283
body: String,
13384
id: i64,
13485
url: String,
13586
}
13687

88+
#[derive(Debug, Deserialize, Serialize)]
89+
struct PullRequest {
90+
html_url: String,
91+
url: String,
92+
}
93+
13794
#[derive(Debug, Deserialize, Serialize)]
13895
struct Issue {
13996
action: IssueActionType,
@@ -147,6 +104,7 @@ struct IssueData {
147104
html_url: String,
148105
id: i64,
149106
number: i32,
107+
pull_request: Option<PullRequest>,
150108
title: String,
151109
url: String,
152110
}
@@ -159,62 +117,18 @@ struct IssueComment {
159117
issue: IssueData,
160118
}
161119

162-
#[derive(Debug, Deserialize, Serialize)]
163-
struct PullRequest {
164-
action: PullRequestActionType,
165-
pull_request: PullRequestData,
166-
}
167-
168-
#[derive(Debug, Deserialize, Serialize)]
169-
struct PullRequestData {
170-
#[serde(default, deserialize_with = "deserialize_null_default")]
171-
body: String,
172-
html_url: String,
173-
id: i64,
174-
number: i32,
175-
title: String,
176-
url: String,
177-
}
178-
179-
#[derive(Debug, Deserialize, Serialize)]
180-
struct Review {
181-
body: String,
182-
id: i64,
183-
url: String,
184-
}
185-
186-
#[derive(Debug, Deserialize, Serialize)]
187-
pub struct PullRequestReview {
188-
action: ReviewActionType,
189-
pull_request: PullRequestData,
190-
review: Review,
191-
}
192-
193-
#[derive(Debug, Deserialize, Serialize)]
194-
struct PullRequestReviewComment {
195-
action: CommentActionType,
196-
comment: Comment,
197-
pull_request: PullRequestData,
198-
}
199-
200120
#[derive(Debug, Deserialize, Serialize)]
201121
#[serde(untagged)]
202122
enum GithubWebhook {
203123
IssueComment(IssueComment),
204124
Issue(Issue),
205-
PullRequestReviewComment(PullRequestReviewComment),
206-
PullRequestReview(PullRequestReview),
207-
PullRequest(PullRequest),
208125
}
209126

210127
impl Display for GithubWebhook {
211128
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
212129
let webhook_type = match self {
213130
Self::Issue(_) => "issue",
214131
Self::IssueComment(_) => "issue comment",
215-
Self::PullRequest(_) => "pull request",
216-
Self::PullRequestReview(_) => "pull request review",
217-
Self::PullRequestReviewComment(_) => "pull request review comment",
218132
};
219133
write!(f, "{}", webhook_type)
220134
}
@@ -252,7 +166,7 @@ pub async fn github_webhook(
252166
action: issue.action.to_action(),
253167
title: issue.issue.title,
254168
body: issue.issue.body,
255-
is_pull_request: false,
169+
is_pull_request: issue.issue.pull_request.is_some(),
256170
number: issue.issue.number,
257171
html_url: issue.issue.html_url,
258172
url: issue.issue.url,
@@ -276,59 +190,6 @@ pub async fn github_webhook(
276190
}))
277191
.await?;
278192
}
279-
GithubWebhook::PullRequest(pr) => {
280-
info!("received {} (state: {})", webhook_type, pr.action);
281-
match pr.action {
282-
PullRequestActionType::Opened | PullRequestActionType::Edited => {
283-
state
284-
.tx
285-
.send(EventData::Issue(crate::IssueData {
286-
source_id: pr.pull_request.id.to_string(),
287-
action: pr.action.to_action(),
288-
title: pr.pull_request.title,
289-
body: pr.pull_request.body,
290-
is_pull_request: true,
291-
number: pr.pull_request.number,
292-
html_url: pr.pull_request.html_url,
293-
url: pr.pull_request.url,
294-
source: Source::Github,
295-
}))
296-
.await?
297-
}
298-
PullRequestActionType::Ignored => (),
299-
}
300-
}
301-
GithubWebhook::PullRequestReview(review) => {
302-
info!("received {} (state: {})", webhook_type, review.action);
303-
match review.action {
304-
ReviewActionType::Submitted | ReviewActionType::Edited => {
305-
state
306-
.tx
307-
.send(EventData::Comment(crate::CommentData {
308-
source_id: review.review.id.to_string(),
309-
issue_id: review.pull_request.id.to_string(),
310-
action: review.action.to_action(),
311-
body: review.review.body,
312-
url: review.review.url,
313-
}))
314-
.await?
315-
}
316-
ReviewActionType::Dismissed => (),
317-
}
318-
}
319-
GithubWebhook::PullRequestReviewComment(comment) => {
320-
info!("received {} (state: {})", webhook_type, comment.action);
321-
state
322-
.tx
323-
.send(EventData::Comment(crate::CommentData {
324-
source_id: comment.comment.id.to_string(),
325-
issue_id: comment.pull_request.id.to_string(),
326-
action: comment.action.to_action(),
327-
body: comment.comment.body,
328-
url: comment.comment.url,
329-
}))
330-
.await?;
331-
}
332193
}
333194

334195
Ok(())

0 commit comments

Comments
 (0)