Files
tgit/docs/dev/GITEA_API.md

68 lines
3.1 KiB
Markdown
Raw Permalink 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 — шпаргалка
Gitea — основной репозиторий и трекер: [`HSE/tgit`](https://gitea.24studbank.ru/HSE/tgit). SourceCraft — зеркало (ADR-010).
> **Кириллица в JSON:** не собирать тело в `curl -d '{...}'` руками — ломается кодировка и экранирование.
> Тело собираем в Python (`json.dumps(..., ensure_ascii=False)`) в файл и отправляем `--data @file.json`.
```bash
set -a; . ./.env; set +a # GITEA_URL, GITEA_TOKEN, GITEA_USER, GITEA_REPO
G="$GITEA_URL/api/v1/repos/$GITEA_REPO"
A="Authorization: token $GITEA_TOKEN"
J="Content-Type: application/json; charset=utf-8"
alias curl='curl --retry 4 --retry-all-errors --retry-delay 2'
```
> Сервер иногда рвёт SSH (`Connection closed … port 2222`) и медленно отвечает на запись — повторять, перед повторным
> POST проверять, не создалась ли сущность.
## Issues
```bash
# мои открытые
curl -s -H "$A" "$G/issues?state=open&type=issues&assigned_by=$GITEA_USER"
# создать: {"title","body","labels":[id…],"milestone":id,"assignees":["$GITEA_USER"]}
curl -s -X POST -H "$A" -H "$J" "$G/issues" --data @issue.json
# обновить тело / закрыть
curl -s -X PATCH -H "$A" -H "$J" "$G/issues/NN" --data @body.json # {"body": "..."}
curl -s -X PATCH -H "$A" -H "$J" "$G/issues/NN" -d '{"state":"closed"}'
# комментарий
curl -s -X POST -H "$A" -H "$J" "$G/issues/NN/comments" --data @comment.json # {"body": "..."}
# метки и вехи — по id
curl -s -H "$A" "$G/labels"
curl -s -H "$A" "$G/milestones?state=all"
```
## Зависимости (только через API, не текстом в теле)
```bash
# #NN зависит от #MM (MM блокирует NN)
curl -s -X POST -H "$A" -H "$J" "$G/issues/NN/dependencies" -d "{\"owner\":\"${GITEA_REPO%%/*}\",\"repo\":\"${GITEA_REPO##*/}\",\"index\":MM}"
curl -s -H "$A" "$G/issues/NN/dependencies"
```
## Pull requests
```bash
# PR в dev (не в main!); тело — с "Closes #NN"
curl -s -X POST -H "$A" -H "$J" "$G/pulls" --data @pr.json # {"head":"feat/NN-slug","base":"dev","title":"…","body":"…"}
# ветка ещё есть? пусто → PR смержен, не пушить
git ls-remote --heads origin <ветка>
```
## Зеркало в SourceCraft
```bash
curl -s -H "$A" "$G/push_mirrors" # статус: last_update, last_error
curl -s -X POST -H "$A" "$G/push_mirrors-sync" # синхронизировать сейчас
```
Зеркало — HTTPS (`git.sourcecraft.dev`) с токеном SourceCraft: SSH-зеркала на этом Gitea отключены.
Синхронизация — на каждый push + раз в 8 часов. Зеркало перезаписывает SourceCraft целиком (`--mirror`):
**в SourceCraft ничего не пушим и не мержим** — изменения пропадут.