feat: port git :report subcommand to golang

The bash :report implementation for the git plugin is replaced with a compiled golang binary. Property, computed and global keys are collected in parallel, while the sha and last-updated-at keys still shell out to git and stat the deploy branch ref so their values are unchanged. The non-report git helpers such as fn-git-cmd and the computed deploy-branch and keep-git-dir getters remain in place for the build pipeline.
This commit is contained in:
Jose Diaz-Gonzalez
2026-07-07 07:02:38 -04:00
parent 6e5afb84a9
commit 3fee5b881a
12 changed files with 356 additions and 118 deletions

106
plugins/git/internal-functions Executable file → Normal file
View File

@@ -328,112 +328,6 @@ cmd-git-public-key() {
fn-git-auth-error
}
cmd-git-report() {
declare desc="displays a git report for one or more apps"
declare cmd="git:report"
[[ "$1" == "$cmd" ]] && shift 1
fn-report-parse-args "$@"
set -- "${REPORT_ARGS[@]}"
declare APP="${1:-}" INFO_FLAG="${2:-}"
if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then
INFO_FLAG="$APP"
APP=""
fi
if [[ "$REPORT_IS_GLOBAL" == "true" ]]; then
APP="--global"
fi
if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then
INFO_FLAG="true"
fi
if [[ "$APP" == "--global" ]]; then
cmd-git-report-single "$APP" "$INFO_FLAG" "$REPORT_FORMAT"
elif [[ -z "$APP" ]]; then
for app in $(dokku_apps); do
cmd-git-report-single "$app" "$INFO_FLAG" "$REPORT_FORMAT" | tee || true
done
else
cmd-git-report-single "$APP" "$INFO_FLAG" "$REPORT_FORMAT"
fi
}
cmd-git-report-single() {
declare APP="$1" INFO_FLAG="$2" FORMAT="${3:-stdout}"
local APP_ROOT="$DOKKU_ROOT/$APP"
if [[ "$INFO_FLAG" == "true" ]]; then
INFO_FLAG=""
fi
local flag_map=()
if [[ "$APP" == "--global" ]]; then
flag_map=(
"--git-computed-archive-max-files: $(fn-archive-computed-max-files)"
"--git-computed-archive-max-size: $(fn-archive-computed-max-size)"
"--git-computed-deploy-branch: $(fn-git-computed-deploy-branch "$APP")"
"--git-computed-keep-git-dir: $(fn-git-computed-keep-git-dir "$APP")"
"--git-global-archive-max-files: $(fn-plugin-property-get "git" "--global" "archive-max-files" "")"
"--git-global-archive-max-size: $(fn-plugin-property-get "git" "--global" "archive-max-size" "")"
"--git-global-deploy-branch: $(fn-plugin-property-get "git" "--global" "deploy-branch" "")"
"--git-global-keep-git-dir: $(fn-plugin-property-get "git" "--global" "keep-git-dir" "")"
)
else
verify_app_name "$APP"
flag_map=(
"--git-computed-archive-max-files: $(fn-archive-computed-max-files)"
"--git-computed-archive-max-size: $(fn-archive-computed-max-size)"
"--git-computed-deploy-branch: $(fn-git-computed-deploy-branch "$APP")"
"--git-computed-keep-git-dir: $(fn-git-computed-keep-git-dir "$APP")"
"--git-deploy-branch: $(fn-plugin-property-get "git" "$APP" "deploy-branch" "")"
"--git-global-archive-max-files: $(fn-plugin-property-get "git" "--global" "archive-max-files" "")"
"--git-global-archive-max-size: $(fn-plugin-property-get "git" "--global" "archive-max-size" "")"
"--git-global-deploy-branch: $(fn-plugin-property-get "git" "--global" "deploy-branch" "")"
"--git-global-keep-git-dir: $(fn-plugin-property-get "git" "--global" "keep-git-dir" "")"
"--git-keep-git-dir: $(fn-plugin-property-get "git" "$APP" "keep-git-dir" "")"
"--git-rev-env-var: $(fn-plugin-property-get "git" "$APP" "rev-env-var" "GIT_REV")"
"--git-sha: $(fn-git-cmd "$APP_ROOT" rev-parse HEAD 2>/dev/null || false)"
"--git-source-image: $(fn-git-source-image "$APP")"
"--git-last-updated-at: $(fn-git-last-updated-at "$APP")"
)
fi
fn-report-validate-format "$FORMAT" "$INFO_FLAG"
if [[ "$FORMAT" == "json" ]]; then
fn-report-emit-json flag_map "git"
return
fi
if [[ -z "$INFO_FLAG" ]]; then
if [[ "$APP" == "--global" ]]; then
dokku_log_info2_quiet "global git information"
else
dokku_log_info2_quiet "${APP} git information"
fi
for flag in "${flag_map[@]}"; do
key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')"
dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")"
done
else
local match=false
for flag in "${flag_map[@]}"; do
valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)"
if [[ "$flag" == "${INFO_FLAG}:"* ]]; then
value=${flag#*: }
size="${#value}"
if [[ "$size" -ne 0 ]]; then
echo "$value" && match=true
else
match=true
fi
fi
done
[[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}"
fi
}
cmd-git-status() {
declare desc="check the git status output for an app"
local cmd="git:status"