First pass at git integration
This commit is contained in:
parent
54a04a38d9
commit
2cbe912a99
|
@ -445,6 +445,32 @@ paths:
|
|||
schema:
|
||||
$ref: "#/components/schemas/ProcessModel"
|
||||
|
||||
/process-models/{modified_process_model_identifier}/publish:
|
||||
parameters:
|
||||
- name: modified_process_model_identifier
|
||||
in: path
|
||||
required: true
|
||||
description: the modified process model id
|
||||
schema:
|
||||
type: string
|
||||
- name: branch_to_update
|
||||
in: query
|
||||
required: false
|
||||
description: the name of the branch we want to merge into
|
||||
schema:
|
||||
type: string
|
||||
put:
|
||||
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_model_publish
|
||||
summary: Merge changes from this model to another branch.
|
||||
tags:
|
||||
- Process Models
|
||||
responses:
|
||||
"200":
|
||||
description: The process model was published.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/OkTrue"
|
||||
|
||||
/processes:
|
||||
get:
|
||||
|
|
|
@ -57,3 +57,4 @@ SENTRY_TRACES_SAMPLE_RATE = environ.get(
|
|||
SPIFFWORKFLOW_BACKEND_LOG_LEVEL = environ.get(
|
||||
"SPIFFWORKFLOW_BACKEND_LOG_LEVEL", default="info"
|
||||
)
|
||||
GIT_MERGE_BRANCH = environ.get("GIT_MERGE_BRANCH", default="staging")
|
||||
|
|
|
@ -353,6 +353,17 @@ def process_model_move(
|
|||
return make_response(jsonify(new_process_model), 201)
|
||||
|
||||
|
||||
def process_model_publish(
|
||||
modified_process_model_identifier: str,
|
||||
branch_to_update: Optional[str] = None
|
||||
) -> flask.wrappers.Response:
|
||||
if branch_to_update is None:
|
||||
branch_to_update = current_app.config["GIT_MERGE_BRANCH"]
|
||||
process_model_identifier = un_modify_modified_process_model_id(modified_process_model_identifier)
|
||||
GitService().publish(process_model_identifier, branch_to_update)
|
||||
return Response(json.dumps({"ok": True}), status=200, mimetype="application/json")
|
||||
|
||||
|
||||
def process_model_list(
|
||||
process_group_identifier: Optional[str] = None,
|
||||
recursive: Optional[bool] = False,
|
||||
|
|
|
@ -29,7 +29,7 @@ class FileSystemService:
|
|||
# fixme: allow absolute files
|
||||
dir_name = current_app.config["BPMN_SPEC_ABSOLUTE_DIR"]
|
||||
app_root = current_app.root_path
|
||||
return os.path.join(app_root, "..", dir_name)
|
||||
return os.path.abspath(os.path.join(app_root, "..", dir_name))
|
||||
|
||||
@staticmethod
|
||||
def id_string_to_relative_path(id_string: str) -> str:
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
"""Git_service."""
|
||||
import datetime
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from flask import current_app
|
||||
from flask import g
|
||||
|
||||
from spiffworkflow_backend.models.process_model import ProcessModelInfo
|
||||
from spiffworkflow_backend.services.file_system_service import FileSystemService
|
||||
|
@ -54,3 +57,40 @@ class GitService:
|
|||
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
|
||||
|
||||
@staticmethod
|
||||
def publish(process_model_id, branch_to_update):
|
||||
source_process_model_root = FileSystemService.root_path()
|
||||
source_process_model_path = os.path.join(source_process_model_root, process_model_id)
|
||||
|
||||
# clone new instance of sample-process-models, checkout branch_to_update
|
||||
os.chdir("/tmp")
|
||||
destination_process_root = "/tmp/sample-process-models"
|
||||
if os.path.exists(destination_process_root):
|
||||
shutil.rmtree(destination_process_root)
|
||||
os.system("git clone https://github.com/sartography/sample-process-models.git")
|
||||
os.chdir(destination_process_root)
|
||||
|
||||
# create publish branch from branch_to_update
|
||||
os.system(f"git checkout {branch_to_update}") # noqa: S605
|
||||
publish_branch = f"publish-{process_model_id}"
|
||||
command = f"git show-ref --verify refs/remotes/origin/{publish_branch}"
|
||||
output = os.popen(command).read() # noqa: S605
|
||||
if output:
|
||||
os.system(f"git checkout {publish_branch}")
|
||||
else:
|
||||
os.system(f"git checkout -b {publish_branch}") # noqa: S605
|
||||
|
||||
# copy files from process model into the new publish branch
|
||||
destination_process_model_path = os.path.join(destination_process_root, process_model_id)
|
||||
if os.path.exists(destination_process_model_path):
|
||||
shutil.rmtree(destination_process_model_path)
|
||||
shutil.copytree(source_process_model_path, destination_process_model_path)
|
||||
|
||||
# add and commit files to publish_branch, then push
|
||||
os.chdir(destination_process_root)
|
||||
os.system("git add .") # noqa: S605
|
||||
commit_message = f"Request to publish changes to {process_model_id}, from {g.user.username}"
|
||||
os.system(f"git commit -m '{commit_message}'") # noqa: S605
|
||||
os.system("git push")
|
||||
print("publish")
|
||||
|
|
|
@ -203,6 +203,14 @@ export default function ProcessModelShow() {
|
|||
});
|
||||
};
|
||||
|
||||
const publishProcessModel = () => {
|
||||
HttpService.makeCallToBackend({
|
||||
path: `/process-models/${modifiedProcessModelId}/publish`,
|
||||
successCallback: navigateToProcessModels,
|
||||
httpMethod: 'PUT',
|
||||
});
|
||||
};
|
||||
|
||||
const navigateToFileEdit = (processModelFile: ProcessFile) => {
|
||||
const url = profileModelFileEditUrl(processModelFile);
|
||||
if (url) {
|
||||
|
@ -568,6 +576,9 @@ export default function ProcessModelShow() {
|
|||
<br />
|
||||
</>
|
||||
</Can>
|
||||
<div>
|
||||
<Button onClick={publishProcessModel}>Publish Changes</Button>
|
||||
</div>
|
||||
</Stack>
|
||||
{processInstanceRunResultTag()}
|
||||
{processModelFilesSection()}
|
||||
|
|
Loading…
Reference in New Issue