-
Notifications
You must be signed in to change notification settings - Fork 30
feat(worktree): use human-readable names for worktree branches #2340
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
Open
MukundaKatta
wants to merge
1
commit into
PostHog:main
Choose a base branch
from
MukundaKatta:fix/human-readable-worktree-branches
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+68
−2
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { generateHumanReadableName } from "./worktree-name"; | ||
|
|
||
| describe("generateHumanReadableName", () => { | ||
| it("returns a string matching adjective-noun-NN", () => { | ||
| const name = generateHumanReadableName(); | ||
| expect(name).toMatch(/^[a-z]+-[a-z]+-\d{2}$/); | ||
| }); | ||
|
|
||
| it("produces varied names over multiple calls", () => { | ||
| const names = new Set<string>(); | ||
| for (let i = 0; i < 50; i++) { | ||
| names.add(generateHumanReadableName()); | ||
| } | ||
| // With 36 * 36 * 90 = ~116k combinations, 50 draws should yield | ||
| // many unique values. Allow generous slack for randomness. | ||
| expect(names.size).toBeGreaterThan(20); | ||
| }); | ||
|
|
||
| it("uses only filesystem-safe characters", () => { | ||
| for (let i = 0; i < 25; i++) { | ||
| const name = generateHumanReadableName(); | ||
| expect(name).toMatch(/^[a-z0-9-]+$/); | ||
| } | ||
| }); | ||
|
|
||
| it("stays compact (under 32 chars)", () => { | ||
| for (let i = 0; i < 25; i++) { | ||
| expect(generateHumanReadableName().length).toBeLessThanOrEqual(32); | ||
| } | ||
| }); | ||
| }); | ||
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,34 @@ | ||
| import * as crypto from "node:crypto"; | ||
|
|
||
| /** | ||
| * Curated adjective-noun word list used to label worktrees. Words are short, | ||
| * filesystem-safe (lowercase a-z only), and chosen to be inoffensive. | ||
| */ | ||
| // biome-ignore format: keep word lists compact | ||
| const ADJECTIVES = [ | ||
| "amber", "brave", "calm", "clever", "cosmic", "crisp", "dapper", "dusty", | ||
| "eager", "fancy", "fluffy", "gentle", "happy", "jolly", "lively", "lucky", | ||
| "merry", "mighty", "nimble", "plucky", "proud", "quick", "quiet", "rapid", | ||
| "shiny", "silver", "smooth", "snappy", "spry", "sturdy", "sunny", "swift", | ||
| "tidy", "vivid", "witty", "zesty", | ||
| ]; | ||
|
|
||
| // biome-ignore format: keep word lists compact | ||
| const NOUNS = [ | ||
| "badger", "beetle", "bison", "cedar", "comet", "cricket", "delta", "ember", | ||
| "falcon", "ferret", "finch", "fjord", "glade", "harbor", "heron", "ibex", | ||
| "lemur", "lynx", "marlin", "meadow", "mountain", "otter", "panda", "petal", | ||
| "pebble", "puffin", "quokka", "raven", "river", "robin", "sparrow", "summit", | ||
| "tiger", "valley", "willow", "wombat", | ||
| ]; | ||
|
|
||
| /** | ||
| * Generates a short, human-readable random name (e.g. "swift-otter-42"). | ||
| * Suffix is a 2-digit number to reduce collisions while keeping names compact. | ||
| */ | ||
| export function generateHumanReadableName(): string { | ||
| const adjective = ADJECTIVES[crypto.randomInt(0, ADJECTIVES.length)]; | ||
| const noun = NOUNS[crypto.randomInt(0, NOUNS.length)]; | ||
| const suffix = crypto.randomInt(10, 100).toString(); | ||
| return `${adjective}-${noun}-${suffix}`; | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it.eachcalls, making each individual sample a named test case and avoiding an imperative loop that obscures the intent.Context Used: Do not attempt to comment on incorrect alphabetica... (source)
Prompt To Fix With AI
This is a comment left during a code review. Path: packages/git/src/worktree-name.test.ts Line: 10-31 Comment: The team's standard is to prefer parameterised tests over manual loops. The three loop-based cases ("varies", "filesystem-safe", "compact") can each be expressed as `it.each` calls, making each individual sample a named test case and avoiding an imperative loop that obscures the intent. ```suggestion it("produces varied names over multiple calls", () => { const names = new Set(Array.from({ length: 50 }, generateHumanReadableName)); // With 36 * 36 * 90 = ~116k combinations, 50 draws should yield // many unique values. Allow generous slack for randomness. expect(names.size).toBeGreaterThan(20); }); it.each(Array.from({ length: 25 }, generateHumanReadableName))( "uses only filesystem-safe characters: %s", (name) => { expect(name).toMatch(/^[a-z0-9-]+$/); }, ); it.each(Array.from({ length: 25 }, generateHumanReadableName))( "stays compact (under 32 chars): %s", (name) => { expect(name.length).toBeLessThanOrEqual(32); }, ); ``` **Context Used:** Do not attempt to comment on incorrect alphabetica... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0)) How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!