fix: fix: hire-an-agent creates .profile repo under wrong user (dev-bot instead of target agent) (#214)
This commit is contained in:
parent
dd6937e997
commit
68fdc898df
1 changed files with 13 additions and 51 deletions
50
bin/disinto
50
bin/disinto
|
|
@ -2717,46 +2717,12 @@ disinto_hire_an_agent() {
|
||||||
repo_exists=true
|
repo_exists=true
|
||||||
echo " Repo '${agent_name}/.profile' already exists"
|
echo " Repo '${agent_name}/.profile' already exists"
|
||||||
else
|
else
|
||||||
# Get user token for creating repo
|
# Create the repo using the admin API to ensure it's created in the agent's namespace.
|
||||||
# Always try to get token using user_pass (set in Step 1 for new users, reset for existing)
|
# Using POST /api/v1/user/repos with a user token would create the repo under the
|
||||||
local user_token=""
|
# authenticated user, which could be wrong if the token belongs to a different user.
|
||||||
user_token=$(curl -sf -X POST \
|
# The admin API POST /api/v1/admin/users/{username}/repos explicitly creates in the
|
||||||
-u "${agent_name}:${user_pass}" \
|
# specified user's namespace.
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
"${forge_url}/api/v1/users/${agent_name}/tokens" \
|
|
||||||
-d "{\"name\":\".profile-repo-token\",\"scopes\":[\"repository\"]}" 2>/dev/null \
|
|
||||||
| jq -r '.sha1 // empty') || user_token=""
|
|
||||||
|
|
||||||
if [ -z "$user_token" ]; then
|
|
||||||
# Try listing existing tokens
|
|
||||||
user_token=$(curl -sf \
|
|
||||||
-u "${agent_name}:${user_pass}" \
|
|
||||||
"${forge_url}/api/v1/users/${agent_name}/tokens" 2>/dev/null \
|
|
||||||
| jq -r '.[0].sha1 // empty') || user_token=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create the repo using the user's namespace (user/repos with user_token creates in that user's namespace)
|
|
||||||
# or use admin API to create in specific user's namespace
|
|
||||||
local repo_created=false
|
|
||||||
local create_output
|
local create_output
|
||||||
|
|
||||||
if [ -n "$user_token" ]; then
|
|
||||||
# Try creating as the agent user (user token creates in that user's namespace)
|
|
||||||
create_output=$(curl -sf -X POST \
|
|
||||||
-H "Authorization: token ${user_token}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
"${forge_url}/api/v1/user/repos" \
|
|
||||||
-d "{\"name\":\".profile\",\"description\":\"${agent_name}'s .profile repo\",\"private\":true,\"auto_init\":false}" 2>&1) || true
|
|
||||||
|
|
||||||
if echo "$create_output" | grep -q '"id":\|[0-9]'; then
|
|
||||||
repo_created=true
|
|
||||||
echo " Created repo '${agent_name}/.profile'"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If user token failed or wasn't available, use admin API to create in agent's namespace
|
|
||||||
if [ "$repo_created" = false ]; then
|
|
||||||
echo " Using admin API to create repo in ${agent_name}'s namespace"
|
|
||||||
create_output=$(curl -sf -X POST \
|
create_output=$(curl -sf -X POST \
|
||||||
-u "${admin_user}:${admin_pass}" \
|
-u "${admin_user}:${admin_pass}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
|
|
@ -2764,12 +2730,8 @@ disinto_hire_an_agent() {
|
||||||
-d "{\"name\":\".profile\",\"description\":\"${agent_name}'s .profile repo\",\"private\":true,\"auto_init\":false}" 2>&1) || true
|
-d "{\"name\":\".profile\",\"description\":\"${agent_name}'s .profile repo\",\"private\":true,\"auto_init\":false}" 2>&1) || true
|
||||||
|
|
||||||
if echo "$create_output" | grep -q '"id":\|[0-9]'; then
|
if echo "$create_output" | grep -q '"id":\|[0-9]'; then
|
||||||
repo_created=true
|
|
||||||
echo " Created repo '${agent_name}/.profile' (via admin API)"
|
echo " Created repo '${agent_name}/.profile' (via admin API)"
|
||||||
fi
|
else
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$repo_created" = false ]; then
|
|
||||||
echo " Error: failed to create repo '${agent_name}/.profile'" >&2
|
echo " Error: failed to create repo '${agent_name}/.profile'" >&2
|
||||||
echo " Response: ${create_output}" >&2
|
echo " Response: ${create_output}" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue