Skip to content

Commit 45620f7

Browse files
committed
chore: squash all branches into one commit
0 parents  commit 45620f7

50 files changed

Lines changed: 5709 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
name: Test (${{ matrix.os }})
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
os:
15+
- ubuntu-latest
16+
- macos-latest
17+
- windows-latest
18+
19+
steps:
20+
- name: Check out repository
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: "3.12"
27+
28+
- name: Set up uv
29+
uses: astral-sh/setup-uv@v8.2.0
30+
with:
31+
enable-cache: true
32+
33+
- name: Sync dependencies
34+
run: uv sync --dev
35+
36+
- name: Run tests
37+
run: uv run pytest
38+
39+
- name: Run lint
40+
run: uv run ruff check
41+
42+
- name: Check POSIX installer syntax
43+
if: runner.os != 'Windows'
44+
run: bash -n install.sh
45+
46+
- name: Check Windows installer syntax
47+
if: runner.os == 'Windows'
48+
shell: pwsh
49+
run: |
50+
$tokens = $null
51+
$errors = $null
52+
[System.Management.Automation.Language.Parser]::ParseFile(
53+
(Resolve-Path "install.ps1"),
54+
[ref]$tokens,
55+
[ref]$errors
56+
) | Out-Null
57+
if ($errors.Count -gt 0) {
58+
$errors | Format-List
59+
exit 1
60+
}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__pycache__/
2+
*.pyc
3+
.venv/
4+
*.egg-info/
5+
docs/superpowers
6+

