From 8c5e11ca68b71470f6f157421acc5e271b60173f Mon Sep 17 00:00:00 2001 From: burnettk Date: Tue, 4 Oct 2022 14:42:31 -0400 Subject: [PATCH 1/5] auto git commit on save --- bin/git_commit_bpmn_models_repo | 28 +++++++++++++++++++ .../routes/process_api_blueprint.py | 4 +++ .../services/git_service.py | 10 +++++++ .../services/process_model_service.py | 7 ++++- 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 bin/git_commit_bpmn_models_repo diff --git a/bin/git_commit_bpmn_models_repo b/bin/git_commit_bpmn_models_repo new file mode 100755 index 00000000..f35d9ac7 --- /dev/null +++ b/bin/git_commit_bpmn_models_repo @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +function error_handler() { + >&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}." + exit "$2" +} +trap 'error_handler ${LINENO} $?' ERR +set -o errtrace -o errexit -o nounset -o pipefail + +# HELP: git adds and commits the entire BPMN models directory, including all process groups + +bpmn_models_absolute_dir="$1" +git_commit_message="$2" + +if [[ -z "${2:-}" ]]; then + >&2 echo "usage: $(basename "$0") [bpmn_models_absolute_dir] [git_commit_message]" + exit 1 +fi + +cd "$bpmn_models_absolute_dir" +git add . + +# https://unix.stackexchange.com/a/155077/456630 +if [ -z "$(git status --porcelain)" ]; then + echo "No changes to commit" +else + git commit -m "$git_commit_message" +fi diff --git a/src/spiffworkflow_backend/routes/process_api_blueprint.py b/src/spiffworkflow_backend/routes/process_api_blueprint.py index f13240df..7b593b04 100644 --- a/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -270,6 +270,10 @@ def process_model_file_update( ) SpecFileService.update_file(process_model, file_name, request_file_contents) + git_output = GitService.commit( + message=f"User: {g.user.username} clicked save for {process_group_id}/{process_model_id}/{file_name}" + ) + current_app.logger.info(f"git output: {git_output}") return Response(json.dumps({"ok": True}), status=200, mimetype="application/json") diff --git a/src/spiffworkflow_backend/services/git_service.py b/src/spiffworkflow_backend/services/git_service.py index 79f2e41f..fde31ef7 100644 --- a/src/spiffworkflow_backend/services/git_service.py +++ b/src/spiffworkflow_backend/services/git_service.py @@ -38,3 +38,13 @@ class GitService: file_contents: str = os.popen(shell_command).read()[:-1] # noqa: S605 assert file_contents # noqa: S101 return file_contents.encode("utf-8") + + @staticmethod + def commit(message: str) -> str: + """Commit.""" + bpmn_spec_absolute_dir = current_app.config["BPMN_SPEC_ABSOLUTE_DIR"] + shell_command = ( + f"./bin/git_commit_bpmn_models_repo '{bpmn_spec_absolute_dir}' '{message}'" + ) + output = os.popen(shell_command).read() # noqa: S605 + return output diff --git a/src/spiffworkflow_backend/services/process_model_service.py b/src/spiffworkflow_backend/services/process_model_service.py index b7333215..20b00e7f 100644 --- a/src/spiffworkflow_backend/services/process_model_service.py +++ b/src/spiffworkflow_backend/services/process_model_service.py @@ -206,7 +206,12 @@ class ProcessModelService(FileSystemService): os.makedirs(cat_path, exist_ok=True) json_path = os.path.join(cat_path, self.CAT_JSON_FILE) with open(json_path, "w") as cat_json: - json.dump(self.GROUP_SCHEMA.dump(process_group), cat_json, indent=4) + json.dump( + self.GROUP_SCHEMA.dump(process_group), + cat_json, + indent=4, + sort_keys=True, + ) return process_group def process_group_delete(self, process_group_id: str) -> None: From 427960698d32871f9f9cfc5342d7d6b5797d0542 Mon Sep 17 00:00:00 2001 From: burnettk Date: Tue, 4 Oct 2022 15:07:48 -0400 Subject: [PATCH 2/5] make git commit on save configurable --- src/spiffworkflow_backend/config/default.py | 4 ++++ src/spiffworkflow_backend/config/staging.py | 1 + .../routes/process_api_blueprint.py | 13 +++++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/spiffworkflow_backend/config/default.py b/src/spiffworkflow_backend/config/default.py index 2dde7ad2..478d8b3e 100644 --- a/src/spiffworkflow_backend/config/default.py +++ b/src/spiffworkflow_backend/config/default.py @@ -23,6 +23,10 @@ SPIFFWORKFLOW_BACKEND_URL = environ.get( "SPIFFWORKFLOW_BACKEND_URL", default="http://localhost:7000" ) +GIT_COMMIT_ON_SAVE = ( + environ.get("GIT_COMMIT_ON_SAVE", default="false") == "true" +) + # Open ID server OPEN_ID_SERVER_URL = environ.get("OPEN_ID_SERVER_URL", default="http://localhost:7002") OPEN_ID_CLIENT_ID = environ.get("OPEN_ID_CLIENT_ID", default="spiffworkflow-backend") diff --git a/src/spiffworkflow_backend/config/staging.py b/src/spiffworkflow_backend/config/staging.py index cca69ba7..90a3ffa9 100644 --- a/src/spiffworkflow_backend/config/staging.py +++ b/src/spiffworkflow_backend/config/staging.py @@ -1 +1,2 @@ """Staging.""" +GIT_COMMIT_ON_SAVE = True diff --git a/src/spiffworkflow_backend/routes/process_api_blueprint.py b/src/spiffworkflow_backend/routes/process_api_blueprint.py index 7b593b04..ffe6742d 100644 --- a/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -270,10 +270,15 @@ def process_model_file_update( ) SpecFileService.update_file(process_model, file_name, request_file_contents) - git_output = GitService.commit( - message=f"User: {g.user.username} clicked save for {process_group_id}/{process_model_id}/{file_name}" - ) - current_app.logger.info(f"git output: {git_output}") + + if current_app.config["GIT_COMMIT_ON_SAVE"]: + git_output = GitService.commit( + message=f"User: {g.user.username} clicked save for {process_group_id}/{process_model_id}/{file_name}" + ) + current_app.logger.info(f"git output: {git_output}") + else: + current_app.logger.info("Git commit on save is disabled") + return Response(json.dumps({"ok": True}), status=200, mimetype="application/json") From b8abd5a7bc9b8668739d7908bdf3f3a4302896f6 Mon Sep 17 00:00:00 2001 From: burnettk Date: Tue, 4 Oct 2022 15:43:18 -0400 Subject: [PATCH 3/5] lint --- src/spiffworkflow_backend/config/default.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/spiffworkflow_backend/config/default.py b/src/spiffworkflow_backend/config/default.py index 478d8b3e..94d89ffc 100644 --- a/src/spiffworkflow_backend/config/default.py +++ b/src/spiffworkflow_backend/config/default.py @@ -23,9 +23,7 @@ SPIFFWORKFLOW_BACKEND_URL = environ.get( "SPIFFWORKFLOW_BACKEND_URL", default="http://localhost:7000" ) -GIT_COMMIT_ON_SAVE = ( - environ.get("GIT_COMMIT_ON_SAVE", default="false") == "true" -) +GIT_COMMIT_ON_SAVE = environ.get("GIT_COMMIT_ON_SAVE", default="false") == "true" # Open ID server OPEN_ID_SERVER_URL = environ.get("OPEN_ID_SERVER_URL", default="http://localhost:7002") From 3b86b3cc1ab0cd968d532848b712d8fc94c25fdc Mon Sep 17 00:00:00 2001 From: burnettk Date: Tue, 4 Oct 2022 16:07:51 -0400 Subject: [PATCH 4/5] configure staging to set git config --- bin/git_commit_bpmn_models_repo | 8 ++++++++ src/spiffworkflow_backend/config/staging.py | 2 ++ src/spiffworkflow_backend/services/git_service.py | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bin/git_commit_bpmn_models_repo b/bin/git_commit_bpmn_models_repo index f35d9ac7..13e18da9 100755 --- a/bin/git_commit_bpmn_models_repo +++ b/bin/git_commit_bpmn_models_repo @@ -11,6 +11,8 @@ set -o errtrace -o errexit -o nounset -o pipefail bpmn_models_absolute_dir="$1" git_commit_message="$2" +git_commit_username="$3" +git_commit_email="$4" if [[ -z "${2:-}" ]]; then >&2 echo "usage: $(basename "$0") [bpmn_models_absolute_dir] [git_commit_message]" @@ -24,5 +26,11 @@ git add . if [ -z "$(git status --porcelain)" ]; then echo "No changes to commit" else + if [[ -n "$git_commit_username" ]]; then + git config --local user.name "$git_commit_username" + fi + if [[ -n "$git_commit_email" ]]; then + git config --local user.email "$git_commit_email" + fi git commit -m "$git_commit_message" fi diff --git a/src/spiffworkflow_backend/config/staging.py b/src/spiffworkflow_backend/config/staging.py index 90a3ffa9..55bb285b 100644 --- a/src/spiffworkflow_backend/config/staging.py +++ b/src/spiffworkflow_backend/config/staging.py @@ -1,2 +1,4 @@ """Staging.""" GIT_COMMIT_ON_SAVE = True +GIT_COMMIT_USERNAME = "staging" +GIT_COMMIT_EMAIL = "staging@example.com" diff --git a/src/spiffworkflow_backend/services/git_service.py b/src/spiffworkflow_backend/services/git_service.py index fde31ef7..6a192b97 100644 --- a/src/spiffworkflow_backend/services/git_service.py +++ b/src/spiffworkflow_backend/services/git_service.py @@ -43,8 +43,13 @@ class GitService: def commit(message: str) -> str: """Commit.""" bpmn_spec_absolute_dir = current_app.config["BPMN_SPEC_ABSOLUTE_DIR"] + git_username = '' + git_email = '' + if current_app.config["GIT_COMMIT_USERNAME"] and current_app.config["GIT_COMMIT_EMAIL"]: + git_username = current_app.config["GIT_COMMIT_USERNAME"] + git_email = current_app.config["GIT_COMMIT_EMAIL"] shell_command = ( - f"./bin/git_commit_bpmn_models_repo '{bpmn_spec_absolute_dir}' '{message}'" + f"./bin/git_commit_bpmn_models_repo '{bpmn_spec_absolute_dir}' '{message}' '{git_username}' '{git_email}'" ) output = os.popen(shell_command).read() # noqa: S605 return output From f44bc1f71c0bdc396ffec287d3b6d6e905a56af4 Mon Sep 17 00:00:00 2001 From: burnettk Date: Tue, 4 Oct 2022 16:37:42 -0400 Subject: [PATCH 5/5] get off branch that is gone --- poetry.lock | 15 ++++++++------- pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/poetry.lock b/poetry.lock index 3ace24fa..0f1f50f0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -823,7 +823,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" [[package]] name = "importlib-metadata" -version = "5.0.0" +version = "4.13.0" description = "Read metadata from Python packages" category = "main" optional = false @@ -1827,7 +1827,7 @@ test = ["pytest"] [[package]] name = "SpiffWorkflow" version = "1.1.7" -description = "A workflow framework and BPMN/DMN Processor" +description = "" category = "main" optional = false python-versions = "*" @@ -1837,14 +1837,15 @@ develop = false celery = "*" configparser = "*" dateparser = "*" +importlib-metadata = "<5.0" lxml = "*" pytz = "*" [package.source] type = "git" url = "https://github.com/sartography/SpiffWorkflow" -reference = "feature/get-description-when-parsing-service-task" -resolved_reference = "e6d8478bcaf19ad90c13dc0a250513a6bfa90760" +reference = "main" +resolved_reference = "76947aa98d81826b88b2eefd05ebae4427b00e02" [[package]] name = "SQLAlchemy" @@ -2156,7 +2157,7 @@ testing = ["func-timeout", "jaraco.itertools", "pytest (>=6)", "pytest-black (>= [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "10b2edb09b9d220cd547527238bb49ff8fe01dd2406e85f0ff6fa2fbc9cca1ce" +content-hash = "7a3c07a2eef00685adbf44b6e26b740e20fc52bf85e916b6c171b13d4fcc6dc9" [metadata.files] alabaster = [ @@ -2521,8 +2522,8 @@ imagesize = [ {file = "imagesize-1.4.1.tar.gz", hash = "sha256:69150444affb9cb0d5cc5a92b3676f0b2fb7cd9ae39e947a5e11a36b4497cd4a"}, ] importlib-metadata = [ - {file = "importlib_metadata-5.0.0-py3-none-any.whl", hash = "sha256:ddb0e35065e8938f867ed4928d0ae5bf2a53b7773871bfe6bcc7e4fcdc7dea43"}, - {file = "importlib_metadata-5.0.0.tar.gz", hash = "sha256:da31db32b304314d044d3c12c79bd59e307889b287ad12ff387b3500835fc2ab"}, + {file = "importlib_metadata-4.13.0-py3-none-any.whl", hash = "sha256:8a8a81bcf996e74fee46f0d16bd3eaa382a7eb20fd82445c3ad11f4090334116"}, + {file = "importlib_metadata-4.13.0.tar.gz", hash = "sha256:dd0173e8f150d6815e098fd354f6414b0f079af4644ddfe90c71e2fc6174346d"}, ] inflection = [ {file = "inflection-0.5.1-py2.py3-none-any.whl", hash = "sha256:f38b2b640938a4f35ade69ac3d053042959b62a0f1076a5bbaa1b9526605a8a2"}, diff --git a/pyproject.toml b/pyproject.toml index e4ec038f..261da3f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ flask-migrate = "*" flask-restful = "*" werkzeug = "*" # go back to main once https://github.com/sartography/SpiffWorkflow/pull/241 is merged -SpiffWorkflow = {git = "https://github.com/sartography/SpiffWorkflow", rev = "feature/get-description-when-parsing-service-task"} +SpiffWorkflow = {git = "https://github.com/sartography/SpiffWorkflow", rev = "main"} # SpiffWorkflow = {develop = true, path = "/Users/kevin/projects/github/sartography/SpiffWorkflow"} # SpiffWorkflow = {develop = true, path = "/home/jason/projects/github/sartography/SpiffWorkflow"} sentry-sdk = "1.9.0"