From 7977e2562c6f5e7c23ec3e72559a635506a09fa1 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 6 Apr 2026 12:14:49 +0000 Subject: [PATCH] fix: fix: disinto init re-run silently drops HUMAN_TOKEN when token already exists (#275) Apply delete-then-recreate pattern for human token (matching admin token in PR #274). Forge/Forgejo only returns sha1 at creation time; listing returns no sha1, causing HUMAN_TOKEN to be silently empty on re-runs when token name already exists. Co-Authored-By: Claude Sonnet 4.6 --- bin/disinto | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bin/disinto b/bin/disinto index 3d0dd9e..67bdf17 100755 --- a/bin/disinto +++ b/bin/disinto @@ -785,6 +785,19 @@ setup_forge() { # Get or create human user token local human_token if curl -sf --max-time 5 "${forge_url}/api/v1/users/${human_user}" >/dev/null 2>&1; then + # Delete existing human token if present (token sha1 is only returned at creation time) + local existing_human_token_id + existing_human_token_id=$(curl -sf \ + -u "${human_user}:${human_pass}" \ + "${forge_url}/api/v1/users/${human_user}/tokens" 2>/dev/null \ + | jq -r '.[] | select(.name == "disinto-human-token") | .id') || existing_human_token_id="" + if [ -n "$existing_human_token_id" ]; then + curl -sf -X DELETE \ + -u "${human_user}:${human_pass}" \ + "${forge_url}/api/v1/users/${human_user}/tokens/${existing_human_token_id}" >/dev/null 2>&1 || true + fi + + # Create human token (fresh, so sha1 is returned) human_token=$(curl -sf -X POST \ -u "${human_user}:${human_pass}" \ -H "Content-Type: application/json" \ @@ -792,14 +805,6 @@ setup_forge() { -d '{"name":"disinto-human-token","scopes":["all"]}' 2>/dev/null \ | jq -r '.sha1 // empty') || human_token="" - if [ -z "$human_token" ]; then - # Token might already exist — try listing - human_token=$(curl -sf \ - -u "${human_user}:${human_pass}" \ - "${forge_url}/api/v1/users/${human_user}/tokens" 2>/dev/null \ - | jq -r '.[0].sha1 // empty') || human_token="" - fi - if [ -n "$human_token" ]; then # Store human token in .env if grep -q '^HUMAN_TOKEN=' "$env_file" 2>/dev/null; then