1
+ import copy
1
2
import datetime
2
3
import io
3
4
import logging
@@ -591,12 +592,44 @@ def _jira_fake_id_generator() -> Generator[str, int, None]:
591
592
592
593
ctx .logger .info (f"Processing { action .id } " )
593
594
595
+ # check if there are iteration is defined
596
+ if action .iterate :
597
+ # for each value prepare a separate action
598
+ for i , iter_vars in enumerate (action .iterate ):
599
+ ctx .logger .debug (f"Processing iteration: { iter_vars } " )
600
+ new_action = copy .deepcopy (action )
601
+ new_action .iterate = None
602
+ if not new_action .environment :
603
+ new_action .environment = copy .deepcopy (iter_vars )
604
+ else :
605
+ new_action .environment = copy .deepcopy (
606
+ {** new_action .environment , ** iter_vars })
607
+ new_action .id = f"{ new_action .id } .iter{ i + 1 } "
608
+ ctx .logger .debug (f"Created issue config action: { new_action } " )
609
+ issue_actions .insert (i , new_action )
610
+ ctx .logger .info (f"Created { i } iterations of action { action .id } " )
611
+ # now all iterations for a given action, let's process them one by one
612
+ continue
613
+
614
+ # update action.environment and action.context for jinja template rendering
615
+ if action .context :
616
+ action .context = copy .deepcopy (
617
+ {** ctx .cli_context , ** action .context })
618
+ else :
619
+ action .context = copy .deepcopy (ctx .cli_context )
620
+ if action .environment :
621
+ action .environment = copy .deepcopy (
622
+ {** ctx .cli_environment , ** action .environment })
623
+ else :
624
+ action .environment = copy .deepcopy (ctx .cli_environment )
625
+
594
626
if action .when and not eval_test (action .when ,
595
627
JOB = artifact_job ,
596
628
EVENT = artifact_job .event ,
597
629
ERRATUM = artifact_job .erratum ,
598
630
COMPOSE = artifact_job .compose ,
599
- ENVIRONMENT = ctx .cli_environment ):
631
+ CONTEXT = action .context ,
632
+ ENVIRONMENT = action .environment ):
600
633
ctx .logger .info (f"Skipped, issue action is irrelevant ({ action .when } )" )
601
634
continue
602
635
@@ -609,12 +642,14 @@ def _jira_fake_id_generator() -> Generator[str, int, None]:
609
642
action .summary ,
610
643
ERRATUM = artifact_job .erratum ,
611
644
COMPOSE = artifact_job .compose ,
612
- ENVIRONMENT = ctx .cli_environment )
645
+ CONTEXT = action .context ,
646
+ ENVIRONMENT = action .environment )
613
647
rendered_description = render_template (
614
648
action .description ,
615
649
ERRATUM = artifact_job .erratum ,
616
650
COMPOSE = artifact_job .compose ,
617
- ENVIRONMENT = ctx .cli_environment )
651
+ CONTEXT = action .context ,
652
+ ENVIRONMENT = action .environment )
618
653
if assignee :
619
654
rendered_assignee = assignee
620
655
elif unassigned :
@@ -624,15 +659,17 @@ def _jira_fake_id_generator() -> Generator[str, int, None]:
624
659
action .assignee ,
625
660
ERRATUM = artifact_job .erratum ,
626
661
COMPOSE = artifact_job .compose ,
627
- ENVIRONMENT = ctx .cli_environment )
662
+ CONTEXT = action .context ,
663
+ ENVIRONMENT = action .environment )
628
664
else :
629
665
rendered_assignee = None
630
666
if action .newa_id :
631
667
action .newa_id = render_template (
632
668
action .newa_id ,
633
669
ERRATUM = artifact_job .erratum ,
634
670
COMPOSE = artifact_job .compose ,
635
- ENVIRONMENT = ctx .cli_environment )
671
+ CONTEXT = action .context ,
672
+ ENVIRONMENT = action .environment )
636
673
637
674
# Detect that action has parent available (if applicable), if we went trough the
638
675
# actions already and parent was not found, we abort.
@@ -803,14 +840,19 @@ def _jira_fake_id_generator() -> Generator[str, int, None]:
803
840
action .job_recipe ,
804
841
ERRATUM = artifact_job .erratum ,
805
842
COMPOSE = artifact_job .compose ,
806
- ENVIRONMENT = ctx .cli_environment )
843
+ CONTEXT = action .context ,
844
+ ENVIRONMENT = action .environment )
807
845
if action .erratum_comment_triggers :
808
846
new_issue .erratum_comment_triggers = action .erratum_comment_triggers
809
- jira_job = JiraJob (event = artifact_job .event ,
810
- erratum = artifact_job .erratum ,
811
- compose = artifact_job .compose ,
812
- jira = new_issue ,
813
- recipe = Recipe (url = recipe_url ))
847
+ jira_job = JiraJob (
848
+ event = artifact_job .event ,
849
+ erratum = artifact_job .erratum ,
850
+ compose = artifact_job .compose ,
851
+ jira = new_issue ,
852
+ recipe = Recipe (
853
+ url = recipe_url ,
854
+ context = action .context ,
855
+ environment = action .environment ))
814
856
ctx .save_jira_job ('jira-' , jira_job )
815
857
816
858
# Processing old issues - we only expect old issues that are to be closed (if any).
@@ -843,7 +885,10 @@ def _jira_fake_id_generator() -> Generator[str, int, None]:
843
885
erratum = artifact_job .erratum ,
844
886
compose = artifact_job .compose ,
845
887
jira = new_issue ,
846
- recipe = Recipe (url = job_recipe ))
888
+ recipe = Recipe (
889
+ url = job_recipe ,
890
+ context = ctx .cli_context ,
891
+ environment = ctx .cli_environment ))
847
892
ctx .save_jira_job ('jira-' , jira_job )
848
893
849
894
@@ -880,9 +925,21 @@ def cmd_schedule(ctx: CLIContext, arch: list[str], fixtures: list[str]) -> None:
880
925
else :
881
926
architectures = jira_job .erratum .archs if (
882
927
jira_job .erratum and jira_job .erratum .archs ) else Arch .architectures ()
928
+
929
+ # prepare initial config copying it from jira_job,recipe but overriding with cli input
930
+ if jira_job .recipe .context :
931
+ initial_context = copy .deepcopy (
932
+ {** ctx .cli_context , ** jira_job .recipe .context })
933
+ else :
934
+ initial_context = copy .deepcopy (ctx .cli_context )
935
+ if jira_job .recipe .environment :
936
+ initial_environment = copy .deepcopy (
937
+ {** ctx .cli_environment , ** jira_job .recipe .environment })
938
+ else :
939
+ initial_environment = copy .deepcopy (ctx .cli_environment )
883
940
initial_config = RawRecipeConfigDimension (compose = compose ,
884
- environment = ctx . cli_environment ,
885
- context = ctx . cli_context )
941
+ environment = initial_environment ,
942
+ context = initial_context )
886
943
ctx .logger .debug (f'Initial config: { initial_config } )' )
887
944
if fixtures :
888
945
for fixture in fixtures :
0 commit comments