Conversation
This seems to work for me for simple cases now, but I feel like I'm missing: * checking if current working tree is a linked worktree. * the `worktrees: true` key
There was a problem hiding this comment.
Pull request overview
Updates the docs preview tooling to better identify the current repo (including in worktree-like setups) and to refactor the Antora extension hook that rewrites the playbook during preview builds.
Changes:
- Derive
PREVIEW_REPOvia GitHub CLI instead of inferring from the local toplevel directory name. - Refactor
lib/preview.jsto use a namedrebuildPlaybookhandler and add local path mapping logic intended to support worktrees. - Adjust the Antora
--extensionpath to be explicitly relative (./lib/preview.js).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| scripts/preview | Switches repo-name detection to gh repo view and tweaks Antora extension path. |
| lib/preview.js | Refactors playbook rebuild hook and adds local URL/path mapping logic aimed at worktree support. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/preview.js
Outdated
| const isMainGitDir = p => { | ||
| const pwg = `${p}/.git` | ||
| if (! fs.existsSync(pwg)) { return false } | ||
| return fs.statSync(pwg).isDirectory() | ||
| } | ||
|
|
||
| function mapLocalUrl (repo, url) { | ||
| for (const repoPath of args.repoPath) { | ||
| const p = path.resolve(repoPath, repo) | ||
| if (fs.existsSync(p)) { | ||
| if (isMainGitDir(p)) { return p } | ||
| // otherwise check if this directory contains worktrees | ||
| const subdir = | ||
| fs.readdirSync(p).find( | ||
| n => isMainGitDir(`${p}/${n}`)) | ||
| if (subdir) { | ||
| return `${p}/${subdir}` | ||
| } |
There was a problem hiding this comment.
isMainGitDir only treats a repo as valid when .git is a directory. Linked worktrees typically have a .git file pointing at the shared gitdir, so this logic will fail to recognize the current worktree checkout and fall back to the remote URL (triggering an unnecessary clone and breaking the intended worktree support). Adjust the detection to treat a .git file as a valid worktree (or parse git rev-parse --git-dir / git worktree list --porcelain to locate the right working tree).
There was a problem hiding this comment.
the intention is that the readdir checks every file, and returns the first one that does have a main git dir.
|
I checked out this PR in my local ~/GitHub/docs-devex/release/7.6 (DOC-12088-udf-guides ✗) preview
🐇 Hello! I'm the Docs Build Rabbit
version 1.1.1
HTTP 401: Bad credentials (https://api.github.com/graphql)
Try authenticating with: gh auth login
Let's build this preview!
PREVIEW_BRANCH=DOC-12088-udf-guides
PREVIEW_REPO=
PREVIEW_START_PATH=.
PREVIEW_OVERRIDE=antora-playbook.preview.local.yml
PREVIEW_CONFIG=DOC-12088-udf-guides
PREVIEW_COMPONENT=server
[14:00:01.593] FATAL (antora): Oh no! source not found in playbook.
You need to add to 'antora-playbook.preview.yml' something like:
content:
sources:
# add in the appropriate place
- url: https://github.com/couchbaselabs/docs-devex.git
branches: DOC-12088-udf-guides
Cause: Error
at notfound (/Users/simondew/GitHub/docs-site/lib/preview.js:184:12)
at GeneratorContext.rebuildPlaybook (/Users/simondew/GitHub/docs-site/lib/preview.js:44:15)
at Object.onceWrapper (node:events:634:26)
at GeneratorContext.notify (/Users/simondew/GitHub/docs-site/node_modules/@antora/site-generator/lib/generator-context.js:59:49)
at generateSite (/Users/simondew/GitHub/docs-site/node_modules/@antora/site-generator/lib/generate-site.js:11:19)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Command.parseAsync (/Users/simondew/GitHub/docs-site/node_modules/commander/lib/command.js:936:5) |
f010327 to
a818b27
Compare
This seems to work for me for simple cases now, but I feel like I'm missing:
worktrees: truekey