From e260afd97616fb3b2087f653c3e713432292a264 Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 25 Sep 2023 10:37:08 -0400 Subject: [PATCH] use the long revision when comparing git revs for webhook w/ burnettk --- .../data_migrations/version_1_3.py | 12 +++++++++--- .../spiffworkflow_backend/services/git_service.py | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/data_migrations/version_1_3.py b/spiffworkflow-backend/src/spiffworkflow_backend/data_migrations/version_1_3.py index e1168eba..009e5bd2 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/data_migrations/version_1_3.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/data_migrations/version_1_3.py @@ -204,15 +204,21 @@ class VersionOneThree: properties_json = copy.copy(task_definition.properties_json) properties_json["event_definition"].pop("internal", None) properties_json["event_definition"].pop("external", None) + + something_changed = False if "escalation_code" in properties_json["event_definition"]: properties_json["event_definition"]["code"] = properties_json["event_definition"].pop( "escalation_code" ) + something_changed = True if "error_code" in properties_json["event_definition"]: properties_json["event_definition"]["code"] = properties_json["event_definition"].pop("error_code") - task_definition.properties_json = properties_json - flag_modified(task_definition, "properties_json") # type: ignore - db.session.add(task_definition) + something_changed = True + + if something_changed: + task_definition.properties_json = properties_json + flag_modified(task_definition, "properties_json") # type: ignore + db.session.add(task_definition) def update_tasks_where_last_change_is_null(self) -> None: task_models = TaskModel.query.filter(TaskModel.properties_json.like('%last_state_change": null%')).all() # type: ignore diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/git_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/git_service.py index fc2fa009..4dc0338a 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/git_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/git_service.py @@ -31,11 +31,17 @@ class GitCommandError(Exception): # TOOD: check for the existence of git and configs on bootup if publishing is enabled class GitService: @classmethod - def get_current_revision(cls) -> str: + def get_current_revision(cls, short_rev: bool = True) -> str: bpmn_spec_absolute_dir = current_app.config["SPIFFWORKFLOW_BACKEND_BPMN_SPEC_ABSOLUTE_DIR"] + + git_command = ["git", "rev-parse"] + if short_rev: + git_command.append("--short") + git_command.append("HEAD") + # The value includes a carriage return character at the end, so we don't grab the last character with FileSystemService.cd(bpmn_spec_absolute_dir): - return cls.run_shell_command_to_get_stdout(["git", "rev-parse", "--short", "HEAD"]) + return cls.run_shell_command_to_get_stdout(git_command) @classmethod def get_instance_file_contents_for_revision( @@ -187,7 +193,7 @@ class GitService: if "after" not in webhook: raise InvalidGitWebhookBodyError(f"Could not find the 'after' arg in the webhook body: {webhook}") - git_revision_before_pull = cls.get_current_revision() + git_revision_before_pull = cls.get_current_revision(short_rev=False) git_revision_after = webhook["after"] if git_revision_before_pull == git_revision_after: current_app.logger.info("Skipping git pull because we already have the current git revision, git boy!")