Author SHA1 Message Date
ElebobaandClaude Opus 5.5 9e1d6322b6 feat(bot): кнопка «🚀 Закоммитить» прямо в папке
При непустом черновике в папке — «🚀 Закоммитить · N»: нет сообщения → спрашивает его и
сразу показывает подтверждение пуша; есть → сразу подтверждение. На подтверждении —
«✏️ Изменить сообщение». Раньше Push был спрятан в «🧾 Черновик» → «💬» → «🚀».

Refs #9

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 00:06:52 +03:00
ElebobaandClaude Opus 5.5 0f27f405a7 chore: локальный запуск без Docker и SourceCraft; fix: относительный GIT_CLONE_DIR
- make demo-repo: локальный bare-репозиторий загрузок из infra/uploads-template
- make run: бот на этой машине (SQLite, настройки из .env)
- fix: при относительном clone_dir клон уезжал в data/data/uploads (git clone
  запускается из родительской папки) — путь теперь абсолютный; тест на это
- data/ в .gitignore

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 19:53:40 +03:00
8 changed files with 96 additions and 10 deletions
+2 -1
View File
@@ -24,5 +24,6 @@ build/
.claude/worktrees/
.DS_Store
# local SQLite DB (bot without Docker)
# local run without Docker: SQLite DB, uploads clone, demo repo
*.db
data/
+16 -1
View File
@@ -1,4 +1,4 @@
.PHONY: install lint fmt typecheck test cov up down logs ps
.PHONY: install lint fmt typecheck test cov up down logs ps run demo-repo
install:
uv sync
@@ -30,3 +30,18 @@ logs:
ps:
docker compose ps
# Run the bot on this machine without Docker: SQLite (./tgit.db) and the settings from .env
run:
uv run python -m app
# A local uploads repo seeded from the template — try the bot without SourceCraft:
# make demo-repo → put the printed GIT_UPLOADS_URL into .env → make run
DEMO_REPO := $(CURDIR)/data/demo-uploads.git
demo-repo:
@test ! -e $(DEMO_REPO) || { echo "$(DEMO_REPO) already exists"; exit 1; }
@rm -rf data/demo-seed && mkdir -p data && cp -r infra/uploads-template data/demo-seed
@cd data/demo-seed && git init -q -b main && git add -A \
&& git -c user.name=tgit-bot -c user.email=tgit-bot@users.noreply.tgit commit -qm "init: uploads template"
@git clone -q --bare data/demo-seed $(DEMO_REPO) && rm -rf data/demo-seed
@echo "GIT_UPLOADS_URL=$(DEMO_REPO)"
+34 -7
View File
@@ -59,6 +59,7 @@ class Act(StrEnum):
PUSH = "ps"
PUSH_GO = "pg"
PUSH_FORCE = "pf"
COMMIT = "cm"
class CommitCb(CallbackData, prefix="c"):
@@ -179,8 +180,10 @@ def render_dir(
kb.button(text=t.new_dir, callback_data=CommitCb(a=Act.NEW_DIR))
sizes.append(2)
if draft_count:
# the main action once something is staged — right in the folder, not two screens deep
kb.button(text=t.commit_button.format(count=draft_count), callback_data=CommitCb(a=Act.COMMIT))
kb.button(text=t.draft_button.format(count=draft_count), callback_data=CommitCb(a=Act.DRAFT))
sizes.append(1)
sizes += [1, 1]
if path:
kb.button(text=t.up, callback_data=CommitCb(a=Act.UP))
sizes.append(1)
@@ -260,6 +263,14 @@ def build_router(
kb.adjust(1)
return text, kb.as_markup()
def confirm_screen(draft: DraftView) -> tuple[str, InlineKeyboardMarkup]:
builder = InlineKeyboardBuilder()
builder.button(text=t.push_go, callback_data=CommitCb(a=Act.PUSH_GO))
builder.button(text=t.edit_message, callback_data=CommitCb(a=Act.MESSAGE))
builder.button(text=texts.menu.back, callback_data=CommitCb(a=Act.TO_DIR))
builder.adjust(1)
return t.push_confirm.format(summary=summary(draft), message=draft.message), builder.as_markup()
def summary(draft: DraftView) -> str:
ops = {ChangeOp.ADD: t.op_add, ChangeOp.MODIFY: t.op_modify, ChangeOp.DELETE: t.op_delete}
return "\n".join(f"{ops[c.op]} /{c.path}" for c in draft.changes)
@@ -466,17 +477,28 @@ def build_router(
return
case Act.MESSAGE:
await state.set_state(Flow.message)
await state.update_data(commit_then_push=False)
await msg.edit_text(t.ask_message, reply_markup=to_dir_keyboard(texts))
case Act.PUSH:
draft = await drafts.get(uid)
if draft is None or not draft.changes or not draft.message:
await query.answer()
return
builder = InlineKeyboardBuilder()
builder.button(text=t.push_go, callback_data=CommitCb(a=Act.PUSH_GO))
builder.button(text=texts.menu.back, callback_data=CommitCb(a=Act.DRAFT))
confirm = t.push_confirm.format(summary=summary(draft), message=draft.message)
await msg.edit_text(confirm, reply_markup=builder.as_markup())
confirm, markup = confirm_screen(draft)
await msg.edit_text(confirm, reply_markup=markup)
case Act.COMMIT:
draft = await drafts.get(uid)
if draft is None or not draft.changes:
await query.answer()
return
if draft.message:
confirm, markup = confirm_screen(draft)
await msg.edit_text(confirm, reply_markup=markup)
else:
# ask for the message, then go straight to the push confirmation
await state.set_state(Flow.message)
await state.update_data(commit_then_push=True)
await msg.edit_text(t.ask_message, reply_markup=to_dir_keyboard(texts))
case Act.PUSH_GO | Act.PUSH_FORCE:
await query.answer()
await do_push(msg, state, member, overwrite=callback_data.a is Act.PUSH_FORCE)
@@ -549,7 +571,12 @@ def build_router(
return
await drafts.set_message(member.tg_id, text)
await state.set_state(None)
screen, kb = await draft_screen(state, member.tg_id)
draft = await drafts.get(member.tg_id)
if (await state.get_data()).get("commit_then_push") and draft is not None and draft.changes:
await state.update_data(commit_then_push=False)
screen, kb = confirm_screen(draft)
else:
screen, kb = await draft_screen(state, member.tg_id)
await message.answer(screen, reply_markup=kb)
@router.message(Flow.content, F.text | F.document)
+2 -1
View File
@@ -47,7 +47,8 @@ class CommitInfo:
class UploadsRepo:
def __init__(self, settings: GitSettings) -> None:
self._s = settings
self._dir = settings.clone_dir
# absolute: git clone runs from the parent dir, a relative path would land one level deeper
self._dir = settings.clone_dir.resolve()
self._lock = asyncio.Lock()
self._fetched_at: float | None = None
self._key_path = self._materialize_key()
+2
View File
@@ -110,6 +110,8 @@ class CommitTexts(_Strict):
ask_message: str
bad_message: str
push_button: str
commit_button: str
edit_message: str
push_confirm: str
push_go: str
pushing: str
+2
View File
@@ -113,6 +113,8 @@ commit:
ask_message: "Сообщение коммита: до 200 символов, первая строка — до 72."
bad_message: "Сообщение: 1–200 символов, первая строка — до 72. Пришлите другое."
push_button: "🚀 Push"
commit_button: "🚀 Закоммитить · {count}"
edit_message: "✏️ Изменить сообщение"
push_confirm: |-
Запушить в main?
+27
View File
@@ -63,3 +63,30 @@ async def test_message_then_push_lands_in_remote(tg: TgClient, texts: Texts, rem
tg.session.requests.clear()
await tg.send(ADMIN, texts.menu.commit)
assert not any(label.startswith("🧾") for label in labels(tg.session.sent(SendMessage)[-1].reply_markup))
async def test_commit_button_in_folder_asks_message_then_confirms(
tg: TgClient, texts: Texts, remote: Path, tmp_path: Path
) -> None:
t = texts.commit
await tg.send(ADMIN, texts.menu.commit)
await tg.press(ADMIN, cb(Act.NEW_FILE))
await tg.send(ADMIN, "quick.txt")
await tg.send(ADMIN, "быстро")
folder = tg.session.sent(SendMessage)[-1]
assert t.commit_button.format(count=1) in labels(folder.reply_markup)
await tg.press(ADMIN, cb(Act.COMMIT))
assert tg.session.sent(EditMessageText)[-1].text == t.ask_message
await tg.send(ADMIN, "feat: быстрый коммит")
confirm = tg.session.sent(SendMessage)[-1]
assert confirm.text.startswith("Запушить в main?") and "feat: быстрый коммит" in confirm.text
assert labels(confirm.reply_markup) == [t.push_go, t.edit_message, texts.menu.back]
await tg.press(ADMIN, cb(Act.PUSH_GO))
assert tg.session.sent(EditMessageText)[-1].text.startswith("✅ Запушено: ")
clone = tmp_path / "verify2"
git(tmp_path, "clone", "-q", str(remote), str(clone))
assert (clone / "quick.txt").read_text(encoding="utf-8") == "быстро"
+11
View File
@@ -83,3 +83,14 @@ async def test_unreachable_remote(tmp_path: Path) -> None:
broken = UploadsRepo(GitSettings(uploads_url=str(tmp_path / "missing.git"), clone_dir=tmp_path / "c3"))
with pytest.raises(GitError, match="clone"):
await broken.refresh()
async def test_relative_clone_dir(remote: Path, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
from app.config import GitSettings
monkeypatch.chdir(tmp_path)
relative = UploadsRepo(GitSettings(uploads_url=str(remote), clone_dir=Path("data/uploads")))
await relative.refresh()
assert (tmp_path / "data" / "uploads" / ".git").is_dir()
assert "README.md" in [e.name for e in await relative.list_dir()]