Files
APAW/scripts/test-gitea.sh
swp 11a2741f46 feat: add Gitea API test scripts
- 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'
2026-04-04 01:28:49 +01:00

203 lines
8.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Test Gitea API Integration
# Run this script after setting GITEA_TOKEN environment variable
echo "=== Gitea API Test Script ==="
echo ""
# Check if GITEA_TOKEN is set
if [ -z "$GITEA_TOKEN" ]; then
echo "❌ GITEA_TOKEN not set!"
echo ""
echo "To get your token:"
echo "1. Run: ./scripts/create-gitea-token.sh <username> <password>"
echo "2. Or create manually at: https://git.softuniq.eu/user/settings/applications"
echo "3. Export it: export GITEA_TOKEN=your_token_here"
echo ""
echo "Note: Use 'all' scope for full access"
echo ""
exit 1
fi
API_URL="https://git.softuniq.eu/api/v1"
OWNER="UniqueSoft"
REPO="APAW"
echo "📦 Testing API: $API_URL"
echo "📁 Repository: $OWNER/$REPO"
echo ""
# 1. Test authentication
echo "🔐 Testing authentication..."
WHOAMI=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$API_URL/user")
if echo "$WHOAMI" | grep -q '"login"'; then
LOGIN=$(echo "$WHOAMI" | sed 's/.*"login":"\([^"]*\)".*/\1/')
echo "✅ Authenticated as: $LOGIN"
else
echo "❌ Authentication failed"
echo "Response: $WHOAMI"
exit 1
fi
echo ""
# 2. Create Milestone
echo "🎯 Creating milestone..."
DUE_DATE=$(date -d "+7 days" -Iseconds 2>/dev/null || date -v+7d -Iseconds 2>/dev/null || date -Iseconds)
MILESTONE_RESPONSE=$(curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"title\": \"Pipeline Integration Test\",
\"description\": \"Testing agent-manager integration with Gitea API\",
\"due_on\": \"$DUE_DATE\"
}" \
"$API_URL/repos/$OWNER/$REPO/milestones")
MILESTONE_ID=$(echo "$MILESTONE_RESPONSE" | sed 's/.*"id":\([0-9]*\).*/\1/' | head -1)
if [ -n "$MILESTONE_ID" ] && [ "$MILESTONE_ID" != "" ]; then
echo "✅ Milestone created: ID=$MILESTONE_ID"
else
echo "❌ Failed to create milestone"
echo "Response: $MILESTONE_RESPONSE"
exit 1
fi
echo ""
# 3. Create Issues with checklists
echo "📝 Creating issues..."
# Issue 1
echo " Creating issue 1..."
ISSUE1_BODY='## Описание
Настроить Gitea API клиент для работы с репозиторием.
## Чеклист
- [x] Создать GiteaClient класс
- [x] Добавить методы для Issues API
- [x] Добавить методы для Labels API
- [x] Добавить методы для Milestones API
- [ ] Написать документацию
## Примечания
Базовая функциональность готова, нужно дописать JSDoc комментарии.'
ISSUE1_RESPONSE=$(curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"title\": \"Setup Gitea Client\",
\"body\": $(echo "$ISSUE1_BODY" | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}' | tr -d '\n' | sed 's/\\n$//'),
\"milestone\": $MILESTONE_ID
}" \
"$API_URL/repos/$OWNER/$REPO/issues")
ISSUE1_NUM=$(echo "$ISSUE1_RESPONSE" | sed 's/.*"number":\([0-9]*\).*/\1/' | head -1)
if [ -n "$ISSUE1_NUM" ]; then
echo "✅ Issue #$ISSUE1_NUM: Setup Gitea Client"
else
echo "❌ Failed to create issue 1"
echo "Response: $ISSUE1_RESPONSE"
fi
# Issue 2
echo " Creating issue 2..."
ISSUE2_BODY='## Описание
Реализовать оркестратор пайплайна для управления workflow.
## Чеклист
- [x] Создать класс PipelineRunner
- [x] Добавить маршрутизацию по статусам
- [x] Интегрировать логирование в Gitea
- [x] Добавить подсчёт эффективности
- [ ] Добавить обработку ошибок
- [ ] Добавить retry механизм
## Примечания
Основная логика готова, нужно улучшить обработку edge cases.'
ISSUE2_RESPONSE=$(curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"title\": \"Implement Pipeline Runner\",
\"body\": $(echo "$ISSUE2_BODY" | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}' | tr -d '\n' | sed 's/\\n$//'),
\"milestone\": $MILESTONE_ID
}" \
"$API_URL/repos/$OWNER/$REPO/issues")
ISSUE2_NUM=$(echo "$ISSUE2_RESPONSE" | sed 's/.*"number":\([0-9]*\).*/\1/' | head -1)
if [ -n "$ISSUE2_NUM" ]; then
echo "✅ Issue #$ISSUE2_NUM: Implement Pipeline Runner"
fi
# Issue 3
echo " Creating issue 3..."
ISSUE3_BODY='## Описание
Протестировать интеграцию с Gitea API.
## Чеклист
- [x] Unit тесты для GiteaClient
- [x] Integration тесты для PipelineRunner
- [ ] E2E тесты с реальным API
- [ ] Performance тесты
## Примечания
Требуется настройка CI/CD для автоматического запуска тестов.'
ISSUE3_RESPONSE=$(curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"title\": \"Test Integration\",
\"body\": $(echo "$ISSUE3_BODY" | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}' | tr -d '\n' | sed 's/\\n$//'),
\"milestone\": $MILESTONE_ID
}" \
"$API_URL/repos/$OWNER/$REPO/issues")
ISSUE3_NUM=$(echo "$ISSUE3_RESPONSE" | sed 's/.*"number":\([0-9]*\).*/\1/' | head -1)
if [ -n "$ISSUE3_NUM" ]; then
echo "✅ Issue #$ISSUE3_NUM: Test Integration"
fi
echo ""
# 4. Add comments
if [ -n "$ISSUE1_NUM" ]; then
echo "💬 Adding comments to issue #$ISSUE1_NUM..."
curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"body": "## ✅ Выполнено\n\n- Базовая структура классов\n- Интеграция с Gitea API\n- Обработка ошибок\n\n## 🔄 В процессе\n\n- Документация\n- Тестирование"}' \
"$API_URL/repos/$OWNER/$REPO/issues/$ISSUE1_NUM/comments" > /dev/null
curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"body": "## 📋 Технические детали\n\n### Используемые API endpoints\n\n```\nPOST /repos/{owner}/{repo}/milestones\nPOST /repos/{owner}/{repo}/issues\nPOST /repos/{owner}/{repo}/issues/{n}/comments\nGET /repos/{owner}/{repo}/labels\n```\n\n### Структура данных\n\n```typescript\ninterface Milestone {\n id: number\n title: string\n state: \"open\" | \"closed\"\n}\n```"}' \
"$API_URL/repos/$OWNER/$REPO/issues/$ISSUE1_NUM/comments" > /dev/null
curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"body": "## ✅ Результаты тестирования\n\n| Компонент | Статус |\n|-----------|--------|\n| GiteaClient | ✅ Работает |\n| PipelineRunner | ✅ Работает |\n| Label API | ✅ Работает |\n| Milestone API | ✅ Работает |\n| Comment API | ✅ Работает |\n\n### Метрики\n\n- **Время создания milestone**: ~200ms\n- **Время создания issue**: ~150ms\n- **Время добавления comment**: ~100ms\n\n### Выводы\n\nИнтеграция с Gitea API 1.21+ работает корректно."}' \
"$API_URL/repos/$OWNER/$REPO/issues/$ISSUE1_NUM/comments" > /dev/null
echo "✅ Comments added"
fi
echo ""
# 5. Summary
echo "=========================================="
echo "📊 Test Results"
echo "=========================================="
echo "✅ Milestone created: ID=$MILESTONE_ID"
echo "✅ Issues created: 3"
if [ -n "$ISSUE1_NUM" ]; then echo " - #$ISSUE1_NUM: Setup Gitea Client"; fi
if [ -n "$ISSUE2_NUM" ]; then echo " - #$ISSUE2_NUM: Implement Pipeline Runner"; fi
if [ -n "$ISSUE3_NUM" ]; then echo " - #$ISSUE3_NUM: Test Integration"; fi
echo "✅ Comments added: 3 per issue (to first issue)"
echo ""
echo "🔗 View at:"
echo " https://git.softuniq.eu/$OWNER/$REPO/milestone/$MILESTONE_ID"
echo ""