@@ -108,40 +108,79 @@ async fn mock_graphql(github: Arc<tokio::sync::Mutex<GitHubState>>, mock_server:
108108 let query: Document < & str > =
109109 graphql_parser:: parse_query ( & body. query ) . expect ( "Could not parse GraphQL query" ) ;
110110 let definition = query. definitions . into_iter ( ) . next ( ) . unwrap ( ) ;
111- let mutation = match definition {
112- Definition :: Operation ( OperationDefinition :: Mutation ( mutation) ) => mutation,
111+ let selection_set = match definition {
112+ Definition :: Operation ( OperationDefinition :: Mutation ( mutation) ) => {
113+ mutation. selection_set
114+ }
115+ Definition :: Operation ( OperationDefinition :: Query ( query) ) => query. selection_set ,
113116 _ => panic ! ( "Unexpected GraphQL query: {}" , body. query) ,
114117 } ;
115- let selection = mutation . selection_set . items . into_iter ( ) . next ( ) . unwrap ( ) ;
118+ let selection = selection_set. items . into_iter ( ) . next ( ) . unwrap ( ) ;
116119 let operation = match selection {
117120 Selection :: Field ( field) => field,
118121 _ => panic ! ( "Unexpected GraphQL selection" ) ,
119122 } ;
120- if operation. name == "minimizeComment" {
121- #[ derive( serde:: Deserialize ) ]
122- struct Variables {
123- node_id : String ,
124- reason : HideCommentReason ,
123+
124+ match operation. name {
125+ "minimizeComment" => {
126+ #[ derive( serde:: Deserialize ) ]
127+ struct Variables {
128+ node_id : String ,
129+ reason : HideCommentReason ,
130+ }
131+
132+ let github = github. clone ( ) ;
133+ let data: Variables = serde_json:: from_value ( body. variables ) . unwrap ( ) ;
134+
135+ // We have to use e.g. `blocking_lock` to lock from a sync function.
136+ // It has to happen in a separate thread though.
137+ std:: thread:: spawn ( move || {
138+ github. blocking_lock ( ) . add_hidden_comment ( HiddenComment {
139+ node_id : data. node_id ,
140+ reason : data. reason ,
141+ } ) ;
142+ } )
143+ . join ( )
144+ . unwrap ( ) ;
145+ ResponseTemplate :: new ( 200 ) . set_body_json ( HashMap :: < String , String > :: new ( ) )
146+ }
147+ "updateComment" => {
148+ #[ derive( serde:: Deserialize ) ]
149+ struct Variables {
150+ id : String ,
151+ body : String ,
152+ }
153+
154+ let data: Variables = serde_json:: from_value ( body. variables ) . unwrap ( ) ;
155+ let response = serde_json:: json!( {
156+ "update_comment" : {
157+ "comment" : {
158+ "id" : data. id,
159+ "body" : data. body
160+ }
161+ }
162+ } ) ;
163+
164+ ResponseTemplate :: new ( 200 ) . set_body_json ( response)
125165 }
166+ "node" => {
167+ #[ derive( serde:: Deserialize ) ]
168+ struct Variables {
169+ node_id : String ,
170+ }
126171
127- let github = github. clone ( ) ;
128- let data: Variables = serde_json:: from_value ( body. variables ) . unwrap ( ) ;
172+ let data: Variables = serde_json:: from_value ( body. variables ) . unwrap ( ) ;
129173
130- // We have to use e.g. `blocking_lock` to lock from a sync function.
131- // It has to happen in a separate thread though.
132- std:: thread:: spawn ( move || {
133- github. blocking_lock ( ) . add_hidden_comment ( HiddenComment {
134- node_id : data. node_id ,
135- reason : data. reason ,
174+ let response = serde_json:: json!( {
175+ "node" : {
176+ "__typename" : "IssueComment" ,
177+ "body" : format!( ":hourglass: Trying commit {} \n To cancel the try build, run the command @bors try cancel`." , data. node_id)
178+ }
136179 } ) ;
137- } )
138- . join ( )
139- . unwrap ( ) ;
140- } else {
141- panic ! ( "Unexpected operation {}" , operation. name) ;
180+ ResponseTemplate :: new ( 200 ) . set_body_json ( response)
181+ }
182+ _ => panic ! ( "Unexpected GraphQL operation {}" , operation. name) ,
142183 }
143-
144- ResponseTemplate :: new ( 200 ) . set_body_json ( HashMap :: < String , String > :: new ( ) )
145184 } ,
146185 "POST" ,
147186 "^/graphql$" . to_string ( ) ,
0 commit comments