Skip to content

Commit 7e96460

Browse files
committed
bump and record outputs
1 parent c180272 commit 7e96460

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

patchwork/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,10 @@ def cli(
238238
if not disable_telemetry:
239239
patched.send_public_telemetry(patchflow_name, inputs)
240240

241-
with patched.patched_telemetry(patchflow_name, {}):
241+
with patched.patched_telemetry(patchflow_name, {}) as output_dict:
242242
patchflow_instance = patchflow_class(inputs)
243-
patchflow_instance.run()
243+
patchflow_output = patchflow_instance.run()
244+
output_dict.update(patchflow_output)
244245
except Exception as e:
245246
logger.debug(traceback.format_exc())
246247
logger.error(f"Error running patchflow {patchflow}: {e}")

patchwork/common/client/patched.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ class PatchedClient(click.ParamType):
7676
ALLOWED_TELEMETRY_KEYS = {
7777
"model",
7878
}
79+
ALLOWED_TELEMETRY_OUTPUT_KEYS = {
80+
"pr_url",
81+
"issue_url",
82+
}
7983

8084
def __init__(self, access_token: str, url: str = DEFAULT_PATCH_URL):
8185
self.access_token = access_token
@@ -140,6 +144,15 @@ def __handle_telemetry_inputs(self, inputs: dict[str, Any]) -> dict:
140144

141145
return inputs_copy
142146

147+
def __handle_telemetry_outputs(self, outputs: dict[str, Any]) -> dict:
148+
diff_keys = set(outputs.keys()).difference(self.ALLOWED_TELEMETRY_KEYS)
149+
150+
outputs_copy = outputs.copy()
151+
for key in diff_keys:
152+
del outputs_copy[key]
153+
154+
return outputs_copy
155+
143156
async def _public_telemetry(self, patchflow: str, inputs: dict[str, Any]):
144157
user_config = get_user_config()
145158
requests.post(
@@ -169,38 +182,42 @@ def send_public_telemetry(self, patchflow: str, inputs: dict):
169182

170183
@contextlib.contextmanager
171184
def patched_telemetry(self, patchflow: str, inputs: dict):
185+
outputs = dict()
186+
172187
if not self.access_token:
173-
yield
188+
yield outputs
174189
return
175190

176191
try:
177192
is_valid_client = self.test_token()
178193
except Exception as e:
179194
logger.error(f"Access Token test failed: {e}")
180-
yield
195+
yield outputs
181196
return
182197

183198
if not is_valid_client:
184-
yield
199+
yield outputs
185200
return
186201

187202
try:
188203
repo = Repo(Path.cwd(), search_parent_directories=True)
189204
patchflow_run_id = self.record_patchflow_run(patchflow, repo, self.__handle_telemetry_inputs(inputs))
190205
except Exception as e:
191206
logger.error(f"Failed to record patchflow run: {e}")
192-
yield
207+
yield outputs
193208
return
194209

195210
if patchflow_run_id is None:
196-
yield
211+
yield outputs
197212
return
198213

199214
try:
200-
yield
215+
yield outputs
201216
finally:
202217
try:
203-
self.finish_record_patchflow_run(patchflow_run_id, patchflow, repo)
218+
self.finish_record_patchflow_run(
219+
patchflow_run_id, patchflow, repo, self.__handle_telemetry_outputs(outputs)
220+
)
204221
except Exception as e:
205222
logger.error(f"Failed to finish patchflow run: {e}")
206223

@@ -222,16 +239,17 @@ def record_patchflow_run(self, patchflow: str, repo: Repo, inputs: dict) -> int
222239
return None
223240

224241
logger.debug(f"Patchflow run recorded for {patchflow}")
225-
return response.json()["id"]
242+
return response.json().get("id")
226243

227-
def finish_record_patchflow_run(self, id: int, patchflow: str, repo: Repo) -> None:
244+
def finish_record_patchflow_run(self, id: int, patchflow: str, repo: Repo, outputs: dict) -> None:
228245
response = self._post(
229246
url=self.url + "/v1/patchwork/",
230247
headers={"Authorization": f"Bearer {self.access_token}"},
231248
json={
232249
"id": id,
233250
"url": repo.remotes.origin.url,
234251
"patchflow": patchflow,
252+
"outputs": outputs
235253
},
236254
)
237255

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "patchwork-cli"
3-
version = "0.0.84.dev1"
3+
version = "0.0.84.dev2"
44
description = ""
55
authors = ["patched.codes"]
66
license = "AGPL"

0 commit comments

Comments
 (0)