ssh-dispatch: inherit os.Environ() so hooks see SHITHUB_DATABASE_URL
Pre-fix: buildSSHEnv built a minimal explicit env list with just
SHITHUB_USER_ID/USERNAME/REPO_ID/REPO_FULL_NAME/PROTOCOL/REMOTE_IP/
REQUEST_ID/PATH + the safe.directory GIT_CONFIG_* triple.
When git-receive-pack forked the pre-receive hook ('shithubd hook
pre-receive', via the shim in internal/git/hooks/install.go), the
hook called config.Load(nil) and exited with 'DB URL not set'
because SHITHUB_DATABASE_URL wasn't in the env. User saw:
remote: shithub: server error: DB URL not set
remote: shithubd: DB URL not set
! [remote rejected] trunk -> trunk (pre-receive hook declined)
The HTTPS-git path didn't hit this because shithubd-web's systemd
unit sources /etc/shithub/web.env via EnvironmentFile= and
receive-pack inherits the env directly.
Fix: base the SSH env on os.Environ() so the SHITHUB_* config keys
the git-shell-commands wrapper sourced from web.env propagate
through receive-pack into the hook. Push-event metadata
(SHITHUB_USER_ID/REPO_ID/...) is appended after the inheritance
so any stale value in the parent env is shadowed by the dispatcher's
real value (last-wins on duplicate env keys).
PATH no longer needs an explicit copy; it's part of os.Environ().
Tests:
- TestBuildSSHEnv_InheritsParentEnv pins SHITHUB_DATABASE_URL +
SHITHUB_STORAGE__REPOS_ROOT propagation.
- TestBuildSSHEnv_ExplicitOverridesInheritance pins last-wins
semantics on the SHITHUB_REQUEST_ID collision case.
Both run without a DB so they fire on every CI invocation, not
just the dbtest-equipped ones.
SHITHUB_USER_ID/USERNAME/REPO_ID/REPO_FULL_NAME/PROTOCOL/REMOTE_IP/
REQUEST_ID/PATH + the safe.directory GIT_CONFIG_* triple.
When git-receive-pack forked the pre-receive hook ('shithubd hook
pre-receive', via the shim in internal/git/hooks/install.go), the
hook called config.Load(nil) and exited with 'DB URL not set'
because SHITHUB_DATABASE_URL wasn't in the env. User saw:
remote: shithub: server error: DB URL not set
remote: shithubd: DB URL not set
! [remote rejected] trunk -> trunk (pre-receive hook declined)
The HTTPS-git path didn't hit this because shithubd-web's systemd
unit sources /etc/shithub/web.env via EnvironmentFile= and
receive-pack inherits the env directly.
Fix: base the SSH env on os.Environ() so the SHITHUB_* config keys
the git-shell-commands wrapper sourced from web.env propagate
through receive-pack into the hook. Push-event metadata
(SHITHUB_USER_ID/REPO_ID/...) is appended after the inheritance
so any stale value in the parent env is shadowed by the dispatcher's
real value (last-wins on duplicate env keys).
PATH no longer needs an explicit copy; it's part of os.Environ().
Tests:
- TestBuildSSHEnv_InheritsParentEnv pins SHITHUB_DATABASE_URL +
SHITHUB_STORAGE__REPOS_ROOT propagation.
- TestBuildSSHEnv_ExplicitOverridesInheritance pins last-wins
semantics on the SHITHUB_REQUEST_ID collision case.
Both run without a DB so they fire on every CI invocation, not
just the dbtest-equipped ones.
Authored by
mfwolffe <wolffemf@dukes.jmu.edu>
- SHA
fe9e5c46639af1b0c1f122aa7f68b880d5712eec- Parents
-
9f6ec52 - Tree
f2ad1d0