한국어
문서
GitHub

GitHub

GitHub issues와 pull requests에서 OpenCode를 사용하세요.

OpenCode는 GitHub 워크플로우와 통합됩니다. 댓글에 /opencode 또는 /oc를 멘션하면 OpenCode가 GitHub Actions runner 내에서 작업을 실행합니다.


기능

  • 이슈 분류: OpenCode에게 이슈를 조사하고 설명해 달라고 요청하세요.
  • 수정 및 구현: OpenCode에게 이슈를 수정하거나 기능을 구현해 달라고 요청하세요. 새 브랜치에서 작업하고 모든 변경 사항이 포함된 PR을 제출합니다.
  • 보안: OpenCode는 GitHub runner 내부에서 실행됩니다.

설치

GitHub 저장소에 있는 프로젝트에서 다음 명령을 실행하세요:

opencode github install

이 명령은 GitHub app 설치, 워크플로우 생성, secrets 설정을 안내합니다.


수동 설정

또는 수동으로 설정할 수 있습니다.

  1. GitHub app 설치

    github.com/apps/opencode-agent (opens in a new tab)로 이동하세요. 대상 저장소에 설치되어 있는지 확인하세요.

  2. 워크플로우 추가

    저장소의 .github/workflows/opencode.yml에 다음 워크플로우 파일을 추가하세요. env에서 적절한 model과 필요한 API 키를 설정하세요.

    .github/workflows/opencode.yml
    name: opencode
     
    on:
      issue_comment:
        types: [created]
      pull_request_review_comment:
        types: [created]
     
    jobs:
      opencode:
        if: |
          contains(github.event.comment.body, '/oc') ||
          contains(github.event.comment.body, '/opencode')
        runs-on: ubuntu-latest
        permissions:
          id-token: write
        steps:
          - name: Checkout repository
            uses: actions/checkout@v6
            with:
              fetch-depth: 1
              persist-credentials: false
     
          - name: Run OpenCode
            uses: anomalyco/opencode/github@latest
            env:
              ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
            with:
              model: anthropic/claude-sonnet-4-20250514
              # share: true
              # github_token: xxxx
  3. secrets에 API 키 저장

    조직 또는 프로젝트 설정에서 왼쪽의 Secrets and variables를 확장하고 Actions를 선택하세요. 그런 다음 필요한 API 키를 추가하세요.


설정

  • model: OpenCode와 함께 사용할 모델. provider/model 형식을 사용합니다. 이것은 필수입니다.

  • agent: 사용할 에이전트. 기본 에이전트여야 합니다. 찾을 수 없으면 설정의 default_agent 또는 "build"로 폴백합니다.

  • share: OpenCode 세션을 공유할지 여부. 공개 저장소의 경우 기본값은 true입니다.

  • prompt: 기본 동작을 재정의하는 선택적 사용자 정의 프롬프트. OpenCode가 요청을 처리하는 방식을 사용자 정의하는 데 사용하세요.

  • token: 댓글 생성, 변경 사항 커밋, pull requests 열기와 같은 작업을 수행하기 위한 선택적 GitHub 액세스 토큰. 기본적으로 OpenCode는 OpenCode GitHub App의 설치 액세스 토큰을 사용하므로 커밋, 댓글, pull requests가 앱에서 온 것으로 표시됩니다.

    또는 OpenCode GitHub App을 설치하지 않고 GitHub Action runner의 내장 GITHUB_TOKEN (opens in a new tab)을 사용할 수 있습니다. 워크플로우에서 필요한 권한을 부여하세요:

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

    원하는 경우 개인 액세스 토큰 (opens in a new tab)(PAT)을 사용할 수도 있습니다.


지원되는 이벤트

OpenCode는 다음 GitHub 이벤트로 트리거될 수 있습니다:

이벤트 유형트리거세부 정보
issue_commentissue 또는 PR에 댓글댓글에 /opencode 또는 /oc를 멘션하세요. OpenCode는 컨텍스트를 읽고 브랜치를 생성하거나, PR을 열거나, 답장할 수 있습니다.
pull_request_review_commentPR의 특정 코드 라인에 댓글코드 리뷰 중 /opencode 또는 /oc를 멘션하세요. OpenCode는 파일 경로, 라인 번호, diff 컨텍스트를 받습니다.
issuesIssue가 열리거나 편집됨issues가 생성되거나 수정될 때 자동으로 OpenCode를 트리거합니다. prompt 입력이 필요합니다.
pull_requestPR이 열리거나 업데이트됨PR이 열리거나, 동기화되거나, 다시 열릴 때 자동으로 OpenCode를 트리거합니다. 자동화된 리뷰에 유용합니다.
scheduleCron 기반 스케줄스케줄에 따라 OpenCode를 실행합니다. prompt 입력이 필요합니다. 출력은 로그와 PR로 전송됩니다(댓글할 issue 없음).
workflow_dispatchGitHub UI에서 수동 트리거Actions 탭을 통해 온디맨드로 OpenCode를 트리거합니다. prompt 입력이 필요합니다. 출력은 로그와 PR로 전송됩니다.

