feat(history): show author avatar in commit list#1339
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR adds GitHub avatar thumbnails to the commit history list by extracting Key issue:
Confidence Score: 3/5
Sequence DiagramsequenceDiagram
participant R as CommitList (Renderer)
participant IPC as Electron IPC
participant G as GitService (Main)
participant GH as github.com
R->>IPC: gitGetLog({ taskPath, maxCount })
IPC->>G: getLog(taskPath, maxCount)
G->>G: git log --pretty=format:%H%s%an%aI%D%ae%b
G-->>IPC: { commits: [{ hash, author, authorEmail, ... }] }
IPC-->>R: { success, commits, aheadCount }
loop For each commit in list
R->>R: githubLoginFromEmail(authorEmail)
alt noreply email → login extracted
R->>GH: GET /login.png?size=40
GH-->>R: 200 avatar image
else regular email → falls back to author name
R->>GH: GET /DisplayName.png?size=40
GH-->>R: 404 (always fails)
R->>R: onError → setFailed(true) → hide avatar
end
end
Last reviewed commit: f86fedb |
| function getAvatarUrl(author: string, authorEmail: string): string { | ||
| const login = githubLoginFromEmail(authorEmail); | ||
| if (login) return `https://github.com/${login}.png?size=40`; | ||
| // Fall back to trying the author name as a GitHub username | ||
| return `https://github.com/${author}.png?size=40`; | ||
| } |
There was a problem hiding this comment.
Fallback constructs URLs from author display names, causing spurious HTTP 404 requests
When githubLoginFromEmail() returns null (the common case for non-GitHub email addresses), this function falls back to using the git author display name (e.g., "Jane Smith") as a GitHub username. This creates URLs like https://github.com/Jane%20Smith.png?size=40, which GitHub will always reject with a 404 response.
The result is one wasted HTTP request per non-noreply commit, every time the list renders. The fallback should return null to signal "no avatar available" instead of blindly constructing a URL:
| function getAvatarUrl(author: string, authorEmail: string): string { | |
| const login = githubLoginFromEmail(authorEmail); | |
| if (login) return `https://github.com/${login}.png?size=40`; | |
| // Fall back to trying the author name as a GitHub username | |
| return `https://github.com/${author}.png?size=40`; | |
| } | |
| function getAvatarUrl(author: string, authorEmail: string): string | null { | |
| const login = githubLoginFromEmail(authorEmail); | |
| if (login) return `https://github.com/${login}.png?size=40`; | |
| return null; | |
| } | |
| function AuthorAvatar({ author, authorEmail }: { author: string; authorEmail: string }) { | |
| const [failed, setFailed] = useState(false); | |
| const url = getAvatarUrl(author, authorEmail); | |
| if (!url || failed) return null; | |
| return ( | |
| <img | |
| src={url} | |
| alt="" | |
| className="h-4 w-4 shrink-0 rounded-sm" | |
| onError={(e: SyntheticEvent<HTMLImageElement>) => { | |
| e.currentTarget.style.display = 'none'; | |
| setFailed(true); | |
| }} | |
| /> | |
| ); | |
| } |
Summary
authorEmailfrom git log output (%aeformat) and pass it through the IPC layerChanges
GitService.ts: AddauthorEmailfield togetLog()return type and include%aein the git log format stringCommitList.tsx: AddAuthorAvatarcomponent that loads GitHub profile images, withgithubLoginFromEmail()helper to extract usernames from GitHub noreply addresseselectron-api.d.ts: AddauthorEmailto thegitGetLogresponse type