Files
PTSRaiAgent/docs/dev/GITEA_API.md
T

59 lines
2.7 KiB
Markdown
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.
# Gitea API — шпаргалка
> **⛔ Кириллица в JSON:** `curl -d '{...}'` ломает кодировку. Тело собирать в файл (python/node `json.dumps(..., ensure_ascii=False)`) и слать через `--data-binary @file` с `Content-Type: application/json; charset=utf-8`.
> **⛔ Обратные кавычки:** markdown-тексты не передавать внутри `"..."` в shell — бэктики выполнятся как команды. Только через файл / heredoc `<<'EOF'`.
```bash
set -a; . ./.env 2>/dev/null; set +a # GITEA_URL, GITEA_REPO, GITEA_USER, GITEA_TOKEN
API="$GITEA_URL/api/v1/repos/$GITEA_REPO"
H=(-H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/json; charset=utf-8")
```
## Issues
```bash
# Мои открытые
curl -s "${H[@]}" "$API/issues?state=open&type=issues&assigned_by=$GITEA_USER"
# Открытые по зоне
curl -s "${H[@]}" "$API/issues?state=open&type=issues&labels=core"
# Создать (тело из файла)
python3 - <<'EOF' > /tmp/issue.json
import json; print(json.dumps({"title":"...","body":open("body.md").read(),"labels":[1,2],"milestone":1}, ensure_ascii=False))
EOF
curl -s -X POST "${H[@]}" "$API/issues" --data-binary @/tmp/issue.json
# Дописать лог выполнения в тело
curl -s "${H[@]}" "$API/issues/NN" | python3 -c '
import json,sys,datetime; b=json.load(sys.stdin)["body"]
b+=f"\n### {datetime.date.today()}\n- **Что сделано:** ...\n- **Результат:** ...\n"
print(json.dumps({"body":b},ensure_ascii=False))' > /tmp/patch.json
curl -s -X PATCH "${H[@]}" "$API/issues/NN" --data-binary @/tmp/patch.json >/dev/null
# Комментарий
curl -s -X POST "${H[@]}" "$API/issues/NN/comments" --data-binary @/tmp/comment.json
```
## Зависимости (только через API)
```bash
# #NN зависит от #MM
curl -s -X POST "${H[@]}" "$API/issues/NN/dependencies" \
-d "{\"owner\":\"${GITEA_REPO%%/*}\",\"repo\":\"${GITEA_REPO##*/}\",\"index\":MM}"
curl -s "${H[@]}" "$API/issues/NN/dependencies"
```
## Pull Requests
```bash
# base = dev, не main
curl -s -X POST "${H[@]}" "$API/pulls" --data-binary @/tmp/pr.json # {"head":"feat/NN-slug","base":"dev","title":"...","body":"Closes #NN ..."}
# Смержить (после зелёного CI)
curl -s -X POST "${H[@]}" "$API/pulls/PP/merge" -d '{"Do":"merge","delete_branch_after_merge":true}'
# Статусы CI коммита
curl -s "${H[@]}" "$API/commits/<sha>/statuses"
```
## Ветки
```bash
git ls-remote --heads origin <ветка> # пусто = PR уже смержен, не пушить
B="feat/NN-slug"; curl -s -X DELETE "${H[@]}" "$API/branches/${B//\//%2F}"
```