diff --git a/README.md b/README.md index b6cfcca..0bb376a 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,9 @@ formatted and adhere to the expected schema (see the section below). Example of validating rule files with CLI: -``` +```bash +export RETASC_CONFIG=examples/config.yaml + # validate all rules in a path recursively retasc validate-rules examples/rules diff --git a/src/retasc/models/prerequisites/schedule.py b/src/retasc/models/prerequisites/schedule.py index 3671b5a..f19e398 100644 --- a/src/retasc/models/prerequisites/schedule.py +++ b/src/retasc/models/prerequisites/schedule.py @@ -19,6 +19,7 @@ class PrerequisiteSchedule(PrerequisiteBase): - schedule_task - name of the schedule task - start_date - the schedule task's start_date - end_date - the schedule task's end_date + - schedule_task_is_draft - if schedule task is marked as draft """ schedule_task: str = Field( @@ -36,6 +37,7 @@ def _params(self, context) -> dict: "schedule_task": schedule_task, "start_date": task.start_date, "end_date": task.end_date, + "schedule_task_is_draft": task.is_draft, } ) return local_params diff --git a/src/retasc/models/prerequisites/target_date.py b/src/retasc/models/prerequisites/target_date.py index 2bbfb77..8dfa8dc 100644 --- a/src/retasc/models/prerequisites/target_date.py +++ b/src/retasc/models/prerequisites/target_date.py @@ -15,6 +15,10 @@ class PrerequisiteTargetDate(PrerequisiteBase): The prerequisite state is Completed only if the target_date evaluates to a date in the past or it is today. Otherwise, the state is Pending. + Additionally, if ignore_drafts is true (the default value), the + prerequisite state is always Pending if the scheduled item is draft (i.e. + schedule_task_is_draft template parameter is true). + Adds the following template parameters: - target_date - the evaluated target date """ @@ -28,12 +32,19 @@ class PrerequisiteTargetDate(PrerequisiteBase): - "today" """).strip(), ) + ignore_drafts: bool = Field( + description="Ignore draft scheduled items if true (the default).", default=True + ) def update_state(self, context) -> ReleaseRuleState: """ Return Completed if target date is earlier than today, otherwise return Pending. """ + if self.ignore_drafts and context.template.params["schedule_task_is_draft"]: + context.report.set("schedule_task_is_draft", True) + return ReleaseRuleState.Pending + target_date = context.template.evaluate(self.target_date) context.template.params["target_date"] = target_date today = context.template.env.globals["today"] diff --git a/src/retasc/product_pages_api.py b/src/retasc/product_pages_api.py index 40bbf85..8339089 100644 --- a/src/retasc/product_pages_api.py +++ b/src/retasc/product_pages_api.py @@ -14,6 +14,7 @@ class ProductPagesScheduleTask: start_date: date end_date: date + is_draft: bool = False class ProductPagesApi: @@ -49,13 +50,16 @@ def release_schedules( :return: dict with schedule name as key and start date as value """ url = f"{self.api_url}/releases/{release_short_name}/schedule-tasks" - res = self.session.get(url, params={"fields": "name,date_start,date_finish"}) + res = self.session.get( + url, params={"fields": "name,date_start,date_finish,draft"} + ) res.raise_for_status() data = res.json() return { item["name"]: ProductPagesScheduleTask( start_date=date.fromisoformat(item["date_start"]), end_date=date.fromisoformat(item["date_finish"]), + is_draft=item["draft"], ) for item in data } diff --git a/tests/test_product_pages_api.py b/tests/test_product_pages_api.py index 6acbec3..8c98006 100644 --- a/tests/test_product_pages_api.py +++ b/tests/test_product_pages_api.py @@ -26,8 +26,24 @@ def test_active_releases(pp_api, requests_mock): def test_release_schedules(pp_api, requests_mock): schedules = [ - {"name": "task1", "date_start": "2024-10-01", "date_finish": "2024-10-02"}, - {"name": "task2", "date_start": "2024-11-20", "date_finish": "2024-11-21"}, + { + "name": "task1", + "date_start": "2024-10-01", + "date_finish": "2024-10-02", + "draft": False, + }, + { + "name": "task2", + "date_start": "2024-11-20", + "date_finish": "2024-11-21", + "draft": False, + }, + { + "name": "task3", + "date_start": "2024-11-21", + "date_finish": "2024-11-22", + "draft": True, + }, ] requests_mock.get( f"{PP_URL}/releases/example_product/schedule-tasks", @@ -43,4 +59,9 @@ def test_release_schedules(pp_api, requests_mock): start_date=date(2024, 11, 20), end_date=date(2024, 11, 21), ), + "task3": ProductPagesScheduleTask( + start_date=date(2024, 11, 21), + end_date=date(2024, 11, 22), + is_draft=True, + ), } diff --git a/tests/test_run.py b/tests/test_run.py index cb066f1..8aab682 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -394,23 +394,26 @@ def test_run_rule_condition_failed(condition_expr, result, factory): @mark.parametrize( - ("target_date", "result"), + ("target_date", "is_draft", "result"), ( - ("start_date", True), - ("start_date - 1|weeks", True), - ("start_date + 1|weeks", True), - ("end_date - 1|weeks", True), - ("end_date + 1|weeks", False), - ("today", True), - ("today + 1|days", False), - ("today + 1|weeks", False), + ("start_date", False, True), + ("start_date", True, False), + ("start_date - 1|weeks", False, True), + ("start_date + 1|weeks", False, True), + ("end_date - 1|weeks", False, True), + ("end_date + 1|weeks", False, False), + ("today", False, True), + ("today", True, False), + ("today + 1|days", False, False), + ("today + 1|weeks", False, False), ), ) -def test_run_rule_schedule_target_date(target_date, result, mock_pp, factory): +def test_run_rule_schedule_target_date(target_date, is_draft, result, mock_pp, factory): mock_pp.release_schedules.return_value = { "TASK": ProductPagesScheduleTask( start_date=date(1990, 1, 1), end_date=datetime.now(UTC).date(), + is_draft=is_draft, ), } rule = factory.new_rule(