github-automation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub 自动化操作

GitHub Automation Operations

功能说明

Feature Overview

此技能专门用于自动化 GitHub 平台的各种操作,包括:
  • 仓库管理和文件操作
  • Pull Request 创建和审查
  • Issue 管理和追踪
  • 分支管理和合并
  • CI/CD 工作流自动化
  • 代码搜索和分析
This skill is specifically designed to automate various operations on the GitHub platform, including:
  • Repository management and file operations
  • Pull Request (PR) creation and review
  • Issue management and tracking
  • Branch management and merging
  • CI/CD workflow automation
  • Code search and analysis

使用场景

Usage Scenarios

  • "创建一个新的 GitHub 仓库"
  • "提交代码并创建 Pull Request"
  • "批量处理 GitHub Issues"
  • "自动化代码审查流程"
  • "搜索代码库中的特定代码"
  • "管理 GitHub Actions 工作流"
  • "Create a new GitHub repository"
  • "Commit code and create a Pull Request"
  • "Batch process GitHub Issues"
  • "Automate code review processes"
  • "Search for specific code in code repositories"
  • "Manage GitHub Actions workflows"

核心功能模块

Core Function Modules

1. 仓库管理

1. Repository Management

  • 创建仓库:创建新的公开或私有仓库
  • Fork 仓库:Fork 其他仓库到自己账户
  • 搜索仓库:按关键词搜索仓库
  • 文件操作:读取、创建、更新文件
  • 批量提交:一次提交多个文件
  • Create Repository: Create new public or private repositories
  • Fork Repository: Fork other repositories to your account
  • Search Repository: Search repositories by keywords
  • File Operations: Read, create, and update files
  • Batch Commit: Commit multiple files at once

2. Pull Request 管理

2. Pull Request Management

  • 创建 PR:从分支创建 Pull Request
  • 审查 PR:添加评论和审查意见
  • 合并 PR:合并 Pull Request
  • 查看变更:获取 PR 的文件变更
  • 状态检查:查看 CI/CD 状态
  • Create PR: Create a Pull Request from a branch
  • Review PR: Add comments and review feedback
  • Merge PR: Merge the Pull Request
  • View Changes: Get file changes in the PR
  • Status Check: View CI/CD status

3. Issue 管理

3. Issue Management

  • 创建 Issue:创建新的问题或任务
  • 更新 Issue:修改状态、标签、负责人
  • 搜索 Issue:按条件筛选 Issue
  • 添加评论:在 Issue 中添加讨论
  • 批量操作:批量处理多个 Issue
  • Create Issue: Create new issues or tasks
  • Update Issue: Modify status, labels, and assignees
  • Search Issue: Filter Issues by conditions
  • Add Comment: Add discussions in Issues
  • Batch Operations: Batch process multiple Issues

4. 分支管理

4. Branch Management

  • 创建分支:从指定分支创建新分支
  • 查看提交:列出分支的提交历史
  • 分支保护:配置分支保护规则
  • 合并策略:选择合并方式(merge、squash、rebase)
  • Create Branch: Create a new branch from the specified branch
  • View Commits: List commit history of a branch
  • Branch Protection: Configure branch protection rules
  • Merge Strategy: Select merge methods (merge, squash, rebase)

5. 代码搜索

5. Code Search

  • 搜索代码:在仓库中搜索代码片段
  • 搜索 Issue:搜索问题和 PR
  • 搜索用户:查找 GitHub 用户
  • 高级查询:使用 GitHub 搜索语法
  • Search Code: Search code snippets in repositories
  • Search Issue: Search Issues and PRs
  • Search User: Find GitHub users
  • Advanced Query: Use GitHub search syntax

工作流程

Workflows

标准开发流程

Standard Development Workflow

  1. 创建分支:从 main 创建功能分支
  2. 开发代码:编写和测试代码
  3. 提交变更:提交文件到分支
  4. 创建 PR:创建 Pull Request
  5. 代码审查:团队审查代码
  6. 合并代码:合并到主分支
  1. Create Branch: Create a feature branch from main
  2. Develop Code: Write and test code
  3. Commit Changes: Commit files to the branch
  4. Create PR: Create a Pull Request
  5. Code Review: Team conducts code review
  6. Merge Code: Merge into the main branch

自动化发布流程

Automated Release Workflow

  1. 监听事件:监听 push 或 tag 事件
  2. 运行测试:执行自动化测试
  3. 构建项目:编译和打包
  4. 创建 Release:发布新版本
  5. 部署应用:自动部署到生产环境
  1. Listen to Events: Listen for push or tag events
  2. Run Tests: Execute automated tests
  3. Build Project: Compile and package the project
  4. Create Release: Publish a new version
  5. Deploy Application: Automatically deploy to production environment

Issue 管理流程

