@@ -51,29 +51,6 @@ impl Display for CommentActionType {
51
51
}
52
52
}
53
53
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
-
77
54
#[ derive( Debug , Deserialize , Serialize ) ]
78
55
#[ serde( rename_all = "snake_case" ) ]
79
56
enum IssueActionType {
@@ -101,39 +78,19 @@ impl Display for IssueActionType {
101
78
}
102
79
}
103
80
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
-
130
81
#[ derive( Debug , Deserialize , Serialize ) ]
131
82
struct Comment {
132
83
body : String ,
133
84
id : i64 ,
134
85
url : String ,
135
86
}
136
87
88
+ #[ derive( Debug , Deserialize , Serialize ) ]
89
+ struct PullRequest {
90
+ html_url : String ,
91
+ url : String ,
92
+ }
93
+
137
94
#[ derive( Debug , Deserialize , Serialize ) ]
138
95
struct Issue {
139
96
action : IssueActionType ,
@@ -147,6 +104,7 @@ struct IssueData {
147
104
html_url : String ,
148
105
id : i64 ,
149
106
number : i32 ,
107
+ pull_request : Option < PullRequest > ,
150
108
title : String ,
151
109
url : String ,
152
110
}
@@ -159,62 +117,18 @@ struct IssueComment {
159
117
issue : IssueData ,
160
118
}
161
119
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
-
200
120
#[ derive( Debug , Deserialize , Serialize ) ]
201
121
#[ serde( untagged) ]
202
122
enum GithubWebhook {
203
123
IssueComment ( IssueComment ) ,
204
124
Issue ( Issue ) ,
205
- PullRequestReviewComment ( PullRequestReviewComment ) ,
206
- PullRequestReview ( PullRequestReview ) ,
207
- PullRequest ( PullRequest ) ,
208
125
}
209
126
210
127
impl Display for GithubWebhook {
211
128
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
212
129
let webhook_type = match self {
213
130
Self :: Issue ( _) => "issue" ,
214
131
Self :: IssueComment ( _) => "issue comment" ,
215
- Self :: PullRequest ( _) => "pull request" ,
216
- Self :: PullRequestReview ( _) => "pull request review" ,
217
- Self :: PullRequestReviewComment ( _) => "pull request review comment" ,
218
132
} ;
219
133
write ! ( f, "{}" , webhook_type)
220
134
}
@@ -252,7 +166,7 @@ pub async fn github_webhook(
252
166
action : issue. action . to_action ( ) ,
253
167
title : issue. issue . title ,
254
168
body : issue. issue . body ,
255
- is_pull_request : false ,
169
+ is_pull_request : issue . issue . pull_request . is_some ( ) ,
256
170
number : issue. issue . number ,
257
171
html_url : issue. issue . html_url ,
258
172
url : issue. issue . url ,
@@ -276,59 +190,6 @@ pub async fn github_webhook(
276
190
} ) )
277
191
. await ?;
278
192
}
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
- }
332
193
}
333
194
334
195
Ok ( ( ) )
0 commit comments