dev vouch dev on at. thats about it atvouch.dev
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

tweak comment style

authored by

Luna and committed by tangled.org 617885d8 0df90a8b

+28 -35
+13 -19
appview/lib/atvouch/tangled/comment_builder.ex
··· 13 13 `handle_map` is a `%{did => handle}` map used to resolve DIDs in route paths 14 14 to display names with bsky.app links. 15 15 """ 16 - def build_comment(author_did, author_handle, maintainer_routes, handle_map \\ %{}) do 17 - author_display = display_name_link(author_did, author_handle) 18 - header = "## atvouch routes for #{author_display}\n" 19 - 20 - body = 16 + def build_comment(_author_did, _author_handle, maintainer_routes, handle_map \\ %{}) do 17 + lines = 21 18 maintainer_routes 22 - |> Enum.map(fn {maintainer_did, maintainer_handle, route_result} -> 23 - format_maintainer_routes(maintainer_did, maintainer_handle, route_result, handle_map) 19 + |> Enum.flat_map(fn {maintainer_did, maintainer_handle, route_result} -> 20 + format_route_lines(maintainer_did, maintainer_handle, route_result, handle_map) 24 21 end) 25 22 |> Enum.join("\n") 26 23 27 - header <> "\n" <> body <> "\n\n---\n*generated by [atvouch](https://atvouch.dev)*" 24 + lines <> "\n\n---\n*generated by [atvouch](https://atvouch.dev)*" 28 25 end 29 26 30 - defp format_maintainer_routes(maintainer_did, maintainer_handle, {:self, _target_did}, _handle_map) do 27 + defp format_route_lines(maintainer_did, maintainer_handle, {:self, _target_did}, _handle_map) do 31 28 maintainer = display_name_link(maintainer_did, maintainer_handle) 32 - "**#{maintainer}** is a maintainer" 29 + ["- #{maintainer} is a maintainer"] 33 30 end 34 31 35 - defp format_maintainer_routes(maintainer_did, maintainer_handle, {:direct, _target_did}, _handle_map) do 36 - maintainer = display_name_link(maintainer_did, maintainer_handle) 37 - "**#{maintainer}**: direct vouch" 32 + defp format_route_lines(maintainer_did, _maintainer_handle, {:direct, target_did}, handle_map) do 33 + [format_path([maintainer_did, target_did], handle_map)] 38 34 end 39 35 40 - defp format_maintainer_routes(maintainer_did, maintainer_handle, {:routes, _target_did, []}, _handle_map) do 36 + defp format_route_lines(maintainer_did, maintainer_handle, {:routes, _target_did, []}, _handle_map) do 41 37 maintainer = display_name_link(maintainer_did, maintainer_handle) 42 - "**#{maintainer}**: no routes found" 38 + ["- no route from #{maintainer}"] 43 39 end 44 40 45 - defp format_maintainer_routes(maintainer_did, maintainer_handle, {:routes, _target_did, paths}, handle_map) do 46 - maintainer = display_name_link(maintainer_did, maintainer_handle) 47 - route_lines = Enum.map(paths, &format_path(&1, handle_map)) 48 - "**#{maintainer}**:\n" <> Enum.join(route_lines, "\n") 41 + defp format_route_lines(_maintainer_did, _maintainer_handle, {:routes, _target_did, paths}, handle_map) do 42 + Enum.map(paths, &format_path(&1, handle_map)) 49 43 end 50 44 51 45 defp format_path(path, handle_map) do
+15 -16
appview/test/atvouch/tangled/comment_builder_test.exs
··· 21 21 routes = [{@alice_did, "alice.test", {:self, @alice_did}}] 22 22 result = CommentBuilder.build_comment(@author_did, "author.test", routes, @handle_map) 23 23 24 - assert result =~ "**[@alice.test](https://bsky.app/profile/did:plc:alice)** is a maintainer" 24 + assert result =~ "- [@alice.test](https://bsky.app/profile/did:plc:alice) is a maintainer" 25 + refute result =~ "##" 25 26 end 26 27 27 28 test "formats self route with nil handle" do 28 29 routes = [{@alice_did, nil, {:self, @alice_did}}] 29 30 result = CommentBuilder.build_comment(@author_did, nil, routes) 30 31 31 - assert result =~ "**`#{@alice_did}`** is a maintainer" 32 + assert result =~ "- `#{@alice_did}` is a maintainer" 32 33 end 33 34 34 - test "formats direct vouch" do 35 + test "formats direct vouch as a route" do 35 36 routes = [{@alice_did, "alice.test", {:direct, @author_did}}] 36 37 result = CommentBuilder.build_comment(@author_did, "author.test", routes, @handle_map) 37 38 38 - assert result =~ "## atvouch routes for [@author.test](https://bsky.app/profile/did:plc:author)" 39 - assert result =~ "**[@alice.test](https://bsky.app/profile/did:plc:alice)**: direct vouch" 39 + refute result =~ "##" 40 + assert result =~ "- [@alice.test](https://bsky.app/profile/did:plc:alice) -> [@author.test](https://bsky.app/profile/did:plc:author)" 40 41 assert result =~ "generated by [atvouch]" 41 42 end 42 43 ··· 48 49 49 50 result = CommentBuilder.build_comment(@author_did, "author.test", routes, @handle_map) 50 51 51 - assert result =~ "**[@alice.test](https://bsky.app/profile/did:plc:alice)**:" 52 52 assert result =~ "- [@alice.test](https://bsky.app/profile/did:plc:alice) -> [@bob.test](https://bsky.app/profile/did:plc:bob) -> [@author.test](https://bsky.app/profile/did:plc:author)" 53 53 end 54 54 ··· 67 67 routes = [{@alice_did, "alice.test", {:routes, @author_did, []}}] 68 68 result = CommentBuilder.build_comment(@author_did, "author.test", routes, @handle_map) 69 69 70 - assert result =~ "**[@alice.test](https://bsky.app/profile/did:plc:alice)**: no routes found" 70 + assert result =~ "- no route from [@alice.test](https://bsky.app/profile/did:plc:alice)" 71 71 end 72 72 73 - test "formats multiple maintainers with mixed results" do 73 + test "formats multiple maintainers as flat list" do 74 74 routes = [ 75 75 {@alice_did, "alice.test", {:direct, @author_did}}, 76 76 {@bob_did, "bob.test", ··· 80 80 81 81 result = CommentBuilder.build_comment(@author_did, "author.test", routes, @handle_map) 82 82 83 - assert result =~ "**[@alice.test](https://bsky.app/profile/did:plc:alice)**: direct vouch" 84 - assert result =~ "**[@bob.test](https://bsky.app/profile/did:plc:bob)**:" 83 + assert result =~ "- [@alice.test](https://bsky.app/profile/did:plc:alice) -> [@author.test](https://bsky.app/profile/did:plc:author)" 85 84 assert result =~ "- [@bob.test](https://bsky.app/profile/did:plc:bob) -> [@carol.test](https://bsky.app/profile/did:plc:carol) -> [@author.test](https://bsky.app/profile/did:plc:author)" 86 - assert result =~ "**[@dave.test](https://bsky.app/profile/did:plc:dave)**: no routes found" 85 + assert result =~ "- no route from [@dave.test](https://bsky.app/profile/did:plc:dave)" 87 86 end 88 87 89 88 test "falls back to DID when handle is nil" do 90 89 routes = [{@alice_did, nil, {:direct, @author_did}}] 91 90 result = CommentBuilder.build_comment(@author_did, nil, routes) 92 91 93 - assert result =~ "## atvouch routes for `#{@author_did}`" 94 - assert result =~ "**`#{@alice_did}`**: direct vouch" 92 + refute result =~ "##" 93 + assert result =~ "- [#{@alice_did}](https://bsky.app/profile/#{@alice_did}) -> [#{@author_did}](https://bsky.app/profile/#{@author_did})" 95 94 end 96 95 97 96 test "falls back to DID when handle is empty string" do 98 97 routes = [{@alice_did, "", {:direct, @author_did}}] 99 98 result = CommentBuilder.build_comment(@author_did, "", routes) 100 99 101 - assert result =~ "## atvouch routes for `#{@author_did}`" 102 - assert result =~ "**`#{@alice_did}`**: direct vouch" 100 + refute result =~ "##" 101 + assert result =~ "- [#{@alice_did}](https://bsky.app/profile/#{@alice_did}) -> [#{@author_did}](https://bsky.app/profile/#{@author_did})" 103 102 end 104 103 105 104 test "formats three-hop path" do ··· 114 113 "- [@alice.test](https://bsky.app/profile/did:plc:alice) -> [@bob.test](https://bsky.app/profile/did:plc:bob) -> [@carol.test](https://bsky.app/profile/did:plc:carol) -> [@author.test](https://bsky.app/profile/did:plc:author)" 115 114 end 116 115 117 - test "formats multiple routes for one maintainer" do 116 + test "formats multiple routes for one maintainer as flat list" do 118 117 routes = [ 119 118 {@alice_did, "alice.test", 120 119 {:routes, @author_did,