README.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# git-auto-sync
2+
3+
定时巡检多个本地 Git 仓库,对有变动的仓库**智能挑选要提交的文件 → AI 生成提交信息 → 提交并同步到远程**,并把结果推送到你选择的通知通道。
4+
5+
由参考脚本(单仓库 bash)演进而来,核心差异:多仓库、配置驱动、平台原生定时、可插拔的 AI provider 与通知通道。
6+
7+
## 工作流程
8+
9+
每个仓库依次执行:
10+
11+
1. 无变动 → 静默跳过
12+
2. **智能暂存**:把变更交给 AI,挑出该提交的文件,排除机密 / 构建产物 / 超大文件;被排除项可自动写入 `.gitignore`(AI 不可用时降级为 `git add -A`)
13+
3. AI 生成 Conventional Commits 中文提交信息(失败回退规则法)
14+
4. `git commit`
15+
5. `git pull --rebase``git push`(冲突则 abort 保持干净、标记失败、继续下一个仓库)
16+
6. 按策略汇总并通知
17+
18+
## 安装
19+
20+
### 一行安装(推荐)
21+
22+
macOS / Linux:
23+
24+
```bash
25+
curl -fsSL https://raw.githubusercontent.com/OctopusGarage/git-auto-sync/main/install.sh | bash
26+
```
27+
28+
Windows PowerShell:
29+
30+
```powershell
31+
powershell -ExecutionPolicy ByPass -c "irm https://raw.githubusercontent.com/OctopusGarage/git-auto-sync/main/install.ps1 | iex"
32+
```
33+
34+
会自动:装 [uv](https://docs.astral.sh/uv/)(若缺失)→ 下载**最新 release**`~/.git-auto-sync``uv sync` → 在 `~/.local/bin` 放全局 `git-auto-sync` 启动器(macOS/Linux 为 shell 脚本,Windows 为 `.cmd`) → 首次安装运行引导向导 `init`。重复执行即更新已有安装,已有配置时会跳过向导避免覆盖。可用 `GIT_AUTO_SYNC_VERSION=v0.1.0` 固定版本、`GIT_AUTO_SYNC_DIR` 改安装目录。
35+
36+
> 通过管道安装(无 tty)时会以 `--yes``init`:写好配置但****安装定时任务——本工具会自动提交并 push,无人值守地启用它需要你显式执行 `git-auto-sync install`
37+
38+
### 手动安装
39+
40+
```bash
41+
cd git-auto-sync
42+
uv sync # 安装依赖
43+
uv run git-auto-sync init # 引导向导(见下)
44+
# 或安装为命令行工具:
45+
uv tool install .
46+
```
47+
48+
### 引导向导(`init`)
49+
50+
```bash
51+
git-auto-sync init # 交互式:扫描目录挑选仓库、选 AI provider、配置通知、可选安装定时任务
52+
git-auto-sync init --yes # 非交互,全用默认值,不安装定时任务
53+
```
54+
55+
向导会扫描你指定的父目录(默认 `~/programming`)下**两层内**的 git 仓库供勾选,也可手动补充路径;写好 `~/.git-auto-sync/config.toml` 后即时校验。
56+
57+
### 更新
58+
59+
```bash
60+
git-auto-sync update # 下载最新 release、uv sync(定时任务无需重装,启动器路径稳定)
61+
git-auto-sync update --check # 只看有没有新版本
62+
```
63+
64+
## 配置
65+
66+
默认读取 `~/.git-auto-sync/config.toml`(可用 `--config` 指定)。所有运行时数据(配置、日志、调度产物)都在 `~/.git-auto-sync/` 下。
67+
68+
```bash
69+
mkdir -p ~/.git-auto-sync
70+
cp config.example.toml ~/.git-auto-sync/config.toml
71+
```
72+
73+
完整字段见 [`config.example.toml`](config.example.toml)。要点:
74+
75+
- `[defaults]` 提供全局默认,每个 `[[repos]]` 可逐字段覆盖。
76+
- 任意字符串值支持 `env:VARNAME`,运行时从环境变量解析,避免把密钥写进文件。
77+
- `ai_provider`:`claude-cli`(默认,复用本地 `claude` CLI)/ `anthropic-api`(读 `ANTHROPIC_API_KEY`)/ `rules`(纯规则)。任何 provider 调用失败都会自动回退到规则法,工具不会因为 AI 不可用而中断。
78+
- `notify_on`:`change_or_fail`(默认,有变动或失败才通知)/ `fail_only` / `always`
79+
80+
## 命令
81+
82+
```bash
83+
git-auto-sync init # 引导向导,生成配置
84+
git-auto-sync sync # 同步全部仓库
85+
git-auto-sync sync --repo foo # 只同步路径匹配 foo 的仓库
86+
git-auto-sync sync --dry-run # 预演:打印将要提交的内容,不落地
87+
git-auto-sync status # 列出各仓库的分支与 clean/dirty
88+
git-auto-sync config check # 校验配置文件
89+
git-auto-sync install --interval 30m # 安装平台原生定时任务
90+
git-auto-sync uninstall # 卸载定时任务
91+
git-auto-sync update # 自更新到最新 release
92+
```
93+
94+
退出码:`0` 成功,`1` 有仓库同步失败,`2` `--repo` 未匹配到任何仓库。
95+
96+
## 定时运行
97+
98+
`install` 按当前平台生成并挂载原生调度,不自带常驻进程:
99+
100+
- **macOS** → launchd(`~/Library/LaunchAgents/com.octopusgarage.git-auto-sync.plist`)
101+
- **Linux** → systemd user timer(`~/.config/systemd/user/git-auto-sync.timer`)
102+
- **Windows** → Task Scheduler(`OctopusGarage.git-auto-sync`)
103+
104+
间隔形如 `30m` / `1h` / `90s`。卸载用 `git-auto-sync uninstall`
105+
106+
## 通知通道
107+
108+
- `log`:追加时间戳块到日志文件,并打印到 stdout(审计用)
109+
- `telegram`:bot token + chat_id
110+
- `lark`:飞书自定义机器人 webhook
111+
112+
一次同步结束后,按 `notify_on` 策略向所有启用的通道推送一条汇总;单个通道发送失败不影响其他通道与主流程。
113+
114+
## 安全边界
115+
116+
无人值守自动提交的最大风险是误提交机密或垃圾。本工具的防线:
117+
118+
- AI 暂存分析排除 `.env`、私钥、证书、`node_modules`/`dist`/`build`/`__pycache__`、超大二进制、日志等;
119+
- 被排除的文件**不提交**,并(在 `ai_gitignore_autowrite=true` 时)自动写入 `.gitignore`;
120+
- 拿不准时可先 `--dry-run` 预演。
121+
122+
## 开发
123+
124+
```bash
125+
uv run pytest # 运行测试
126+
uv run ruff check . # 代码检查
127+
```
128+
129+
## License
130+
131+
MIT

config.example.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# git-auto-sync 示例配置
2+
# 复制到 ~/.git-auto-sync/config.toml 后按需修改。
3+
4+
[defaults]
5+
ai_provider = "claude-cli" # claude-cli | anthropic-api | rules
6+
ai_staging = true # AI 智能挑选要提交的文件;false 则 git add -A
7+
ai_gitignore_autowrite = true # ai_staging 下,把被忽略的文件追加进 .gitignore
8+
push = true # 提交后 pull --rebase 再 push
9+
notify_on = "change_or_fail" # change_or_fail | fail_only | always
10+
11+
# ---- 要同步的仓库,可配置多个 ----
12+
[[repos]]
13+
path = "~/programming/foo"
14+
15+
[[repos]]
16+
path = "~/programming/bar"
17+
push = false # 可逐仓库覆盖任意 defaults 字段
18+
19+
# ---- 通知通道(只有 enabled=true 的才生效) ----
20+
[notifiers.log]
21+
enabled = true
22+
path = "~/.git-auto-sync/sync.log"
23+
24+
[notifiers.telegram]
25+
enabled = false
26+
bot_token = "env:TELEGRAM_BOT_TOKEN" # env: 前缀表示从环境变量读取,避免明文写密钥
27+
chat_id = "123456"
28+
29+
[notifiers.lark]
30+
enabled = false
31+
webhook = "https://open.feishu.cn/open-apis/bot/v2/hook/xxxx"

0 commit comments

Comments
 (0)