Skip to content

fix: read BACKLOG_PROJECT env var in document create, wiki create, and document view - #116

Open
sakai-classmethod wants to merge 3 commits into
nulab:mainfrom
sakai-classmethod:fix/document-wiki-create-project-env
Open

fix: read BACKLOG_PROJECT env var in document create, wiki create, and document view#116
sakai-classmethod wants to merge 3 commits into
nulab:mainfrom
sakai-classmethod:fix/document-wiki-create-project-env

Conversation

@sakai-classmethod

Copy link
Copy Markdown

Fixes #115

Summary

document create, wiki create, and document view did not read the BACKLOG_PROJECT environment variable, even though their help text advertises it via envVars(). For the create commands, non-interactive runs (piped stdin or CI) failed with an error, and interactive runs showed an unnecessary prompt:

$ export BACKLOG_PROJECT=MY_PROJECT
$ echo "body" | bee document create -t "Title"
 ERROR  Project is required. Use arguments to provide it in non-interactive mode.

$ bee document list   # works fine with the same environment variable

For document view, --web failed with The --project flag is required when using --web. under the same conditions.

The --project option of these commands was defined with a plain .option() call, missing .env("BACKLOG_PROJECT"). envVars() only affects help rendering and does not wire the environment variable to the option.

This PR wires the option to the environment variable using the same pattern as issue create:

.addOption(new Option("-p, --project <id>", "Project ID or project key").env("BACKLOG_PROJECT"))

It also fixes a related help-rendering issue: _renderEnvVars() concatenated env vars auto-collected from Option.env() with the manually declared envVars() entries, so commands declaring BACKLOG_PROJECT in both places (e.g. issue create and every opt.project() user) listed it twice in the ENVIRONMENT VARIABLES section. It is now deduplicated by variable name.

This is a minimal targeted fix for the affected commands. The underlying issue — envVars() (help rendering) and Option.env() (actual wiring) being independent, so a mismatch between them is not detected anywhere — remains. If you are interested, I would be happy to follow up with a separate PR that adds a consistency test walking the command tree and asserting that every command declaring BACKLOG_PROJECT in envVars() actually wires it to its --project option.

Test plan

  • Added a test per command asserting that the project is resolved from BACKLOG_PROJECT when --project is omitted, and a BeeCommand test asserting each env var is listed only once in help output.
  • pnpm test (724 tests), pnpm typecheck, pnpm lint, and pnpm format --check all pass.
  • Verified manually against a real Backlog space with BACKLOG_PROJECT set and --project omitted:
    • document create succeeded end-to-end: the project was resolved from the environment and the document was created (previously it aborted immediately in non-interactive mode).
    • wiki create resolved the project from the environment and reached the API call (creation itself returned 403 because the wiki feature is disabled on the test space, which is unrelated to this change).
    • document view <id> --web --no-browser now prints the document URL containing the project key from the environment.
    • --help shows (env: BACKLOG_PROJECT) on the option, and the ENVIRONMENT VARIABLES section lists BACKLOG_PROJECT exactly once.

The --project option of `document create` and `wiki create` was defined
with a plain .option() call, missing .env("BACKLOG_PROJECT"), while the
commands' help text advertised BACKLOG_PROJECT support via .envVars().
As a result, non-interactive runs (piped stdin or CI) failed with
"Project is required" even when BACKLOG_PROJECT was set, and interactive
runs showed an unnecessary prompt.

Wire the option to the environment variable using the same pattern as
`issue create`.

Claude-Session: https://claude.ai/code/session_01LoiedKxE7eSb6MFjNYApnn
The --project option of `document view` (required for --web) had the
same missing .env("BACKLOG_PROJECT") wiring as document create and
wiki create.

Claude-Session: https://claude.ai/code/session_01LoiedKxE7eSb6MFjNYApnn
_renderEnvVars() concatenated env vars auto-collected from Option.env()
with the manually declared envVars() entries, so commands declaring
BACKLOG_PROJECT in both places showed it twice in the ENVIRONMENT
VARIABLES section. Deduplicate by variable name, letting the
option-derived entry win.

Claude-Session: https://claude.ai/code/session_01LoiedKxE7eSb6MFjNYApnn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

document create, wiki create, and document view do not read the BACKLOG_PROJECT env var

1 participant