- create-gitea-token.sh: Create API token from username/password - full-gitea-test.sh: Complete test creating milestone, issues, comments - test-gitea.sh: Updated with correct scope names (all, read:*, write:*) Test results: ✅ Token creation via Basic Auth ✅ Milestone creation (ID=42) ✅ 3 issues with checklists created ✅ 3 comments added with progress Gitea API scopes: 'all' for full access, or granular like 'read:issue', 'write:issue'
66 lines
1.8 KiB
Bash
Executable File
66 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Create Gitea API token using Basic Auth
|
|
# Usage: ./scripts/create-gitea-token.sh <username> <password>
|
|
|
|
API_URL="https://git.softuniq.eu/api/v1"
|
|
|
|
if [ -z "$1" ] || [ -z "$2" ]; then
|
|
echo "Usage: $0 <username> <password>"
|
|
echo ""
|
|
echo "Example: $0 NW mypassword"
|
|
echo ""
|
|
echo "This will create a new API token for the user."
|
|
exit 1
|
|
fi
|
|
|
|
USERNAME="$1"
|
|
PASSWORD="$2"
|
|
TOKEN_NAME="Pipeline Test $(date +%Y%m%d%H%M%S)"
|
|
|
|
echo "=== Gitea Token Creation ==="
|
|
echo ""
|
|
echo "👤 Username: $USERNAME"
|
|
echo "🔑 Token name: $TOKEN_NAME"
|
|
echo ""
|
|
|
|
# Create token using Basic Auth
|
|
echo "🔐 Creating token..."
|
|
RESPONSE=$(curl -s -X POST \
|
|
-u "$USERNAME:$PASSWORD" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"name\":\"$TOKEN_NAME\",\"scopes\":[\"all\"]}" \
|
|
"$API_URL/users/$USERNAME/tokens")
|
|
|
|
# Check for error
|
|
if echo "$RESPONSE" | grep -q '"message"'; then
|
|
ERROR=$(echo "$RESPONSE" | sed 's/.*"message":"\([^"]*\)".*/\1/')
|
|
echo "❌ Failed to create token: $ERROR"
|
|
echo ""
|
|
echo "Response: $RESPONSE"
|
|
exit 1
|
|
fi
|
|
|
|
# Extract token
|
|
TOKEN=$(echo "$RESPONSE" | sed 's/.*"sha1":"\([^"]*\)".*/\1/' | head -1)
|
|
TOKEN_ID=$(echo "$RESPONSE" | sed 's/.*"id":\([0-9]*\).*/\1/' | head -1)
|
|
|
|
if [ -n "$TOKEN" ] && [ ${#TOKEN} -gt 10 ]; then
|
|
echo "✅ Token created successfully!"
|
|
echo ""
|
|
echo "📋 Token details:"
|
|
echo " ID: $TOKEN_ID"
|
|
echo " Name: $TOKEN_NAME"
|
|
echo " Token: $TOKEN"
|
|
echo ""
|
|
echo "💡 Save this token for future use:"
|
|
echo ""
|
|
echo " export GITEA_TOKEN=$TOKEN"
|
|
echo ""
|
|
echo " # Add to ~/.bashrc for persistence:"
|
|
echo " echo 'export GITEA_TOKEN=$TOKEN' >> ~/.bashrc"
|
|
echo ""
|
|
else
|
|
echo "❌ Failed to extract token from response"
|
|
echo "Response: $RESPONSE"
|
|
exit 1
|
|
fi |