关于 github-ai-features-2025
面向管理代码和仓库的团队,介绍 GitHub 开发工作流与安全功能实践,涵盖主干开发、密钥保护、代码扫描、依赖审查和自动化 Agent。
主要功能
- 01主干开发实践
- 02AI 辅助密钥检测
- 03CodeQL 扫描与 Copilot Autofix
- 04用于修复缺陷和生成 PR 的 Agent
- 05依赖变更审查
适用场景
- 01规划短期分支工作流
- 02在推送前检测仓库密钥
- 03审查代码安全问题
- 04自动处理问题并创建 PR
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ josiahsiegel/ claude-plugin-marketplace --skill github-ai-features-2025安装后在 Claude Code 中输入/github-ai-features-2025确认已加载。
详细介绍
🚨 关键指南
Windows 文件路径要求
强制要求:在 Windows 上始终使用反斜杠表示文件路径
在 Windows 上使用 Edit 或 Write 工具时,必须在文件路径中使用反斜杠(\),而不是正斜杠(/)。
示例:
- ❌ 错误:
D:/repos/project/file.tsx - ✅ 正确:
D:\repos\project\file.tsx
适用于:
- Edit 工具的 file_path 参数
- Write 工具的 file_path 参数
- 在 Windows 系统上执行的所有文件操作
文档指南
除非用户明确要求,否则绝不创建新的文档文件。
- 优先事项:更新现有 README.md 文件,而不是创建新文档
- 保持仓库整洁:保持仓库根目录整洁——除非用户另有要求,否则只保留 README.md
- 风格:文档应简洁、直接、专业,避免使用 AI 生成的语气
- 用户偏好:只有在用户明确要求编写文档时,才创建其他 .md 文件
GitHub AI 功能 2025
主干开发(TBD)
大型科技公司(Google:35,000+ 名开发者)采用的现代工作流:
原则
- **短生命周期分支:**最长数小时至 1 天
- **小而频繁的提交:**减少合并冲突
- **持续集成:**主分支始终可部署
- **功能标志:**隐藏未完成的功能
实施
# Create task branch from main
git checkout main
git pull origin main
git checkout -b task/add-login-button
# Make small changes
git add src/components/LoginButton.tsx
git commit -m "feat: add login button component"
# Push and create PR (same day)
git push origin task/add-login-button
gh pr create --title "Add login button" --body "Implements login UI"
# Merge within hours, delete branch
gh pr merge --squash --delete-branch
优势
- 减少合并冲突(降低 75%)
- 加快反馈周期
- 简化代码审查(改动更小)
- 主分支始终可发布
- 简化 CI/CD 流水线
GitHub 密钥保护(AI 驱动)
AI 会在密钥进入仓库前检测出来:
推送保护
# Attempt to commit secret
git add config.py
git commit -m "Add config"
git push
# GitHub AI detects secret:
"""
⛔ Push blocked by secret scanning
Found: AWS Access Key
Pattern: AKIA[0-9A-Z]{16}
File: config.py:12
Options:
1. Remove secret and try again
2. Mark as false positive (requires justification)
3. Request review from admin
"""
# Fix: Use environment variables
# config.py
import os
aws_key = os.environ.get('AWS_ACCESS_KEY')
git add config.py
git commit -m "Use env vars for secrets"
git push # ✅ Success
支持的密钥类型(AI 增强)
- AWS 凭据
- Azure 服务主体
- Google Cloud 密钥
- GitHub 令牌
- 数据库连接字符串
- API 密钥(OpenAI、Stripe 等)
- 私钥(SSH、TLS)
- OAuth 令牌
- 自定义模式(基于正则表达式)
GitHub 代码安全
CodeQL 代码扫描
AI 驱动的静态分析:
# .github/workflows/codeql.yml
name: "CodeQL"
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
analyze:
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: javascript, python, java
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
可检测:
- SQL 注入
- XSS 漏洞
- 路径遍历
- 命令注入
- 不安全的反序列化
- 身份验证绕过
- 逻辑错误
Copilot Autofix
AI 自动修复安全漏洞:
# Vulnerable code detected by CodeQL
def get_user(user_id):
query = f"SELECT * FROM users WHERE id = {user_id}" # ❌ SQL injection
return db.execute(query)
# Copilot Autofix suggests:
def get_user(user_id):
query = "SELECT * FROM users WHERE id = ?"
return db.execute(query, (user_id,)) # ✅ Parameterized query
# One-click to apply fix
GitHub Agent(自动化工作流)
用于自动修复错误和生成 PR 的 AI Agent:
错误修复 Agent
# .github/workflows/ai-bugfix.yml
name: AI Bug Fixer
on:
issues:
types: [labeled]
jobs:
autofix:
if: contains(github.event.issue.labels.*.name, 'bug')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Analyze Bug
uses: github/ai-agent@v1
with:
task: 'analyze-bug'
issue-number: ${{ github.event.issue.number }}
- name: Generate Fix
uses: github/ai-agent@v1
with:
task: 'generate-fix'
create-pr: true
pr-title: "Fix: ${{ github.event.issue.title }}"
自动生成 PR
# GitHub Agent creates PR automatically
# When issue is labeled "enhancement":
# 1. Analyzes issue description
# 2. Generates implementation code
# 3. Creates tests
# 4. Opens PR with explanation
# Example: Issue #42 "Add dark mode toggle"
# Agent creates PR with:
# - DarkModeToggle.tsx component
# - ThemeContext.tsx provider
# - Tests for theme switching
# - Documentation update
依赖项审查(AI 增强)
AI 会分析 PR 中的依赖项变更:
# .github/workflows/dependency-review.yml
name: Dependency Review
on: [pull_request]
permissions:
contents: read
jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Dependency Review
uses: actions/dependency-review-action@v3
with:
fail-on-severity: high
fail-on-scopes: runtime
AI 洞察:
- 新依赖项中的已知漏洞
- 许可证合规问题
- 更新中的重大变更
- 更安全的替代软件包
- 依赖项新鲜度评分
主干开发工作流
日常工作流
# Morning: Sync with main
git checkout main
git pull origin main
# Create task branch
git checkout -b task/user-profile-api
# Work in small iterations (2-4 hours)
# First iteration: API endpoint
git add src/api/profile.ts
git commit -m "feat: add profile API endpoint"
git push origin task/user-profile-api
gh pr create --title "Add user profile API" --draft
# Continue work: Add tests
git add tests/profile.test.ts
git commit -m "test: add profile API tests"
git push
# Mark ready for review
gh pr ready
# Get review (should happen within hours)
# Merge same day
gh pr merge --squash --delete-branch
# Next task: Start fresh from main
git checkout main
git pull origin main
git checkout -b task/profile-ui
小而频繁的提交模式
# ❌ Bad: Large infrequent commit
git add .
git commit -m "Add complete user profile feature with API, UI, tests, docs"
# 50 files changed, 2000 lines
# ✅ Good: Small frequent commits
git add src/api/profile.ts
git commit -m "feat: add profile API endpoint"
git push
git add src/components/ProfileCard.tsx
git commit -m "feat: add profile card component"
git push
git add tests/profile.test.ts
git commit -m "test: add profile tests"
git push
git add docs/profile.md
git commit -m "docs: document profile API"
git push
# Each commit: 1-3 files, 50-200 lines
# Easier reviews, faster merges, less conflicts
安全最佳实践(2025)
- 启用密钥扫描:
# Repository Settings → Security → Secret scanning
# Enable: Push protection + AI detection
- 配置 CodeQL:
# Add .github/workflows/codeql.yml
# Enable for all languages in project
- 使用 Copilot Autofix:
# Review security alerts weekly
# Apply Copilot-suggested fixes
# Test before merging
- 实施主干开发:
# Branch lifespan: <1 day
# Commit frequency: Every 2-4 hours
# Main branch: Always deployable
- 利用 GitHub Agent:
# Automate: Bug triage, PR creation, dependency updates
# Review: All AI-generated code before merging
资源
评论
支持 Markdown