Repository navigation
small-user-avatars - Restore on new PR lists - #10080
Conversation
| function addAvatar(link: HTMLElement): void { | ||
| const username = link.textContent; | ||
| const hovercardUrl = link.getAttribute('data-hovercard-url'); | ||
| const username = hovercardUrl ? hovercardUrl.split('/', 3)[2] : link.textContent; |
There was a problem hiding this comment.
I'm curious why this should be needed. The selected item still contains the username, does it not?
There was a problem hiding this comment.
I'm seeing this on https://github.com/pulls/authored for link.textContent
There was a problem hiding this comment.
The issue is not on the global PR list it's on the global issue lists do. Every author button there looks like this:
<button data-testid="author-filter-link" data-hovercard-url="/users/0xShinRai/hovercard" data-hovercard-type="user">
<span class="prc-VisuallyHidden-...">Filter by author </span>0xShinRai
</button>
This is what happens when the hover card check is removed (tested locally)
And this with the hover card parsing
There was a problem hiding this comment.
Thanks! I'd love this to be detailed in the code.
- move the getter into a "extractUsername(el)` function
- Add a link to your own comment to the function as an explanation
- It would also be great to add an internal assertion to ensure that the extracted username is valid (no spaces for example)
For the third point, we might already have some helper or logic in related functions. If not, feel free to create one in github-helpers/index.ts
| '[data-testid="created-at"]', | ||
| '[data-testid="closed-at"]', | ||
| ) + ' a[data-hovercard-url*="/users"]', // `isIssueList` | ||
| '[data-testid="author-filter-link"][aria-label^="Filter by author "]:not([aria-label$="[bot]"])', // Preview and global PR lists |
There was a problem hiding this comment.
Why exclude the bot? We don't have this exclusion elsewhere. Can you provide a test URL where this makes a difference?
There was a problem hiding this comment.
Bot author links have no user hovercard, so the existing selectors never matched them and on the issue lists that's why they had no avatar.
On the new PR list dependabot[bot] is skipped by the data-hovercard-type selector for the same reason. The PR list is the only place where a bot link has an aria-label, which is also the attribute we need for attributed-author-filter-link, so :not([aria-label$="[bot]"]) keeps it matching the other lists instead of adding a new rule.
PR list with bot authors without the exclusion selector (locally tested)
PR list with bot authors with the exclusion selector (locally tested)
Test URLs:
https://github.com/pulls/search?q=is%3Apr+author%3Aapp%2Fdependabot+state%3Aopen
https://github.com/issues/search?q=is%3Aissue+author%3Aapp%2Fgithub-actions
https://github.com/mf4633/low-no/issues?q=sort%3Aupdated-desc+is%3Aissue+state%3Aopen+
There was a problem hiding this comment.
If the limitation is the presence of the hovercard, then we should select the hovercard rather than building a blacklist
There was a problem hiding this comment.
I am sorry but GitHub has done GitHub and hovercard* is only present on Issue Lists but absent on PR Lists, so there's nothing to target hovercard there.
*The hovercard isn't an element, just a data-hovercard-url attribute, added by GitHub to dynamically fetch the user's profile card/modal.
There was a problem hiding this comment.
The comment suggests that this selector only applies to PR lists, so I'm not sure why Issue lists are relevant here.
It can be changed to
'[aria-label^="Filter by author "][data-hovercard-url]', // Preview and global PR lists
There was a problem hiding this comment.
Sorry, I think I misworded it. There are two separate questions here: 1. which selector to use, and 2. whether we need the bot exclusion.
1 which selector to use
- Issue List author elements HAVE
data-hovercard-url. - PR List author elements DOESN'T HAVE
data-hovercard-url, so the suggested selector matches nothing, including human authors. - We therefore need:
'[aria-label^="Filter by author "]'2 whether we need the bot exclusion
The bot exclusion selector is optional:
:not([aria-label$="[bot]"])I added it to preserve the behaviour I observed on issue lists, where the existing hovercard selectors skip app authors.
However, this is a best-effort exclusion: it skips names ending in [bot], such as dependabot[bot], but not bare app names such as Copilot, which already gets an avatar.
If showing bot avatars is preferred I am happy to remove the exclusion selector.
There was a problem hiding this comment.
Ah I had misread your comment.
Don't we have a function to get the avatar for apps too? As long as it works and doesn't duplicate any existing avatars I don't see why not support it.
There was a problem hiding this comment.
In the latest push I have added support for it and updated the avatar lookup for a few more bots.
|
I will look into the comments, I was testing alot of things that got messed up in the Preview UI and I am using the downloaded/copied HTML for the work. I will do cleanup on my local, reverify everything. |
|
To maintainers: Please add labels to this PR |
|
Thank you! I'll open a followup PR to further improve the logic and support for bots. It's kind of a mess at the moment because there's no one-fetch URL for app/bot avatars. Also GitHub calls them in two different ways:
and a million DOM variations... |
|
also I have found that the new Preview screens are also very inconsistent, I will try to file detailed issues as I find them 👍🏼 |
|
It's possible that it's just too early and that we shouldn't spend time on them yet. Most likely they'll add the hovercard attribute at some point. |
Split out of #10072 as requested, so each feature gets its own release note.
Restores small avatars on the new PR lists' author links, plus the global issue lists that use the same
[data-testid="author-filter-link"]element. On global issue lists that element wraps a visually-hidden "Filter by author " label, so the username is read fromdata-hovercard-urlwhen available.Follow-up to #10065.
Test URLs
Screenshot