스케줄 예제

자동화된 작업을 수행하기 위해 스케줄에 따라 OpenCode를 실행하세요:

.github/workflows/opencode-scheduled.yml
name: Scheduled OpenCode Task
 
on:
  schedule:
    - cron: "0 9 * * 1" # Every Monday at 9am UTC
 
jobs:
  opencode:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: write
      pull-requests: write
      issues: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6
        with:
          persist-credentials: false
 
      - name: Run OpenCode
        uses: anomalyco/opencode/github@latest
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        with:
          model: anthropic/claude-sonnet-4-20250514
          prompt: |
            Review the codebase for any TODO comments and create a summary.
            If you find issues worth addressing, open an issue to track them.

스케줄된 이벤트의 경우 지시를 추출할 댓글이 없으므로 prompt 입력이 필수입니다. 스케줄된 워크플로우는 권한 확인을 위한 사용자 컨텍스트 없이 실행되므로 OpenCode가 브랜치나 PR을 생성할 것으로 예상되면 워크플로우에서 contents: writepull-requests: write를 부여해야 합니다.


Pull Request 예제

PR이 열리거나 업데이트될 때 자동으로 리뷰하세요:

.github/workflows/opencode-review.yml
name: opencode-review
 
on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]
 
jobs:
  review:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
      pull-requests: read
      issues: read
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - uses: anomalyco/opencode/github@latest
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          model: anthropic/claude-sonnet-4-20250514
          use_github_token: true
          prompt: |
            Review this pull request:
            - Check for code quality issues
            - Look for potential bugs
            - Suggest improvements

pull_request 이벤트의 경우 prompt가 제공되지 않으면 OpenCode는 기본적으로 pull request를 리뷰합니다.


Issues 분류 예제

새 issues를 자동으로 분류하세요. 이 예제는 스팸을 줄이기 위해 30일 이상 된 계정을 필터링합니다:

.github/workflows/opencode-triage.yml
name: Issue Triage
 
on:
  issues:
    types: [opened]
 
jobs:
  triage:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: write
      pull-requests: write
      issues: write
    steps:
      - name: Check account age
        id: check
        uses: actions/github-script@v7
        with:
          script: |
            const user = await github.rest.users.getByUsername({
              username: context.payload.issue.user.login
            });
            const created = new Date(user.data.created_at);
            const days = (Date.now() - created) / (1000 * 60 * 60 * 24);
            return days >= 30;
          result-encoding: string
 
      - uses: actions/checkout@v6
        if: steps.check.outputs.result == 'true'
        with:
          persist-credentials: false
 
      - uses: anomalyco/opencode/github@latest
        if: steps.check.outputs.result == 'true'
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        with:
          model: anthropic/claude-sonnet-4-20250514
          prompt: |
            Review this issue. If there's a clear fix or relevant docs:
            - Provide documentation links
            - Add error handling guidance for code examples
            Otherwise, do not comment.

issues 이벤트의 경우 지시를 추출할 댓글이 없으므로 prompt 입력이 필수입니다.


사용자 정의 프롬프트

워크플로우에서 OpenCode의 동작을 사용자 정의하려면 기본 프롬프트를 재정의하세요.

.github/workflows/opencode.yml
- uses: anomalyco/opencode/github@latest
  with:
    model: anthropic/claude-sonnet-4-5
    prompt: |
      Review this pull request:
      - Check for code quality issues
      - Look for potential bugs
      - Suggest improvements

이것은 프로젝트와 관련된 특정 리뷰 기준, 코딩 표준 또는 중점 영역을 적용하는 데 유용합니다.


예제

GitHub에서 OpenCode를 사용하는 몇 가지 예제입니다.

  • 이슈 설명

    GitHub issue에 이 댓글을 추가하세요.

    /opencode explain this issue

    OpenCode는 모든 댓글을 포함한 전체 스레드를 읽고 명확한 설명으로 답장합니다.

  • 이슈 수정

    GitHub issue에서 다음과 같이 말하세요:

    /opencode fix this

    그러면 OpenCode가 새 브랜치를 생성하고, 변경 사항을 구현하고, 변경 사항이 포함된 PR을 엽니다.

  • PR 리뷰 및 변경

    GitHub PR에 다음 댓글을 남기세요.

    Delete the attachment from S3 when the note is removed /oc

    OpenCode는 요청된 변경 사항을 구현하고 동일한 PR에 커밋합니다.

  • 특정 코드 라인 리뷰

    PR의 "Files" 탭에서 코드 라인에 직접 댓글을 남기세요. OpenCode는 정확한 응답을 제공하기 위해 파일, 라인 번호, diff 컨텍스트를 자동으로 감지합니다.

    [Comment on specific lines in Files tab]
    /oc add error handling here

    특정 라인에 댓글을 달 때 OpenCode는 다음을 받습니다:

    • 리뷰 중인 정확한 파일
    • 특정 코드 라인
    • 주변 diff 컨텍스트
    • 라인 번호 정보

    이를 통해 파일 경로나 라인 번호를 수동으로 지정하지 않고도 더 타겟팅된 요청이 가능합니다.