Files
tgit/docs/dev/SOURCECRAFT_API.md
T

70 lines
2.9 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.
# SourceCraft API — шпаргалка
Справочник: [методы](https://sourcecraft.dev/portal/docs/en/api-ref/index.md) ·
[интерактивный](https://api.sourcecraft.tech/docs/index.html) ·
[swagger.json](https://api.sourcecraft.tech/sourcecraft.swagger.json)
```bash
set -a; . ./.env; set +a # SOURCECRAFT_TOKEN
R=https://api.sourcecraft.tech/repos/rogachevegorushka/tgit
H="Authorization: Bearer $SOURCECRAFT_TOKEN"
J="Content-Type: application/json"
```
> В CI вместо личного токена — предопределённая переменная `SOURCECRAFT_TOKEN`.
## Подводные камни
- `color` у метки — hex **без** `#` (`"ff7f0e"`), иначе `400 ValidationError`.
- Ответы-списки кладут элементы в разные ключи: `/issues` → `issues`, `/labels` репо → `items`, метки issue → `labels`.
- Issue адресуется номером (`issues/1`), метка — slug'ом (`size/0.5` → `size-0-5`).
- Тело issue — поле `description` (не `body`); тело комментария — `body`.
- Длинный markdown удобнее собрать в JSON-файл и передать `--data @file.json`.
## Issues
```bash
# список / одна
curl -s -H "$H" "$R/issues"
curl -s -H "$H" "$R/issues/1"
# создать (status_slug: open | inProgress | paused | closed | declined | duplicate)
curl -s -X POST -H "$H" -H "$J" "$R/issues" --data @issue.json
# issue.json: {"title": "...", "description": "...", "label_slugs": ["bot","feature","size-1"], "status_slug": "open"}
# обновить (описание, статус, исполнитель)
curl -s -X PATCH -H "$H" -H "$J" "$R/issues/1" -d '{"status_slug":"closed"}'
# комментарий
curl -s -X POST -H "$H" -H "$J" "$R/issues/1/comments" -d '{"body":"текст"}'
# метки issue: POST — добавить, PUT — заменить, DELETE — убрать
curl -s -X POST -H "$H" -H "$J" "$R/issues/1/labels" -d '{"slugs":["ci"]}'
# связь между issue
curl -s -X POST -H "$H" -H "$J" "$R/issues/2/issue_links" --data @link.json
```
## Метки репозитория
```bash
curl -s -H "$H" "$R/labels"
curl -s -X POST -H "$H" -H "$J" "$R/labels" -d '{"name":"size/1","slug":"size-1","color":"a0a0a0"}'
```
Заведены: зоны `bot` `ci` `infra` `llm` `docs` · типы `feature` `fix` `refactor` · размеры `size/0.5` `size/1` `size/2`.
## Pull requests
```bash
# создать PR в dev
curl -s -X POST -H "$H" -H "$J" "$R/pulls" --data @pr.json
# pr.json: {"title": "...", "description": "...", "source_branch": "feat/2-x", "target_branch": "dev", "publish": true}
curl -s -H "$H" "$R/pulls/1"
curl -s -H "$H" "$R/pulls/1/merge-checks"
# мерж (rebase | squash, delete_branch)
curl -s -X POST -H "$H" -H "$J" "$R/pulls/1/merge" -d '{"delete_branch": true}'
```