Issue Management Workflow

  1. 创建 Issue:报告问题或需求
  2. 分配任务:指定负责人
  3. 添加标签:分类和优先级
  4. 跟踪进度:更新状态
  5. 关闭 Issue:完成后关闭
  1. Create Issue: Report issues or requirements
  2. Assign Tasks: Specify assignees
  3. Add Labels: Classify and set priorities
  4. Track Progress: Update status
  5. Close Issue: Close after completion

最佳实践

Best Practices

提交规范

Commit Guidelines

  • 使用清晰的提交信息
  • 遵循 Conventional Commits 规范
  • 一次提交解决一个问题
  • 包含必要的测试和文档
  • Use clear commit messages
  • Follow the Conventional Commits specification
  • Solve one issue per commit
  • Include necessary tests and documentation

PR 规范

PR Guidelines

  • 提供详细的 PR 描述
  • 关联相关的 Issue
  • 确保 CI 检查通过
  • 及时响应审查意见
  • 保持 PR 大小适中
  • Provide detailed PR descriptions
  • Link related Issues
  • Ensure CI checks pass
  • Respond to review feedback promptly
  • Keep PR size moderate

分支策略

Branch Strategy

  • 使用 Git Flow 或 GitHub Flow
  • 保护主分支
  • 定期同步上游分支
  • 及时删除已合并的分支
  • Use Git Flow or GitHub Flow
  • Protect the main branch
  • Regularly sync with upstream branches
  • Delete merged branches in a timely manner

安全实践

Security Practices

  • 不提交敏感信息
  • 使用 GitHub Secrets 管理密钥
  • 启用双因素认证
  • 定期审查权限设置
  • Do not commit sensitive information
  • Use GitHub Secrets to manage keys
  • Enable two-factor authentication
  • Regularly review permission settings
  • Follow open source project contribution guidelines

常用代码示例

Common Code Examples

1. 创建仓库并提交文件

1. Create Repository and Commit Files

javascript
// 创建仓库
const repo = await createRepository({
  name: "my-project",
  description: "项目描述",
  private: false,
  autoInit: true
});

// 批量提交文件
await pushFiles({
  owner: "username",
  repo: "my-project",
  branch: "main",
  files: [
    {
      path: "README.md",
      content: "# My Project\n\n项目说明"
    },
    {
      path: "src/index.js",
      content: "console.log('Hello World');"
    }
  ],
  message: "Initial commit"
});
javascript
// 创建仓库
const repo = await createRepository({
  name: "my-project",
  description: "项目描述",
  private: false,
  autoInit: true
});

// 批量提交文件
await pushFiles({
  owner: "username",
  repo: "my-project",
  branch: "main",
  files: [
    {
      path: "README.md",
      content: "# My Project\n\n项目说明"
    },
    {
      path: "src/index.js",
      content: "console.log('Hello World');"
    }
  ],
  message: "Initial commit"
});

2. 创建分支和 Pull Request

2. Create Branch and Pull Request

javascript
// 创建新分支
await createBranch({
  owner: "username",
  repo: "my-project",
  branch: "feature/new-feature",
  from_branch: "main"
});

// 提交代码到新分支
await createOrUpdateFile({
  owner: "username",
  repo: "my-project",
  path: "src/feature.js",
  content: "// 新功能代码",
  message: "Add new feature",
  branch: "feature/new-feature"
});

// 创建 Pull Request
await createPullRequest({
  owner: "username",
  repo: "my-project",
  title: "添加新功能",
  head: "feature/new-feature",
  base: "main",
  body: "## 变更说明\n- 添加了新功能\n- 更新了文档"
});
javascript
// 创建新分支
await createBranch({
  owner: "username",
  repo: "my-project",
  branch: "feature/new-feature",
  from_branch: "main"
});

// 提交代码到新分支
await createOrUpdateFile({
  owner: "username",
  repo: "my-project",
  path: "src/feature.js",
  content: "// 新功能代码",
  message: "Add new feature",
  branch: "feature/new-feature"
});

// 创建 Pull Request
await createPullRequest({
  owner: "username",
  repo: "my-project",
  title: "添加新功能",
  head: "feature/new-feature",
  base: "main",
  body: "## 变更说明\n- 添加了新功能\n- 更新了文档"
});

3. Issue 管理

3. Issue Management

javascript
// 创建 Issue
const issue = await createIssue({
  owner: "username",
  repo: "my-project",
  title: "修复登录问题",
  body: "## 问题描述\n用户无法登录\n\n## 复现步骤\n1. 打开登录页面\n2. 输入凭证\n3. 点击登录",
  labels: ["bug", "high-priority"],
  assignees: ["developer1"]
});

// 添加评论
await addIssueComment({
  owner: "username",
  repo: "my-project",
  issue_number: issue.number,
  body: "正在调查此问题"
});

// 更新 Issue
await updateIssue({
  owner: "username",
  repo: "my-project",
  issue_number: issue.number,
  state: "closed",
  labels: ["bug", "fixed"]
});
javascript
// 创建 Issue
const issue = await createIssue({
  owner: "username",
  repo: "my-project",
  title: "修复登录问题",
  body: "## 问题描述\n用户无法登录\n\n## 复现步骤\n1. 打开登录页面\n2. 输入凭证\n3. 点击登录",
  labels: ["bug", "high-priority"],
  assignees: ["developer1"]
});

