codex-actionでバグのissueを自動で修正するワークフローを作成しました。
以下がソースコードです。
name: code autofix
on:
issues:
types: [labeled]
jobs:
codex:
if: github.event.label.name == 'bug'
runs-on: ubuntu-latest
permissions:
contents: write
issues: read
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Run Codex
uses: openai/codex-action@v1
id: codex
with:
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
prompt: |
Issueの内容からバグを修正して下さい。
Issue Content:
${{ github.event.issue.body }}
- name: Setup Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Create branch and commit changes
env:
BRANCH_NAME: codex/auto-fix-${{ github.run_number }}
run: |
git checkout -b $BRANCH_NAME
git add .
git commit -m "Fix: Auto-fix by Codex for issue #${{ github.event.issue.number }}" || echo "No changes to commit"
git push origin $BRANCH_NAME
- name: create pull request
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "auto fix codex",
head: `codex/auto-fix-${{ github.run_number }}`,
base: "main",
body: "Codexにより自動で修正されました。",
draft: true
});