我构建了一个 API,读取你的 Git 混乱并写出完美的提交(+ 捕获你泄露的 API 密钥)
Source: Dev.to
我构建的内容
推动我构建它的问题
提交信息很重要——它们是帮助我们(以及团队成员)了解代码库中发生了什么的面包屑。然而,编写好的提交信息是一件麻烦事。
我发现自己在做以下两件事之一:
- 每天只提交一两次,使用懒散的消息如 “fix stuff” 或 “updates”。
- 为每一个小改动花费大量时间去撰写 “完美” 的提交信息。
这两种做法都不可持续。我需要一种能够理解我的改动并为我生成有意义提交的工具。
GitSense API 概览
GitSense API 是一个面向生产环境的开发者工具包,解决了提交信息的问题。其工作流程非常简单:
- 一次性初始化 – 在 API 中注册你的项目。
- 单条命令 – 发送
git status,获取智能提交建议。 - 复制并执行 – 直接使用生成的 git 命令。
除了提交信息,API 还充当个人安全守卫,在代码进入仓库之前扫描暴露的密钥和漏洞。
它提供的数据服务
1) 智能提交智能
- 分析变更文件并按用途(文档、配置、功能、工具)进行分类。
- 生成符合 Conventional Commit 规范的语义化提交信息。
- 提供按逻辑功能分组的可直接执行的 git 命令。
2) 安全漏洞检测
- 扫描文件内容,查找暴露的 API 密钥(AWS、GitHub、OpenAI、Stripe 等)。
- 检测硬编码的密码和数据库连接字符串。
- 提供带有具体命令的可操作修复步骤。
3) 项目分析
- 跟踪提交模式和仓库分析历史。
- 维护项目元数据和建议历史。
- 提供对开发工作流的洞察。
实际影响
使用 GitSense 前
git add .
git commit -m "fix stuff" # 😅 我们都有过这种经历
使用 GitSense 后
# 一次 API 调用即可得到以下内容:
git add HACKATHON_SUBMISSION.md
git commit -m 'feat: add hackathon submission documentation'
git add .vscode/settings.json
git commit -m 'chore: configure VS Code workspace settings'
git add docs/API.md
git commit -m 'docs: update project documentation'
为什么这很重要
1) 个人开发者
- 每天节省 15–20 分钟的提交信息编写时间。
- 创建专业的 git 历史,在代码评审时留下好印象。
- 在问题发生前防止安全灾难。
2) 开发团队
- 在整个团队中统一提交信息格式。
- 让 git 历史对调试和功能追踪更有价值。
- 减少共享仓库中的安全漏洞。
3) 项目维护者
- 从语义化提交中自动生成变更日志。
- 用描述性的提交信息提升代码评审效率。
- 为安全合规提供审计轨迹。
GitSense API 将 git 提交从一项必要的琐事转变为自动化、智能化的过程,为你的开发工作流带来真实价值。
API 文档
基础 URL
可用端点
POST /analyze-project– 初始化项目分析。POST /generate_smart_commits– 生成智能提交建议。GET /project_lookup– 获取项目状态和历史。POST /Security_Analysis– 扫描安全漏洞。POST /generate_commit_suggestion– 基础提交信息生成。
1. 初始化项目分析
端点: POST https://x8ki-letl-twmt.n7.xano.io/api:78VRpQ6j/analyze-project
# 进入你的项目目录
cd /path/to/your/project
# 向 GitSense API 注册项目
curl -X POST "https://x8ki-letl-twmt.n7.xano.io/api:78VRpQ6j/analyze-project" \
-H "Content-Type: application/json" \
-d "{\"repo_path\": \"$(pwd)\"}"
预期响应
{
"status": "created",
"project_id": 3,
"message": "New project created successfully.",
"repo_path": "/path/to/your/project"
}
2. 生成智能提交信息
端点: POST https://x8ki-letl-twmt.n7.xano.io/api:78VRpQ6j/generate_smart_commits
# 从你的项目目录运行
cd /path/to/your/project
# 获取智能提交建议(将 project_id 替换为实际 ID)
curl -X POST "https://x8ki-letl-twmt.n7.xano.io/api:78VRpQ6j/generate_smart_commits" \
-H "Content-Type: application/json" \
-d "{\"project_id\": 3, \"git_status\": \"$(git status --porcelain)\"}"
预期响应
{
"suggested_commits": [
{
"files": [".vscode/settings.json"],
"git_add": "git add .vscode/settings.json",
"git_commit": "git commit -m 'chore: configure VS Code workspace settings'",
"feature": "development_environment",
"type": "tooling"
},
{
"files": ["README.md", "docs/API.md"],
"git_add": "git add README.md docs/API.md",
"git_commit": "git commit -m 'docs: update project documentation'",
"feature": "documentation",
"type": "documentation"
}
],
"total_groups": 2,
"total_files": 6,
"analysis": "Files categorized by feature and purpose"
}
3. 检查项目状态
端点: GET https://x8ki-letl-twmt.n7.xano.io/api:78VRpQ6j/project_lookup
# 获取项目详情和历史
curl -X GET "https://x8ki-letl-twmt.n7.xano.io/api:78VRpQ6j/project_lookup?repo_path=$(pwd)" \
-H "Content-Type: application/json"
预期响应
{
"project_id": 3,
"repo_path": "/path/to/your/project",
"last_analyzed": 1765775353612,
"commit_count": 0,
"recent_suggestions": [],
"status": "success"
}
4. 安全漏洞扫描
端点: POST https://x8ki-letl-twmt.n7.xano.io/api:78VRpQ6j/Security_Analysis
# 扫描文件内容中的安全问题
curl -X POST "https://x8ki-letl-twmt.n7.xano.io/api:78VRpQ6j/Security_Analysis" \
-H "Content-Type: application/json" \
-d "{\"project_id\": 3, \"file_contents\": \"$(cat .env 2>/dev/null || echo 'const apiKey = \\\"sk-test123\\\";')\"}"
预期响应
{
"security_issues": ["Database Connection URL", "Hardcoded Password/Secret"],
"risk_level": "medium",
"suggestions": [
"Remove or use environment variables for Database Connection URL",
"Remove or use environment variables for Hardcoded Password/Secret"
],
"total_issues": 2,
"scan_timestamp": "2025-12-15T05:09:55.688Z"
}
5. 基础提交建议
端点: POST https://x8ki-letl-twmt.n7.xano.io/api:78VRpQ6j/generate_commit_suggestion
(为简洁起见,后续细节已省略。)