@@ -297,11 +297,15 @@ def test_convert_to_pipeline_event(
297297
298298@pytest .mark .asyncio
299299@patch ("operatorcert.webhook_dispatcher.dispatcher.asyncio.sleep" )
300+ @patch (
301+ "operatorcert.webhook_dispatcher.dispatcher.EventDispatcher.set_github_queued_label"
302+ )
300303@patch ("operatorcert.webhook_dispatcher.dispatcher.PipelineEvent.trigger_pipeline" )
301304@patch ("operatorcert.webhook_dispatcher.dispatcher.PipelineEvent.is_capacity_available" )
302305async def test_process_pipeline_event (
303306 mock_is_capacity_available : AsyncMock ,
304307 mock_trigger_pipeline : AsyncMock ,
308+ mock_set_github_queued_label : MagicMock ,
305309 mock_time_sleep : MagicMock ,
306310 dispatcher : EventDispatcher ,
307311) -> None :
@@ -319,14 +323,17 @@ async def test_process_pipeline_event(
319323 # no capacity
320324 await dispatcher .process_pipeline_event (pipeline_event )
321325 mock_trigger_pipeline .assert_not_called ()
326+ mock_set_github_queued_label .assert_called_once_with (pipeline_event )
322327 assert pipeline_event .event .processed == False
323328
324329 # capacity available but trigger pipeline failed
325330 mock_trigger_pipeline .reset_mock ()
331+ mock_set_github_queued_label .reset_mock ()
326332 mock_trigger_pipeline .return_value = False
327333 mock_is_capacity_available .return_value = True
328334 await dispatcher .process_pipeline_event (pipeline_event )
329335 mock_trigger_pipeline .assert_called_once_with ()
336+ mock_set_github_queued_label .assert_not_called ()
330337 assert pipeline_event .event .processed == False
331338
332339 # capacity available and trigger pipeline successful
@@ -519,3 +526,49 @@ def test_match_cel_expression(
519526
520527 result = dispatcher .match_cel_expression (event , item .filter .cel_expression ) # type: ignore
521528 assert result is expected_result
529+
530+
531+ @patch ("operatorcert.webhook_dispatcher.dispatcher.add_labels_to_pull_request" )
532+ @patch ("operatorcert.webhook_dispatcher.dispatcher.Github" )
533+ @patch ("operatorcert.webhook_dispatcher.dispatcher.Auth" )
534+ def test_set_github_queued_label (
535+ mock_auth : MagicMock ,
536+ mock_github : MagicMock ,
537+ mock_add_labels : MagicMock ,
538+ monkeypatch : Any ,
539+ ) -> None :
540+ monkeypatch .setenv ("GITHUB_TOKEN" , "test_token" )
541+ config_item = DispatcherConfigItem (
542+ name = "test1.0" ,
543+ events = ["pull_request" ],
544+ full_repository_name = "test/test" ,
545+ callback_url = "http://test.com" ,
546+ capacity = CapacityConfig (
547+ type = "test" ,
548+ pipeline_name = "my-pipeline" ,
549+ max_capacity = 10 ,
550+ namespace = "test" ,
551+ ),
552+ )
553+ event = WebhookEvent (
554+ id = 1 ,
555+ repository_full_name = "test/test" ,
556+ pull_request_number = 1 ,
557+ action = "push" ,
558+ processed = False ,
559+ processing_error = None ,
560+ )
561+ pipeline_event = PipelineEvent (event , config_item )
562+ mock_pull_request = MagicMock ()
563+ mock_github .return_value .get_repo .return_value .get_pull .return_value = (
564+ mock_pull_request
565+ )
566+ EventDispatcher .set_github_queued_label (pipeline_event )
567+
568+ mock_auth .Token .assert_called_once_with ("test_token" )
569+ mock_github .assert_called_once_with (auth = mock_auth .Token .return_value )
570+
571+ mock_github .return_value .get_repo .assert_called_once_with ("test/test" )
572+ mock_github .return_value .get_repo .return_value .get_pull .assert_called_once_with (1 )
573+
574+ mock_add_labels .assert_called_once_with (mock_pull_request , ["my-pipeline/queued" ])
0 commit comments