Hermes Agent Python自动化:用自然语言写Python脚本

维护咨询 大模型部署 问题解决 技能定制 大模型训练

站长交流微信: aixbwz

GitHub Actions 是 GitHub 官方的 CI/CD 自动化平台,可以自动化代码构建、测试、部署等流程。把 Hermes Agent 和 GitHub Actions 结合,让你的开发工作流更自动化。

GitHub Actions 能做什么

  • 代码 push 后自动运行测试
  • PR 创建后自动 Code Review
  • 代码合并后自动部署
  • 定时执行数据备份
  • Issue/PR 创建时自动回复

Hermes Agent 在 GitHub Actions 中的角色

  • Code Review 自动化:PR 提交后让 AI 自动 Review
  • 自动生成 Commit Message:根据 diff 自动生成规范的提交信息
  • Bug 自动分析:CI 失败时 AI 自动分析错误原因
  • Issue 自动回复:新 Issue 创建时 AI 自动识别意图并回复

场景一:PR 自动 Code Review

创建 GitHub Actions Workflow

# .github/workflows/ai-code-review.yml
name: AI Code Review

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Run AI Code Review
        env:
          HERMES_API_KEY: ${{ secrets.HERMES_API_KEY }}
        run: |
          # 获取 PR diff
          git diff origin/main...HEAD > pr_diff.txt

          # 调用 Hermes Agent 分析
          curl -X POST https://api.hermes-agent.dev/review \
            -H "Authorization: Bearer $HERMES_API_KEY" \
            -d @pr_diff.txt \
            -o review_result.md

          # 发表评论
          gh pr comment $PR_NUMBER --body-file review_result.md
        env:
          PR_NUMBER: ${{ github.event.pull_request.number }}

场景二:自动生成 Commit Message

# .github/workflows/auto-commit-msg.yml
name: Auto Commit Message

on:
  commit:
    branches: [main]

jobs:
  gen-msg:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Generate Commit Message
        run: |
          git log --oneline -5 > commits.txt

          # 用 Hermes 生成规范的 commit message
          hermes generate-commit-msg --file commits.txt \
            --format conventionalcommits \
            --output commit_msg.txt

      - name: Display Result
        run: cat commit_msg.txt

场景三:CI 失败自动分析

# .github/workflows/ci-failure-analysis.yml
name: CI Failure Analysis

on:
  workflow_run:
    workflows: ["CI"]
    types: [completed]

jobs:
  analyze:
    if: github.event.workflow_run.conclusion == 'failure'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Download Artifacts
        uses: actions/download-artifact@v4

      - name: Run Failure Analysis
        env:
          HERMES_API_KEY: ${{ secrets.HERMES_API_KEY }}
        run: |
          # 收集失败日志
          cat failed_tests.log error.log > failures.txt

          hermes analyze-errors --file failures.txt \
            --explain \
            --suggest-fixes \
            --output analysis.md

      - name: Post Analysis Comment
        uses: actions/github-script@v7
        with:
          script: |
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: fs.readFileSync('analysis.md', 'utf8')
            })

场景四:Issue 自动回复

# .github/workflows/issue-auto-reply.yml
name: AI Issue Auto Reply

on:
  issues:
    types: [opened]

jobs:
  auto-reply:
    runs-on: ubuntu-latest
    steps:
      - name: Auto Reply
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          HERMES_API_KEY: ${{ secrets.HERMES_API_KEY }}
        run: |
          # 分析 Issue 类型和意图
          hermes classify-issue \
            --title "$ISSUE_TITLE" \
            --body "$ISSUE_BODY" \
            --repo "$REPO_NAME"

          # 生成回复
          hermes generate-reply \
            --type "$ISSUE_TYPE" \
            --repo "$REPO_NAME" \
            --output reply.txt

          # 发表回复
          gh issue comment $ISSUE_NUMBER --body "$(cat reply.txt)"
        env:
          ISSUE_TITLE: ${{ github.event.issue.title }}
          ISSUE_BODY: ${{ github.event.issue.body }}
          ISSUE_NUMBER: ${{ github.event.issue.number }}
          REPO_NAME: ${{ github.repository }}

配置 GitHub Secrets

# 在 GitHub 仓库设置中添加:
# Settings → Secrets and variables → Actions
# 添加:
# HERMES_API_KEY = 你的 Hermes API 密钥

注意事项

  • API Key 一定要放在 Secrets 里,不要硬编码
  • GitHub Actions 有免费额度,超出要付费
  • AI 回复内容要审核,避免误导用户
  • 合理设置触发条件,避免浪费资源

用了 Hermes Agent 还遇到问题?

加我微信进「AI工具交流群」,里面都是做AI落地的人

扫码加我,备注「Hermes」拉你进群

相关推荐

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容

七天热门