refactor: Exclude Syncthing special files and streamline author logic
This commit is contained in:
parent
80fa4c8eda
commit
fb96578987
1 changed files with 13 additions and 14 deletions
|
|
@ -37,43 +37,42 @@ git config user.name "$COMMITTER_NAME"
|
|||
git config user.email "$COMMITTER_EMAIL"
|
||||
git config commit.gpgsign false
|
||||
|
||||
# Scope restricted to raw/ directory. raw/.stignore is omitted via .git/info/exclude
|
||||
git add -A -- raw/
|
||||
git reset -q -- raw/.stignore 2>/dev/null || true
|
||||
grep -qxF 'raw/.stignore' "${vault}/.git/info/exclude" 2>/dev/null || echo 'raw/.stignore' >> "${vault}/.git/info/exclude"
|
||||
grep -qxF 'raw/.stfolder' "${vault}/.git/info/exclude" 2>/dev/null || echo 'raw/.stfolder' >> "${vault}/.git/info/exclude"
|
||||
|
||||
git add -A -- raw/
|
||||
git reset -q -- raw/.stignore raw/.stfolder 2>/dev/null || true
|
||||
if git diff --cached --quiet; then
|
||||
printf '{"status":"noop","genome":"%s"}\n' "$genome"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Map Syncthing device ID to author information (name, email)
|
||||
resolve_dev() {
|
||||
# $1 = file path relative to the vault root (e.g., raw/file.txt)
|
||||
resolve_dev() { # $1 = path relativo al vault (raw/...) -> stampa lo short device id o vuoto
|
||||
[[ -z "${SYNCTHING_API_KEY:-}" ]] && return 0
|
||||
curl -fsS -H "X-API-Key: ${SYNCTHING_API_KEY}" --get "${SYNCTHING_URL}/rest/db/file" \
|
||||
--data-urlencode "folder=${fid}" --data-urlencode "file=${1#raw/}" 2>/dev/null \
|
||||
| jq -r '.local.modifiedBy // empty' 2>/dev/null || true
|
||||
}
|
||||
|
||||
author_for_dev() {
|
||||
# $1 = device ID
|
||||
author_for_dev() { # $1 = device id -> stampa "name\temail"
|
||||
local dev="$1" name="$DEFAULT_AUTHOR_NAME" email="$DEFAULT_AUTHOR_EMAIL"
|
||||
if [[ -n "$dev" && -f "$authors_map" ]] && jq -e --arg d "$dev" '.[$d]' "$authors_map" >/dev/null 2>&1; then
|
||||
name="$(jq -r --arg d "$dev" '.[$d].name' "$authors_map")"
|
||||
email="$(jq -r --arg d "$dev" '.[$d].email' "$authors_map")"
|
||||
fi
|
||||
printf '%s\t%s\t%s' "$name" "$email" "${dev:-unknown}"
|
||||
printf '%s\t%s' "$name" "$email"
|
||||
}
|
||||
|
||||
# Group staged files by author identity
|
||||
declare -A G_FILES G_NAME G_EMAIL G_DEV
|
||||
# raccolgo per-file (relpath, author) e raggruppo per autore per il commit
|
||||
declare -A G_FILES G_NAME G_EMAIL
|
||||
declare -a ROWS
|
||||
while IFS= read -r f; do
|
||||
[[ -z "$f" ]] && continue
|
||||
dev="$(resolve_dev "$f")"
|
||||
IFS=$'\t' read -r aname aemail adev <<< "$(author_for_dev "$dev")"
|
||||
IFS=$'\t' read -r aname aemail <<< "$(author_for_dev "$dev")"
|
||||
ROWS+=("${f}"$'\t'"${aname}")
|
||||
key="${aname} <${aemail}>"
|
||||
G_FILES["$key"]+="${f}"$'\n'
|
||||
G_NAME["$key"]="$aname"; G_EMAIL["$key"]="$aemail"; G_DEV["$key"]="$adev"
|
||||
G_NAME["$key"]="$aname"; G_EMAIL["$key"]="$aemail"
|
||||
done < <(git diff --cached --name-only -- raw/)
|
||||
|
||||
ts="$(date +%Y-%m-%dT%H:%M:%S%z)"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue