Merge remote-tracking branch 'origin/main' into update_imports

This commit is contained in:
burnettk 2022-10-04 17:26:05 -04:00
commit ac87a6384c
8 changed files with 80 additions and 9 deletions

36
bin/git_commit_bpmn_models_repo Executable file
View File

@ -0,0 +1,36 @@
#!/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"
git_commit_username="$3"
git_commit_email="$4"
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
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

15
poetry.lock generated
View File

@ -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"},

View File

@ -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"

View File

@ -23,6 +23,8 @@ 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")

View File

@ -1 +1,4 @@
"""Staging."""
GIT_COMMIT_ON_SAVE = True
GIT_COMMIT_USERNAME = "staging"
GIT_COMMIT_EMAIL = "staging@example.com"

View File

@ -270,6 +270,15 @@ def process_model_file_update(
)
SpecFileService.update_file(process_model, file_name, request_file_contents)
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")

View File

@ -38,3 +38,18 @@ 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"]
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}' '{git_username}' '{git_email}'"
)
output = os.popen(shell_command).read() # noqa: S605
return output

View File

@ -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: