Skip to content

Commit 07b68d1

Browse files
committed
bugfixes and changes
1 parent 5b4daf7 commit 07b68d1

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

patchwork/steps/CallSQL/CallSQL.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,33 @@
33
from sqlalchemy import URL, create_engine, exc, text
44

55
from patchwork.common.utils.utils import mustache_render
6+
from patchwork.logger import logger
67
from patchwork.step import Step, StepStatus
78
from patchwork.steps.CallSQL.typed import CallSQLInputs, CallSQLOutputs
89

910

1011
class CallSQL(Step, input_class=CallSQLInputs, output_class=CallSQLOutputs):
1112
def __init__(self, inputs: dict):
1213
super().__init__(inputs)
13-
query_template_data = inputs.get("query_template_values", {})
14-
self.query = mustache_render(inputs["query"], query_template_data)
14+
query_template_data = inputs.get("db_query_template_values", {})
15+
self.query = mustache_render(inputs["db_query"], query_template_data)
1516
self.__build_engine(inputs)
1617

1718
def __build_engine(self, inputs: dict):
18-
dialect = inputs["dialect"]
19-
driver = inputs.get("driver")
19+
dialect = inputs["db_dialect"]
20+
driver = inputs.get("db_driver")
2021
dialect_plus_driver = f"{dialect}+{driver}" if driver is not None else dialect
2122
kwargs = dict(
22-
username=inputs["username"],
23-
host=inputs.get("host", "localhost"),
24-
port=inputs.get("port", 5432),
23+
username=inputs["db_username"],
24+
host=inputs.get("db_host", "localhost"),
25+
port=inputs.get("db_port", 5432),
2526
)
26-
if inputs.get("password") is not None:
27-
kwargs["password"] = inputs.get("password")
27+
if inputs.get("db_password") is not None:
28+
kwargs["password"] = inputs.get("db_password")
29+
if inputs.get("db_name") is not None:
30+
kwargs["database"] = inputs.get("db_name")
31+
if inputs.get("db_params") is not None:
32+
kwargs["query"] = inputs.get("db_params")
2833
connection_url = URL.create(
2934
dialect_plus_driver,
3035
**kwargs,
@@ -36,10 +41,14 @@ def __build_engine(self, inputs: dict):
3641

3742
def run(self) -> dict:
3843
try:
44+
rv = []
3945
with self.engine.begin() as conn:
4046
cursor = conn.execute(text(self.query))
41-
result = cursor.fetchall()
42-
return dict(result=result)
47+
for row in cursor:
48+
result = row._asdict()
49+
rv.append(result)
50+
logger.info(f"Retrieved {len(rv)} rows!")
51+
return dict(results=rv)
4352
except exc.InvalidRequestError as e:
4453
self.set_status(StepStatus.FAILED, f"`{self.query}` failed with message:\n{e}")
45-
return dict(result=[])
54+
return dict(results=[])

patchwork/steps/CallSQL/typed.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55

66
class __RequiredCallSQLInputs(TypedDict):
7-
dialect: str
8-
username: str
9-
query: str
7+
db_dialect: str
8+
db_username: str
9+
db_query: str
1010

1111

1212
class CallSQLInputs(__RequiredCallSQLInputs, total=False):
13-
driver: str
14-
password: str
15-
host: str
16-
port: int
17-
database: str
18-
query_template_values: dict[str, Any]
13+
db_driver: str
14+
db_password: str
15+
db_host: str
16+
db_port: int
17+
db_name: str
18+
db_query_template_values: dict[str, Any]
1919

2020

2121
class CallSQLOutputs(TypedDict):
22-
result: list[dict[str, Any]]
22+
results: list[dict[str, Any]]

patchwork/steps/CallShell/CallShell.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def run(self) -> dict:
5151
except subprocess.CalledProcessError as e:
5252
self.set_status(
5353
StepStatus.FAILED,
54-
f"script failed with stdout:\n{p.stdout}\nstderr:\n{e.stderr}",
54+
f"Script failed.",
5555
)
56+
logger.info(f"stdout: \n{p.stdout}")
57+
logger.info(f"stderr:\n{p.stderr}")
5658
return dict(stdout_output=p.stdout, stderr_output=p.stderr)

patchwork/steps/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
"ReadPRDiffs",
9696
"ReadPRDiffsPB",
9797
"ReadPRs",
98-
"ResolveIssue",
9998
"ScanDepscan",
10099
"ScanSemgrep",
101100
"ScanSonar",

0 commit comments

Comments
 (0)