-
Notifications
You must be signed in to change notification settings - Fork 264
feat(web): Commit diffs #1154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat(web): Commit diffs #1154
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
00784f2
feat(web): scaffold commit diff routing
brendan-kellam 059240a
feat(web): scaffold commit diff merge view
brendan-kellam 3b53335
refactor browse components into seperate folders
brendan-kellam dbc4d14
feat(web): swap commit diff renderer for lightweight viewer
brendan-kellam 7fe2972
fix(web): polish commit diff layout and sticky behavior
brendan-kellam 4c33b60
feat(web): add diffstat indicators and per-file actions to commit diff
brendan-kellam 29ed7b9
move logger out of utils
brendan-kellam 3e20e0d
feat(web): clickable history rows, multi-author commit header, file a…
brendan-kellam df906c4
wip
brendan-kellam 5c36e73
fix(web): polish PathHeader rendering for SHAs and empty paths
brendan-kellam 038edcc
feat(web): add optional path filter to /api/diff and get_diff tool
brendan-kellam 5b7b01b
feat(web): focused single-file commit diff view
brendan-kellam fae7b72
feedback
brendan-kellam 0a11df8
typo
brendan-kellam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/web/src/app/(app)/browse/[...path]/components/commitDiffPanel/commitHashLine.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| 'use client'; | ||
|
|
||
| import { CopyIconButton } from "@/app/(app)/components/copyIconButton"; | ||
| import { useToast } from "@/components/hooks/use-toast"; | ||
| import Link from "next/link"; | ||
| import { Fragment, useCallback } from "react"; | ||
| import { getBrowsePath } from "../../../hooks/utils"; | ||
|
|
||
| interface CommitHashLineProps { | ||
| repoName: string; | ||
| commitHash: string; | ||
| parents: string[]; | ||
| } | ||
|
|
||
| export const CommitHashLine = ({ repoName, commitHash, parents }: CommitHashLineProps) => { | ||
| const { toast } = useToast(); | ||
|
|
||
| const onCopyHash = useCallback(() => { | ||
| navigator.clipboard.writeText(commitHash).then(() => { | ||
| toast({ description: "✅ Copied commit SHA to clipboard" }); | ||
| }); | ||
| return true; | ||
| }, [commitHash, toast]); | ||
|
|
||
| return ( | ||
| <div className="text-xs font-mono text-muted-foreground flex flex-row items-center gap-1"> | ||
| {parents.length > 0 && ( | ||
| <> | ||
| <span> | ||
| {parents.length} parent{parents.length > 1 ? 's' : ''} | ||
| </span> | ||
| {parents.map((parent, i) => ( | ||
| <Fragment key={parent}> | ||
| {i > 0 && <span>+</span>} | ||
| <Link | ||
| href={getBrowsePath({ | ||
| repoName, | ||
| path: '', | ||
| pathType: 'commit', | ||
| commitSha: parent, | ||
| })} | ||
| className="underline hover:text-foreground" | ||
| title={parent} | ||
| > | ||
| {parent.slice(0, 7)} | ||
| </Link> | ||
| </Fragment> | ||
| ))} | ||
| </> | ||
| )} | ||
| <span>commit {commitHash.slice(0, 7)}</span> | ||
| <CopyIconButton onCopy={onCopyHash} /> | ||
| </div> | ||
| ); | ||
| }; |
31 changes: 31 additions & 0 deletions
31
packages/web/src/app/(app)/browse/[...path]/components/commitDiffPanel/commitMessage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| 'use client'; | ||
|
|
||
| import { CommitBody, CommitBodyToggle } from "@/app/(app)/browse/components/commitParts"; | ||
| import { useState } from "react"; | ||
|
|
||
| interface CommitMessageProps { | ||
| subject: string; | ||
| body: string; | ||
| } | ||
|
|
||
| export const CommitMessage = ({ subject, body }: CommitMessageProps) => { | ||
| const [isBodyExpanded, setIsBodyExpanded] = useState(false); | ||
| const hasBody = body.trim().length > 0; | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="flex flex-row items-center gap-2"> | ||
| <h1 className="text-lg font-semibold">{subject}</h1> | ||
| {hasBody && ( | ||
| <CommitBodyToggle | ||
| pressed={isBodyExpanded} | ||
| onPressedChange={setIsBodyExpanded} | ||
| /> | ||
| )} | ||
| </div> | ||
| {hasBody && isBodyExpanded && ( | ||
| <CommitBody body={body} className="rounded max-h-[40vh] overflow-y-auto" /> | ||
| )} | ||
| </> | ||
| ); | ||
| }; |
97 changes: 97 additions & 0 deletions
97
packages/web/src/app/(app)/browse/[...path]/components/commitDiffPanel/diffStat.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { FileDiff } from "@/features/git"; | ||
|
|
||
| const TOTAL_SQUARES = 5; | ||
|
|
||
| // Count `+`/`-` lines across all hunks in a file. | ||
| export const computeChangeCounts = (file: FileDiff) => { | ||
| let additions = 0; | ||
| let deletions = 0; | ||
| for (const hunk of file.hunks) { | ||
| for (const raw of hunk.body.split('\n')) { | ||
| if (raw.startsWith('+')) { | ||
| additions++; | ||
| } else if (raw.startsWith('-')) { | ||
| deletions++; | ||
| } | ||
| } | ||
| } | ||
| return { additions, deletions }; | ||
| }; | ||
|
|
||
| // Sum line-level change counts across multiple files. | ||
| export const computeTotalChangeCounts = (files: FileDiff[]) => { | ||
| let additions = 0; | ||
| let deletions = 0; | ||
| for (const file of files) { | ||
| const counts = computeChangeCounts(file); | ||
| additions += counts.additions; | ||
| deletions += counts.deletions; | ||
| } | ||
| return { additions, deletions }; | ||
| }; | ||
|
|
||
| // Map a total change count to a number of filled squares (0–5) using a | ||
| // log-ish scale so tiny diffs still show one square and huge diffs cap out. | ||
| // Mirrors GitHub's diffstat indicator behavior. | ||
| const filledSquaresForTotal = (total: number): number => { | ||
| if (total === 0) { | ||
| return 0; | ||
| } | ||
| if (total < 5) { | ||
| return 1; | ||
| } | ||
| if (total < 10) { | ||
| return 2; | ||
| } | ||
| if (total < 30) { | ||
| return 3; | ||
| } | ||
| if (total < 100) { | ||
| return 4; | ||
| } | ||
| return 5; | ||
| }; | ||
|
|
||
| interface DiffStatProps { | ||
| additions: number; | ||
| deletions: number; | ||
| } | ||
|
|
||
| export const DiffStat = ({ additions, deletions }: DiffStatProps) => { | ||
| const total = additions + deletions; | ||
|
|
||
| // Skip rendering when there are no line-level changes (e.g. pure renames). | ||
| if (total === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const filled = filledSquaresForTotal(total); | ||
| const greenCount = Math.round((filled * additions) / total); | ||
| const redCount = filled - greenCount; | ||
| const emptyCount = TOTAL_SQUARES - filled; | ||
|
|
||
| return ( | ||
| <div | ||
| className="flex flex-row items-center gap-2 text-xs flex-shrink-0 font-mono" | ||
| title={`${additions} additions, ${deletions} deletions`} | ||
| > | ||
| {additions > 0 && ( | ||
| <span className="text-green-700 dark:text-green-400">+{additions}</span> | ||
| )} | ||
| {deletions > 0 && ( | ||
| <span className="text-red-700 dark:text-red-400">-{deletions}</span> | ||
| )} | ||
| <div className="flex flex-row gap-px"> | ||
| {Array.from({ length: greenCount }).map((_, i) => ( | ||
| <span key={`g-${i}`} className="w-2 h-2 bg-green-500 dark:bg-green-400 rounded-[1px]" /> | ||
| ))} | ||
| {Array.from({ length: redCount }).map((_, i) => ( | ||
| <span key={`r-${i}`} className="w-2 h-2 bg-red-500 dark:bg-red-400 rounded-[1px]" /> | ||
| ))} | ||
| {Array.from({ length: emptyCount }).map((_, i) => ( | ||
| <span key={`e-${i}`} className="w-2 h-2 bg-border rounded-[1px]" /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.