Skip to content

Commit 950dcff

Browse files
authored
Feat: improve cicd comment message format (#2747)
1 parent 638e7cb commit 950dcff

File tree

4 files changed

+73
-49
lines changed

4 files changed

+73
-49
lines changed

sqlmesh/integrations/github/cicd/controller.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def pull_request_comment_body(self) -> t.Optional[str]:
279279

280280

281281
class GithubController:
282-
BOT_HEADER_MSG = "**SQLMesh Bot Info**"
282+
BOT_HEADER_MSG = ":robot: **SQLMesh Bot Info** :robot:"
283283
MAX_BYTE_LENGTH = 65535
284284

285285
def __init__(
@@ -565,7 +565,7 @@ def deploy_to_prod(self) -> None:
565565
"Please check PR and resolve any issues."
566566
)
567567
plan_summary = f"""<details>
568-
<summary>Prod Plan Being Applied</summary>
568+
<summary>:ship: Prod Plan Being Applied</summary>
569569
570570
{self.get_plan_summary(self.prod_plan)}
571571
</details>
@@ -814,9 +814,16 @@ def conclusion_handler(
814814
table_header = h("thead", [h("tr", row) for row in header_rows])
815815
table_body = h("tbody", [h("tr", row) for row in body_rows])
816816
summary = str(h("table", [table_header, table_body]))
817+
vde_title = (
818+
"- :eyes: To **review** this PR's changes, use virtual data environment:"
819+
)
820+
comment_value = f"{vde_title}\n - `{self.pr_environment_name}`"
821+
if self.bot_config.enable_deploy_command:
822+
comment_value += "\n- :arrow_forward: To apply this PR's plan to prod, comment:\n - `/deploy`"
823+
dedup_regex = vde_title.replace("*", r"\*") + r".*"
817824
updated_comment, _ = self.update_sqlmesh_comment_info(
818-
value=f"- {check_title}",
819-
dedup_regex=rf"- {check_title_static}.*",
825+
value=comment_value,
826+
dedup_regex=dedup_regex,
820827
)
821828
if updated_comment:
822829
self._append_output("created_pr_environment", "true")

tests/integrations/github/cicd/test_github_commands.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ def test_run_all_success_with_approvers_approved(
138138

139139
assert len(created_comments) == 1
140140
assert created_comments[0].body.startswith(
141-
"""**SQLMesh Bot Info**
142-
- PR Virtual Data Environment: myoverride_2
141+
""":robot: **SQLMesh Bot Info** :robot:
142+
- :eyes: To **review** this PR's changes, use virtual data environment:
143+
- `myoverride_2`
143144
<details>
144-
<summary>Prod Plan Being Applied</summary>
145+
<summary>:ship: Prod Plan Being Applied</summary>
145146
146147
**New environment `prod` will be created from `prod`**"""
147148
)
@@ -264,10 +265,11 @@ def test_run_all_success_with_approvers_approved_merge_delete(
264265

265266
assert len(created_comments) == 1
266267
assert created_comments[0].body.startswith(
267-
"""**SQLMesh Bot Info**
268-
- PR Virtual Data Environment: hello_world_2
268+
""":robot: **SQLMesh Bot Info** :robot:
269+
- :eyes: To **review** this PR's changes, use virtual data environment:
270+
- `hello_world_2`
269271
<details>
270-
<summary>Prod Plan Being Applied</summary>
272+
<summary>:ship: Prod Plan Being Applied</summary>
271273
272274
**New environment `prod` will be created from `prod`**"""
273275
)
@@ -390,7 +392,9 @@ def test_run_all_missing_approval(
390392
assert len(created_comments) == 1
391393
assert (
392394
created_comments[0].body
393-
== """**SQLMesh Bot Info**\n- PR Virtual Data Environment: hello_world_2"""
395+
== """:robot: **SQLMesh Bot Info** :robot:
396+
- :eyes: To **review** this PR's changes, use virtual data environment:
397+
- `hello_world_2`"""
394398
)
395399
with open(github_output_file, "r", encoding="utf-8") as f:
396400
output = f.read()
@@ -902,10 +906,11 @@ def raise_on_prod_plan(plan: Plan):
902906

903907
assert len(created_comments) == 1
904908
assert created_comments[0].body.startswith(
905-
"""**SQLMesh Bot Info**
906-
- PR Virtual Data Environment: hello_world_2
909+
""":robot: **SQLMesh Bot Info** :robot:
910+
- :eyes: To **review** this PR's changes, use virtual data environment:
911+
- `hello_world_2`
907912
<details>
908-
<summary>Prod Plan Being Applied</summary>
913+
<summary>:ship: Prod Plan Being Applied</summary>
909914
910915
**New environment `prod` will be created from `prod`**"""
911916
)
@@ -1095,10 +1100,13 @@ def test_comment_command_deploy_prod(
10951100

10961101
assert len(created_comments) == 1
10971102
assert created_comments[0].body.startswith(
1098-
"""**SQLMesh Bot Info**
1099-
- PR Virtual Data Environment: hello_world_2
1103+
""":robot: **SQLMesh Bot Info** :robot:
1104+
- :eyes: To **review** this PR's changes, use virtual data environment:
1105+
- `hello_world_2`
1106+
- :arrow_forward: To apply this PR's plan to prod, comment:
1107+
- `/deploy`
11001108
<details>
1101-
<summary>Prod Plan Being Applied</summary>
1109+
<summary>:ship: Prod Plan Being Applied</summary>
11021110
11031111
**New environment `prod` will be created from `prod`**"""
11041112
)

tests/integrations/github/cicd/test_github_controller.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ def test_run_tests(github_client, make_controller):
317317
[],
318318
"test1",
319319
None,
320-
"**SQLMesh Bot Info**\ntest1",
321-
"**SQLMesh Bot Info**\ntest1",
320+
":robot: **SQLMesh Bot Info** :robot:\ntest1",
321+
":robot: **SQLMesh Bot Info** :robot:\ntest1",
322322
),
323323
(
324324
"Existing comments that are not related, one is created and then updated with value",
@@ -328,43 +328,43 @@ def test_run_tests(github_client, make_controller):
328328
],
329329
"test1",
330330
None,
331-
"**SQLMesh Bot Info**\ntest1",
332-
"**SQLMesh Bot Info**\ntest1",
331+
":robot: **SQLMesh Bot Info** :robot:\ntest1",
332+
":robot: **SQLMesh Bot Info** :robot:\ntest1",
333333
),
334334
(
335335
"Existing bot comment, that is updated and create comment is not called",
336336
[
337-
MockIssueComment(body="**SQLMesh Bot Info**\ntest2"),
337+
MockIssueComment(body=":robot: **SQLMesh Bot Info** :robot:\ntest2"),
338338
MockIssueComment(body="test3"),
339339
],
340340
"test1",
341341
None,
342-
"**SQLMesh Bot Info**\ntest2\ntest1",
342+
":robot: **SQLMesh Bot Info** :robot:\ntest2\ntest1",
343343
None,
344344
),
345345
(
346346
"Existing bot comment, that is not updated because of dedup_regex and create comment is not called",
347347
[
348-
MockIssueComment(body="**SQLMesh Bot Info**\ntest2"),
348+
MockIssueComment(body=":robot: **SQLMesh Bot Info** :robot:\ntest2"),
349349
MockIssueComment(body="test3"),
350350
],
351351
"test1",
352352
"test2",
353-
"**SQLMesh Bot Info**\ntest2",
353+
":robot: **SQLMesh Bot Info** :robot:\ntest2",
354354
None,
355355
),
356356
(
357357
"Ensure comments are truncated if they are too long",
358358
[
359-
MockIssueComment(body="**SQLMesh Bot Info**\ntest1"),
359+
MockIssueComment(body=":robot: **SQLMesh Bot Info** :robot:\ntest1"),
360360
],
361361
# Making sure that although we will be under the character limit of `65535` we will still truncate
362362
# because the byte size of this character is 3 and therefore we will be over the limit since it is based
363363
# on bytes on not characters (despite what the error message may say)
364364
"桜" * 65000,
365365
None,
366-
# ((Max Byte Length) - (Length of "**SQLMesh Bot Info**\ntest1\n")) / (Length of "桜")
367-
"**SQLMesh Bot Info**\ntest1\n" + ("桜" * int((65535 - 27) / 3)),
366+
# ((Max Byte Length) - (Length of ":robot: **SQLMesh Bot Info** :robot:\ntest1\n")) / (Length of "桜")
367+
":robot: **SQLMesh Bot Info** :robot:\ntest1\n" + ("桜" * int((65535 - 43) / 3)),
368368
None,
369369
),
370370
]

tests/integrations/github/cicd/test_integration.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ def test_merge_pr_has_non_breaking_change(
227227
assert len(created_comments) == 1
228228
assert (
229229
created_comments[0].body
230-
== f"""**SQLMesh Bot Info**
231-
- PR Virtual Data Environment: hello_world_2
230+
== f""":robot: **SQLMesh Bot Info** :robot:
231+
- :eyes: To **review** this PR's changes, use virtual data environment:
232+
- `hello_world_2`
232233
<details>
233-
<summary>Prod Plan Being Applied</summary>
234+
<summary>:ship: Prod Plan Being Applied</summary>
234235
235236
{expected_prod_plan_summary}
236237
</details>
@@ -425,10 +426,11 @@ def test_merge_pr_has_non_breaking_change_diff_start(
425426
assert len(created_comments) == 1
426427
assert (
427428
created_comments[0].body
428-
== f"""**SQLMesh Bot Info**
429-
- PR Virtual Data Environment: hello_world_2
429+
== f""":robot: **SQLMesh Bot Info** :robot:
430+
- :eyes: To **review** this PR's changes, use virtual data environment:
431+
- `hello_world_2`
430432
<details>
431-
<summary>Prod Plan Being Applied</summary>
433+
<summary>:ship: Prod Plan Being Applied</summary>
432434
433435
{expected_prod_plan}
434436
</details>
@@ -735,9 +737,9 @@ def test_merge_pr_has_no_changes(
735737
assert len(created_comments) == 1
736738
assert (
737739
created_comments[0].body
738-
== f"""**SQLMesh Bot Info**
740+
== f""":robot: **SQLMesh Bot Info** :robot:
739741
<details>
740-
<summary>Prod Plan Being Applied</summary>
742+
<summary>:ship: Prod Plan Being Applied</summary>
741743
742744
{expected_prod_plan_summary}
743745
</details>
@@ -921,8 +923,9 @@ def test_no_merge_since_no_deploy_signal(
921923
assert len(created_comments) == 1
922924
assert (
923925
created_comments[0].body
924-
== """**SQLMesh Bot Info**
925-
- PR Virtual Data Environment: hello_world_2"""
926+
== """:robot: **SQLMesh Bot Info** :robot:
927+
- :eyes: To **review** this PR's changes, use virtual data environment:
928+
- `hello_world_2`"""
926929
)
927930

928931
with open(github_output_file, "r", encoding="utf-8") as f:
@@ -1080,8 +1083,9 @@ def test_no_merge_since_no_deploy_signal_no_approvers_defined(
10801083
assert len(created_comments) == 1
10811084
assert (
10821085
created_comments[0].body
1083-
== """**SQLMesh Bot Info**
1084-
- PR Virtual Data Environment: hello_world_2"""
1086+
== """:robot: **SQLMesh Bot Info** :robot:
1087+
- :eyes: To **review** this PR's changes, use virtual data environment:
1088+
- `hello_world_2`"""
10851089
)
10861090

10871091
with open(github_output_file, "r", encoding="utf-8") as f:
@@ -1257,10 +1261,13 @@ def test_deploy_comment_pre_categorized(
12571261
assert len(created_comments) == 1
12581262
assert (
12591263
created_comments[0].body
1260-
== f"""**SQLMesh Bot Info**
1261-
- PR Virtual Data Environment: hello_world_2
1264+
== f""":robot: **SQLMesh Bot Info** :robot:
1265+
- :eyes: To **review** this PR's changes, use virtual data environment:
1266+
- `hello_world_2`
1267+
- :arrow_forward: To apply this PR's plan to prod, comment:
1268+
- `/deploy`
12621269
<details>
1263-
<summary>Prod Plan Being Applied</summary>
1270+
<summary>:ship: Prod Plan Being Applied</summary>
12641271
12651272
{expected_prod_plan}
12661273
</details>
@@ -1613,10 +1620,11 @@ def test_overlapping_changes_models(
16131620
assert len(created_comments) == 1
16141621
assert (
16151622
created_comments[0].body
1616-
== f"""**SQLMesh Bot Info**
1617-
- PR Virtual Data Environment: hello_world_2
1623+
== f""":robot: **SQLMesh Bot Info** :robot:
1624+
- :eyes: To **review** this PR's changes, use virtual data environment:
1625+
- `hello_world_2`
16181626
<details>
1619-
<summary>Prod Plan Being Applied</summary>
1627+
<summary>:ship: Prod Plan Being Applied</summary>
16201628
16211629
{expected_prod_plan_summary}
16221630
</details>
@@ -1791,10 +1799,11 @@ def test_pr_delete_model(
17911799
assert len(created_comments) == 1
17921800
assert (
17931801
created_comments[0].body
1794-
== f"""**SQLMesh Bot Info**
1795-
- PR Virtual Data Environment: hello_world_2
1802+
== f""":robot: **SQLMesh Bot Info** :robot:
1803+
- :eyes: To **review** this PR's changes, use virtual data environment:
1804+
- `hello_world_2`
17961805
<details>
1797-
<summary>Prod Plan Being Applied</summary>
1806+
<summary>:ship: Prod Plan Being Applied</summary>
17981807
17991808
{expected_prod_plan_summary}
18001809
</details>

0 commit comments

Comments
 (0)