Skip to content

Commit

Permalink
feat: Link flag and component names in PR comment back to dashboard p…
Browse files Browse the repository at this point in the history
…ages
  • Loading branch information
scott-codecov committed Aug 14, 2023
1 parent 319753b commit 307efa8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 44 deletions.
10 changes: 8 additions & 2 deletions services/notification/notifiers/mixins/message/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,10 @@ async def do_write_section(self, comparison, diff, changes, links, behind_by=Non

yield (
"| {name} {metrics}{cf}".format(
name=flag["name"],
name="[{flag_name}]({href}/flags?src=pr&el=flag)".format(
flag_name=flag["name"],
href=links["pull"],
),
metrics=make_metrics(
flag["before"],
flag["after"],
Expand Down Expand Up @@ -727,7 +730,10 @@ async def do_write_section(
for component_data in component_data_to_show:
yield (
"| {name} {metrics}".format(
name=component_data["name"],
name="[{component_name}]({href}/components?src=pr&el=component)".format(
component_name=component_data["name"],
href=links["pull"],
),
metrics=make_metrics(
component_data["before"],
component_data["after"],
Expand Down
84 changes: 42 additions & 42 deletions services/notification/notifiers/tests/unit/test_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,8 @@ async def test_build_message(
f"",
f"| Flag | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
f"| integration | `?` | `?` | |",
f"| unit | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"| [integration](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `?` | `?` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
f"",
Expand Down Expand Up @@ -967,14 +967,14 @@ async def test_build_message_flags_empty_coverage(
f"",
"| Flag | Coverage Δ | |",
"|---|---|---|",
"| eighth | `?` | |",
"| fifth | `∅ <ø> (?)` | |",
"| first | `100.00% <ø> (ø)` | |",
"| fourth | `∅ <ø> (∅)` | |",
"| second | `50.00% <ø> (∅)` | |",
"| seventh | `?` | |",
"| sixth | `100.00% <ø> (?)` | |",
"| third | `∅ <ø> (∅)` | |",
f"| [eighth](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `?` | |",
f"| [fifth](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `∅ <ø> (?)` | |",
f"| [first](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <ø> (ø)` | |",
f"| [fourth](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `∅ <ø> (∅)` | |",
f"| [second](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `50.00% <ø> (∅)` | |",
f"| [seventh](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `?` | |",
f"| [sixth](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <ø> (?)` | |",
f"| [third](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `∅ <ø> (∅)` | |",
"",
"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
"",
Expand Down Expand Up @@ -1038,8 +1038,8 @@ async def test_build_message_more_sections(
f"",
f"| Flag | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
f"| integration | `?` | `?` | |",
f"| unit | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"| [integration](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `?` | `?` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
f"",
Expand Down Expand Up @@ -1303,8 +1303,8 @@ async def test_build_message_hide_complexity(
f"",
f"| Flag | Coverage Δ | |",
f"|---|---|---|",
f"| integration | `?` | |",
f"| unit | `100.00% <100.00%> (?)` | |",
f"| [integration](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `?` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <100.00%> (?)` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
f"",
Expand Down Expand Up @@ -1377,7 +1377,7 @@ async def test_build_message_no_base_report(
f"",
f"| Flag | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
f"| unit | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
f"",
Expand Down Expand Up @@ -1448,7 +1448,7 @@ async def test_build_message_no_base_commit(
f"",
f"| Flag | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
f"| unit | `100.00% <0.00%> (?)` | `0.00% <0.00%> (?%)` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <0.00%> (?)` | `0.00% <0.00%> (?%)` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
f"",
Expand Down Expand Up @@ -1518,7 +1518,7 @@ async def test_build_message_no_change(
f"",
f"| Flag | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
f"| unit | `100.00% <100.00%> (ø)` | `0.00 <0.00> (ø)` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <100.00%> (ø)` | `0.00 <0.00> (ø)` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
f"",
Expand Down Expand Up @@ -1593,8 +1593,8 @@ async def test_build_message_negative_change(
f"",
f"| Flag | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
f"| integration | `100.00% <ø> (?)` | `0.00 <ø> (?)` | |",
f"| unit | `?` | `?` | |",
f"| [integration](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <ø> (?)` | `0.00 <ø> (?)` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `?` | `?` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
f"",
Expand Down Expand Up @@ -1788,8 +1788,8 @@ async def test_build_message_show_carriedforward_flags_no_cf_coverage(
f"",
f"| Flag | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
f"| integration | `?` | `?` | |",
f"| unit | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"| [integration](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `?` | `?` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"",
f"| [Files Changed](test.example.br/gh/{repository.slug}/pull/{pull.pullid}?src=pr&el=tree) | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
Expand Down Expand Up @@ -1922,9 +1922,9 @@ async def test_build_message_with_without_flags(
f"",
f"| Flag | Coverage Δ | | *Carryforward flag |",
f"|---|---|---|---|",
f"| enterprise | `25.00% <ø> (ø)` | | Carriedforward from [1234567](test.example.br/gh/{repository.slug}/commit/123456789sha) |",
f"| integration | `25.00% <ø> (ø)` | | Carriedforward |",
f"| unit | `25.00% <ø> (ø)` | | |",
f"| [enterprise](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `25.00% <ø> (ø)` | | Carriedforward from [1234567](test.example.br/gh/{repository.slug}/commit/123456789sha) |",
f"| [integration](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `25.00% <ø> (ø)` | | Carriedforward |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `25.00% <ø> (ø)` | | |",
f"",
f"*This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags) to find out more."
f"",
Expand Down Expand Up @@ -1998,9 +1998,9 @@ async def test_build_message_show_carriedforward_flags_has_cf_coverage(
f"",
f"| Flag | Coverage Δ | | *Carryforward flag |",
f"|---|---|---|---|",
f"| enterprise | `25.00% <ø> (ø)` | | Carriedforward from [1234567](test.example.br/gh/{repository.slug}/commit/123456789sha) |",
f"| integration | `25.00% <ø> (ø)` | | Carriedforward |",
f"| unit | `25.00% <ø> (ø)` | | |",
f"| [enterprise](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `25.00% <ø> (ø)` | | Carriedforward from [1234567](test.example.br/gh/{repository.slug}/commit/123456789sha) |",
f"| [integration](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `25.00% <ø> (ø)` | | Carriedforward |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `25.00% <ø> (ø)` | | |",
f"",
f"*This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags) to find out more."
f"",
Expand Down Expand Up @@ -2074,7 +2074,7 @@ async def test_build_message_hide_carriedforward_flags_has_cf_coverage(
f"",
f"| Flag | Coverage Δ | |",
f"|---|---|---|",
f"| unit | `25.00% <ø> (ø)` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `25.00% <ø> (ø)` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more."
f"",
Expand Down Expand Up @@ -2177,7 +2177,7 @@ async def test_build_message_no_flags(
f"",
f"| Flag | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
f"| integration | `?` | `?` | |",
f"| [integration](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `?` | `?` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
f"",
Expand Down Expand Up @@ -4051,7 +4051,7 @@ async def test_build_message_no_base_commit_new_layout(
f"",
f"| Flag | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
f"| unit | `100.00% <0.00%> (?)` | `0.00% <0.00%> (?%)` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <0.00%> (?)` | `0.00% <0.00%> (?%)` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
f"",
Expand Down Expand Up @@ -4117,7 +4117,7 @@ async def test_build_message_no_base_report_new_layout(
f"",
f"| Flag | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
f"| unit | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
f"",
Expand Down Expand Up @@ -4231,8 +4231,8 @@ async def test_build_message_head_and_pull_head_differ_new_layout(
f"",
f"| Flag | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
f"| integration | `?` | `?` | |",
f"| unit | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"| [integration](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `?` | `?` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
f"",
Expand Down Expand Up @@ -4306,15 +4306,15 @@ async def test_build_message_head_and_pull_head_differ_with_components(
f"",
f"| Flag | Coverage Δ | Complexity Δ | |",
f"|---|---|---|---|",
f"| integration | `?` | `?` | |",
f"| unit | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"| [integration](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `?` | `?` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `100.00% <100.00%> (?)` | `0.00 <0.00> (?)` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.",
f"",
f"| Components | Coverage Δ | |",
f"|---|---|---|",
f"| go_files | `62.50% <66.67%> (+12.50%)` | :arrow_up: |",
f"| unit_flags | `100.00% <100.00%> (∅)` | |",
f"| [go_files](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/components?src=pr&el=component) | `62.50% <66.67%> (+12.50%)` | :arrow_up: |",
f"| [unit_flags](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/components?src=pr&el=component) | `100.00% <100.00%> (∅)` | |",
f"",
f"</details>",
f"",
Expand Down Expand Up @@ -4371,7 +4371,7 @@ async def test_build_message_no_patch_or_proj_change(
f"",
f"| Flag | Coverage Δ | |",
f"|---|---|---|",
f"| unit | `25.00% <ø> (ø)` | |",
f"| [unit](test.example.br/gh/{repository.slug}/pull/{pull.pullid}/flags?src=pr&el=flag) | `25.00% <ø> (ø)` | |",
f"",
f"Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more."
f"",
Expand Down Expand Up @@ -4653,8 +4653,8 @@ async def test_write_message_component_section(
expected = [
"| Components | Coverage Δ | |",
"|---|---|---|",
"| go_files | `62.50% <66.67%> (+12.50%)` | :arrow_up: |",
"| py_files | `50.00% <ø> (ø)` | |",
"| [go_files](urlurl/components?src=pr&el=component) | `62.50% <66.67%> (+12.50%)` | :arrow_up: |",
"| [py_files](urlurl/components?src=pr&el=component) | `50.00% <ø> (ø)` | |",
]
assert message == expected

Expand Down Expand Up @@ -4689,7 +4689,7 @@ async def test_write_message_component_section_no_base(
expected = [
"| Components | Coverage Δ | |",
"|---|---|---|",
"| go_files | `62.50% <0.00%> (?)` | |",
"| py_files | `50.00% <0.00%> (?)` | |",
"| [go_files](urlurl/components?src=pr&el=component) | `62.50% <0.00%> (?)` | |",
"| [py_files](urlurl/components?src=pr&el=component) | `50.00% <0.00%> (?)` | |",
]
assert message == expected

0 comments on commit 307efa8

Please sign in to comment.