// 添加评论
await addIssueComment({
  owner: "username",
  repo: "my-project",
  issue_number: issue.number,
  body: "正在调查此问题"
});

// 更新 Issue
await updateIssue({
  owner: "username",
  repo: "my-project",
  issue_number: issue.number,
  state: "closed",
  labels: ["bug", "fixed"]
});

4. 代码审查

4. Code Review

javascript
// 获取 PR 详情
const pr = await getPullRequest({
  owner: "username",
  repo: "my-project",
  pull_number: 123
});

// 获取 PR 文件变更
const files = await getPullRequestFiles({
  owner: "username",
  repo: "my-project",
  pull_number: 123
});

// 创建审查
await createPullRequestReview({
  owner: "username",
  repo: "my-project",
  pull_number: 123,
  body: "代码看起来不错,有几点建议",
  event: "COMMENT",
  comments: [
    {
      path: "src/index.js",
      line: 10,
      body: "建议添加错误处理"
    }
  ]
});

// 合并 PR
await mergePullRequest({
  owner: "username",
  repo: "my-project",
  pull_number: 123,
  merge_method: "squash",
  commit_title: "feat: 添加新功能"
});
javascript
// 获取 PR 详情
const pr = await getPullRequest({
  owner: "username",
  repo: "my-project",
  pull_number: 123
});

// 获取 PR 文件变更
const files = await getPullRequestFiles({
  owner: "username",
  repo: "my-project",
  pull_number: 123
});

// 创建审查
await createPullRequestReview({
  owner: "username",
  repo: "my-project",
  pull_number: 123,
  body: "代码看起来不错,有几点建议",
  event: "COMMENT",
  comments: [
    {
      path: "src/index.js",
      line: 10,
      body: "建议添加错误处理"
    }
  ]
});

// 合并 PR
await mergePullRequest({
  owner: "username",
  repo: "my-project",
  pull_number: 123,
  merge_method: "squash",
  commit_title: "feat: 添加新功能"
});

5. 搜索和查询

5. Search and Query

javascript
// 搜索代码
const codeResults = await searchCode({
  q: "function login repo:username/my-project"
});

// 搜索 Issue
const issueResults = await searchIssues({
  q: "is:open label:bug repo:username/my-project",
  sort: "created",
  order: "desc"
});

// 搜索仓库
const repoResults = await searchRepositories({
  query: "react stars:>1000 language:javascript"
});
javascript
// 搜索代码
const codeResults = await searchCode({
  q: "function login repo:username/my-project"
});

// 搜索 Issue
const issueResults = await searchIssues({
  q: "is:open label:bug repo:username/my-project",
  sort: "created",
  order: "desc"
});

// 搜索仓库
const repoResults = await searchRepositories({
  query: "react stars:>1000 language:javascript"
});

GitHub Actions 集成

GitHub Actions Integration

自动化测试

Automated Testing

yaml
name: CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Run tests
        run: npm test
yaml
name: CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Run tests
        run: npm test

自动化部署

Automated Deployment

yaml
name: Deploy
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Deploy
        run: ./deploy.sh
yaml
name: Deploy
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Deploy
        run: ./deploy.sh

集成场景

Integration Scenarios

1. 自动化代码审查

1. Automated Code Review

  • 监听 PR 创建事件
  • 运行代码质量检查
  • 自动添加审查评论
  • 标记需要改进的地方
  • Listen to PR creation events
  • Run code quality checks
  • Automatically add review comments
  • Mark areas that need improvement

2. Issue 自动分类

2. Automatic Issue Classification

  • 监听 Issue 创建
  • 分析 Issue 内容
  • 自动添加标签
  • 分配给合适的人员
  • Listen to Issue creation events
  • Analyze Issue content
  • Automatically add labels
  • Assign to appropriate personnel

3. 发布管理

3. Release Management

  • 监听版本标签
  • 生成变更日志
  • 创建 GitHub Release
  • 通知团队成员
  • Listen to version tag events
  • Generate change logs
  • Create GitHub Release
  • Notify team members

4. 依赖更新

4. Dependency Update

  • 定期检查依赖更新
  • 创建更新 PR
  • 运行测试验证
  • 自动合并安全更新
  • Regularly check for dependency updates
  • Create update PRs
  • Run tests for verification
  • Automatically merge security updates

注意事项

Notes

  • 遵守 GitHub API 速率限制
  • 使用 Personal Access Token 认证
  • 正确处理 API 错误和重试
  • 保护敏感信息和密钥
  • 遵循开源项目贡献指南
  • Comply with GitHub API rate limits
  • Use Personal Access Token for authentication
  • Properly handle API errors and retries
  • Protect sensitive information and keys
  • Follow open source project contribution guidelines