🔥

Claude Code Actionで複数リポジトリを横断して情報を参照し調査・実装を進めてもらおう

に公開

はじめに

本記事はGMOペパボ アドベントカレンダー3日目の記事です。

これまで以下のようなClaude Code Actionの記事を書いてきました。

今回は、表題の通り、Githubに導入しているClaude Code Actionがリポジトリを横断して情報を集め、調査・実装を進められるようにした時にやらなければいけなかったことを伝えたいと思います。

前提

私が所属するGMOペパボ suzuri・minne事業部におけるminneのプロダクト開発においては、バックエンドであるRailsのリポジトリと、WebフロントエンドであるNext.jsのリポジトリを分けて開発をしています。また、minneはiOSアプリ・Androidアプリも提供しているので、それらについても個別にリポジトリが存在しています。

そして、バックエンドであるRailsではGraphQL APIをクライアント向けに提供しており、各クライアントはそのGraphQL APIを通してアプリケーションの動作に必要な情報の取得・更新をしています。(minneでのGraphQLの推進について興味がある方はこちらを参照されたいです。ref: minneはなぜGraphQLを推進しているか

既に各リポジトリにClaude Code Actionは導入していたのですが、例えばNext.jsのリポジトリのissue・PRで動作するClaude Code Actionから、バックエンドから提供されるGraphQL APIの処理の実装やバックエンド側の過去のissueやPRの情報は参照できませんでした。

あるいは、例えばRailsのリポジトリのissue・PRで動作するClaude Code Actionから、iOSやAndroidリポジトリでRailsが提供する任意のGraphQL APIが実際に使われているか確認することはできませんでした。

実現したこと

そこで、既存のClaude Code Actionを動作させるワークフローにおいて、gh cliコマンドをインストールし、Github App Tokenを使うことでClaude Code Actionがリポジトリ横断でソースコード・issue・PRなどの情報を探索できるようにしました。

実際にリポジトリ横断で探索している様子

必要だったこと

  • Github appの作成
    • orgのSettingsにおけるGithub Appsの画面で、Claude Code Actionが横断して探索してほしいそれぞれのリポジトリについてのRepository accessを許可しておくこと
    • 本Github AppのPermission設定において、Repository permissions配下のIssues・Pull requestsのRead and Write権限を付与しておくこと
    • ワークフローにおいて、create token時にminne配下のリポジトリへのアクセス権を付与(owner: minne
      • なるべく最小限度のアクセスに絞るならばownerではなくrepositoryを1つ以上指定しておくと良いです、
  • ghコマンドのinstall
  • Bash, Read toolsのallow

変更前のコード

name: Claude PR Action

permissions:
  contents: write
  pull-requests: write
  issues: write
  id-token: write 

on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]
  issues:
    types: [opened, assigned]

jobs:
  claude-pr:
    if: |
      (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'issues' && contains(github.event.issue.body, '@claude'))
    runs-on: xxx
    env:
      AWS_REGION: xxx
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Generate GitHub App token
        id: app-token
        uses: actions/create-github-app-token@v2
        with:
          app-id: xxx
          private-key: xxx

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          audience: sts.amazonaws.com
          aws-region: xxx
          role-to-assume: xxx

      - uses: anthropics/claude-code-action
        with:
          model: # Bedrockで提供されるアプリケーション推論プロファイルのARN
          use_bedrock: "true"
          trigger_phrase: "@claude"
          timeout_minutes: "60"
          github_token: ${{ steps.app-token.outputs.token }}

変更後のコード

name: Claude PR Action 

permissions:
  contents: write
  pull-requests: write
  issues: write
  id-token: write 

on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]
  issues:
    types: [opened, assigned]

jobs:
  claude-pr:
    if: |
      (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'issues' && contains(github.event.issue.body, '@claude'))
    runs-on: xxx
    env:
      AWS_REGION: xxx
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Generate GitHub App token
        id: app-token
        uses: actions/create-github-app-token@v2
        with:
          app-id: xxx
          private-key: xxx
          owner: minne # ここで自身のorgの名前を指定。それによって指定org配下のリポジトリを参照することが可能になる。リポジトリを個別に指定することも可能。

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          audience: sts.amazonaws.com
          aws-region: xxx
          role-to-assume: xxx

      - name: Install GitHub CLI
        run: |
          curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
          sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
          echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
          sudo apt update
          sudo apt install gh -y

      - name: Setup gh CLI with App Token
        env:
          GH_TOKEN: ${{ steps.app-token.outputs.token }}
        run: |
          echo "$GH_TOKEN" | gh auth login --hostname xxx --with-token

      - uses: anthropics/claude-code-action
        with:
          model: # Bedrockで提供されるアプリケーション推論プロファイルのARN
          use_bedrock: "true"
          trigger_phrase: "@claude"
          timeout_minutes: "60"
          github_token: ${{ steps.app-token.outputs.token }}
          allowed_tools: |
            Bash
            Read
            Glob
            Grep

良くなった事

複数リポジトリが存在し、それぞれの連携がある私たちのような環境においては横断的にClaude Code Actionが情報を探索してくれることでより調査や実装が容易になりました。

また本取り組みによって、Github上のissueなどでディレクターやプロダクトマネージャがClaude Code Actionを使って以前より詳細な調査ができるようになったり、より詳細に要件定義を記述できるようになったことはAI前提のプロダクト開発に寄与したと考えています。

GitHubで編集を提案
GMOペパボ株式会社

Discussion