diff --git a/Makefile b/Makefile index e999b732..b094ea9c 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,11 @@ build: ## build hrp cli tool @echo "[info] build hrp cli tool" @. scripts/build.sh +.PHONY: install-hooks +install-hooks: ## install git hooks + @find scripts -name "install-*-hook" | awk -F'-' '{s=$$2;for(i=3;i StepResult: - return self.__step.run(runner) \ No newline at end of file + return self.__step.run(runner) diff --git a/httprunner/step_sql_request.py b/httprunner/step_sql_request.py index cc5ddfba..4b6fedc0 100644 --- a/httprunner/step_sql_request.py +++ b/httprunner/step_sql_request.py @@ -11,7 +11,11 @@ from httprunner.models import IStep, StepResult, TStep from httprunner.models import SqlMethodEnum, TSqlRequest from httprunner.response import SqlResponseObject from httprunner.runner import HttpRunner -from httprunner.step_request import (StepRequestExtraction, StepRequestValidation, call_hooks) +from httprunner.step_request import ( + StepRequestExtraction, + StepRequestValidation, + call_hooks, +) try: import sqlalchemy @@ -73,6 +77,7 @@ def run_step_sql_request(runner: HttpRunner, step: TStep) -> StepResult: if not runner.db_engine: ensure_sql_ready() from httprunner.database.engine import DBEngine + runner.db_engine = DBEngine( f'mysql+pymysql://{parsed_request_dict["db_config"]["user"]}:' f'{parsed_request_dict["db_config"]["password"]}@{parsed_request_dict["db_config"]["ip"]}:' diff --git a/httprunner/step_thrift_request.py b/httprunner/step_thrift_request.py index bef05448..ea7aadf7 100644 --- a/httprunner/step_thrift_request.py +++ b/httprunner/step_thrift_request.py @@ -66,30 +66,30 @@ def run_step_thrift_request(runner: HttpRunner, step: TStep) -> StepResult: parsed_request_dict["psm"] = parsed_request_dict["psm"] or config.thrift.psm parsed_request_dict["env"] = parsed_request_dict["env"] or config.thrift.env parsed_request_dict["cluster"] = ( - parsed_request_dict["cluster"] or config.thrift.cluster + parsed_request_dict["cluster"] or config.thrift.cluster ) parsed_request_dict["idl_path"] = ( - parsed_request_dict["idl_path"] or config.thrift.idl_path + parsed_request_dict["idl_path"] or config.thrift.idl_path ) parsed_request_dict["include_dirs"] = ( - parsed_request_dict["include_dirs"] or config.thrift.include_dirs + parsed_request_dict["include_dirs"] or config.thrift.include_dirs ) parsed_request_dict["method"] = ( - parsed_request_dict["method"] or config.thrift.method + parsed_request_dict["method"] or config.thrift.method ) parsed_request_dict["service_name"] = ( - parsed_request_dict["service_name"] or config.thrift.service_name + parsed_request_dict["service_name"] or config.thrift.service_name ) parsed_request_dict["ip"] = parsed_request_dict["ip"] or config.thrift.ip parsed_request_dict["port"] = parsed_request_dict["port"] or config.thrift.port parsed_request_dict["proto_type"] = ( - parsed_request_dict["proto_type"] or config.thrift.proto_type + parsed_request_dict["proto_type"] or config.thrift.proto_type ) parsed_request_dict["trans_port"] = ( - parsed_request_dict["trans_type"] or config.thrift.trans_type + parsed_request_dict["trans_type"] or config.thrift.trans_type ) parsed_request_dict["timeout"] = ( - parsed_request_dict["timeout"] or config.thrift.timeout + parsed_request_dict["timeout"] or config.thrift.timeout ) parsed_request_dict["thrift_client"] = parsed_request_dict["thrift_client"] @@ -105,6 +105,7 @@ def run_step_thrift_request(runner: HttpRunner, step: TStep) -> StepResult: if not runner.thrift_client: ensure_thrift_ready() from httprunner.thrift.thrift_client import ThriftClient + runner.thrift_client = ThriftClient( thrift_file=parsed_request_dict["idl_path"], service_name=parsed_request_dict["service_name"], @@ -214,7 +215,7 @@ class RunThriftRequest(IStep): return self def teardown_hook( - self, hook: Text, assign_var_name: Text = None + self, hook: Text, assign_var_name: Text = None ) -> "RunThriftRequest": if assign_var_name: self.__step.teardown_hooks.append({assign_var_name: hook}) @@ -224,7 +225,7 @@ class RunThriftRequest(IStep): return self def setup_hook( - self, hook: Text, assign_var_name: Text = None + self, hook: Text, assign_var_name: Text = None ) -> "RunThriftRequest": if assign_var_name: self.__step.setup_hooks.append({assign_var_name: hook}) @@ -247,7 +248,7 @@ class RunThriftRequest(IStep): return self def with_thrift_client( - self, thrift_client: Union["ThriftClient", str] + self, thrift_client: Union["ThriftClient", str] ) -> "RunThriftRequest": self.__step.thrift_request.thrift_client = thrift_client return self @@ -287,7 +288,7 @@ class RunThriftRequest(IStep): return StepThriftRequestValidation(self.__step) def with_jmespath( - self, jmes_path: Text, var_name: Text + self, jmes_path: Text, var_name: Text ) -> "StepThriftRequestExtraction": self.__step.extract[var_name] = jmes_path return StepThriftRequestExtraction(self.__step) diff --git a/scripts/install-pre-commit-hook b/scripts/install-pre-commit-hook new file mode 100644 index 00000000..6c47fa98 --- /dev/null +++ b/scripts/install-pre-commit-hook @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" +echo "SCRIPT_DIR:, $SCRIPT_DIR" +# assume the script is always in /scripts +pushd "$SCRIPT_DIR/.." >/dev/null + +PRE_COMMIT_FILE=.git/hooks/pre-commit + +# install pre-commit hook and make it executable +function install() { + go get mvdan.cc/gofumpt + go get github.com/incu6us/goimports-reviser/v2@latest + cat > $PRE_COMMIT_FILE <<'EOF' +#!/bin/bash + +# What does this script do? +# 1. gofumpt go files automatically +# 2. goimports-reviser go files automatically +# 3. black python files automatically + +# make sure gofumpt is installed +# What does each letter mean in "ACMRTUXB"? +# Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, +# submodule, ...) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B) +for file in $(git diff --name-only --cached --diff-filter=ACMRTUXB | grep '.go$') +do + echo "(gofumpt) $file" + gofumpt -w "$file" + echo "(goimports-reviser) $file" + goimports-reviser -file-path "$file" -rm-unused + git add "$file" +done + +for file in $(git diff --name-only --cached --diff-filter=ACMRTUXB | grep '.py$') +do + echo "(black) $file" + black "$file" + git add "$file" +done +EOF + + chmod +x $PRE_COMMIT_FILE +} + +if [[ -f $PRE_COMMIT_FILE ]]; then + echo "Backing up $PRE_COMMIT_FILE to ${PRE_COMMIT_FILE}.bak" + mv $PRE_COMMIT_FILE ${PRE_COMMIT_FILE}.bak + install +else + install +fi + +popd >/dev/null \ No newline at end of file