InfoGrab DocsInfoGrab Docs

Agent Platform의 커스텀 리뷰 지침 설정

요약

GitLab 18.3에서 기능 플래그 duo_code_review_custom_instructions가 기본으로 활성화됨. GitLab 18.4에서 기능 플래그 duo_code_review_custom_instructions가 제거됨.

히스토리
  • GitLab 18.2에서 duo_code_review_custom_instructions라는 플래그와 함께 베타도입됨. 기본적으로 비활성화됨.
  • GitLab 18.3에서 기능 플래그 duo_code_review_custom_instructions기본으로 활성화됨.

  • GitLab 18.4에서 기능 플래그 duo_code_review_custom_instructions제거됨.

  • GitLab 19.1에서 fileFilters의 유니온 패턴(예: {rb,ts})이 도입됨.

머지 리퀘스트를 리뷰할 때 GitLab Duo가 참조할 표준을 제공하는 커스텀 리뷰 지침을 생성합니다.

예를 들어, Ruby 파일에는 Ruby 스타일 규칙을, Go 파일에는 Go 스타일 규칙을 적용하도록 GitLab Duo를 안내할 수 있습니다.

Note

커스텀 리뷰 지침은 AI 리뷰어에 대한 안내이며, 강제되는 정책이 아닙니다. GitLab Duo는 이를 컨텍스트로 활용해 리뷰를 구성하지만, 모든 지침이 모든 경우에 적용된다고 보장할 수 없습니다. 일관된 적용이 필요한 보안 제어, 컴플라이언스 의무, 또는 기타 요건에는 커스텀 지침을 사용하지 마세요.

GitLab Duo는 기존 리뷰 기준을 대체하는 것이 아니라, 커스텀 리뷰 지침을 기존 기준에 추가합니다.

Code Review Flow는 특정 프로젝트 또는 그룹 내 모든 프로젝트에 설정된 커스텀 리뷰 지침을 지원합니다.

프로젝트에 커스텀 리뷰 지침 설정#

커스텀 머지 리퀘스트 리뷰 지침을 설정하려면:

  • 리포지터리 루트에 .gitlab/duo 디렉터리가 없으면 생성합니다.

  • .gitlab/duo 디렉터리에 mr-review-instructions.yaml 파일을 생성합니다.

  • 다음 형식으로 커스텀 지침을 추가합니다:

instructions:
  - name: <instruction_group_name>
    fileFilters:
      - <glob_pattern_1>
      - <glob_pattern_2>
      - !<exclude_pattern>  # Exclude files matching this pattern
    instructions: |
      <your_custom_review_instructions>

fileFilters 섹션은 선택 사항입니다. 이 섹션에서 글로브 패턴을 사용해 특정 파일에만 지침을 적용할 수 있습니다. fileFilters를 생략하거나 비워 두면 GitLab Duo는 머지 리퀘스트의 모든 파일에 해당 지침을 적용합니다.

예시:

instructions:
  - name: Ruby Style Guide
    fileFilters:
      - "*.rb"           # Ruby files in the root directory
      - "lib/**/*.rb"    # Ruby files in lib and its subdirectories
      - "!spec/**/*.rb"  # Exclude test files
    instructions: |
      1. Ensure all methods have proper documentation
      2. Follow Ruby style guide conventions
      3. Prefer symbols over strings for hash keys

  - name: TypeScript Source Files
    fileFilters:
      - "**/*.ts"        # Typescript files in any directory
      - "!**/*.test.ts"  # Exclude test files
      - "!**/*.spec.ts"  # Exclude spec files
    instructions: |
      1. Ensure proper TypeScript types (avoid 'any')
      2. Follow naming conventions
      3. Document complex functions

  - name: All Files Except Tests
    fileFilters:
      - "!**/*.test.*"   # Exclude all test files
      - "!**/*.spec.*"   # Exclude all spec files
      - "!test/**/*"     # Exclude test directories
      - "!spec/**/*"     # Exclude spec directories
    instructions: |
      1. Follow consistent code style
      2. Add meaningful comments for complex logic
      3. Ensure proper error handling

  - name: Test Coverage
    fileFilters:
      - "spec/**/*_spec.rb" # Ruby test files in spec directory
    instructions: |
      1. Test both happy paths and edge cases
      2. Include error scenarios
      3. Use shared examples to reduce duplication

  - name: Database Migrations
    fileFilters:
      - "db/migrate/**/*.rb"
      - "db/post_migrate/**/*.rb"
    instructions: |
      1. Follow the migration safety guidelines in
         https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/development/database/avoiding_downtime_in_migrations.md
      2. Apply the team checklist in docs/migrations-checklist.md

  - name: All Files
    fileFilters:
      - "**/*"   # All files in the repository
    instructions: |
      1. Explain the "why" behind each suggestion

지침에서 파일을 참조하는 방법은 지침에서 파일 참조하기를 참조하세요.

글로브 문법 예시는 파일 패턴 참조를 참조하세요.

  • 선택 사항: mr-review-instructions.yaml 파일 변경을 보호하기 위해 Code Owners 항목을 추가합니다.
[GitLab Duo]
.gitlab/duo @default-owner @tech-lead

GitLab Duo는 파일 패턴이 일치하면 커스텀 지침을 자동으로 적용합니다.

  • 여러 지침 그룹이 하나의 파일에 적용될 수 있습니다. 파일이 둘 이상의 그룹 fileFilters와 일치하면, Code Review Flow는 일치하는 모든 그룹의 지침을 적용합니다.

  • 커스텀 지침으로 트리거된 리뷰 코멘트의 경우, GitLab Duo는 다음 형식을 사용합니다:

According to custom instructions in '[instruction_name]': [feedback comments]

instruction_name 값은 .gitlab/duo/mr-review-instructions.yaml 파일의 name 속성에 해당합니다. GitLab Duo의 표준 코멘트는 이 형식을 사용하지 않습니다.

GitLab Duo가 문제를 발견하지 못한 경우에는 리뷰 요약 코멘트를 남깁니다. 커스텀 지침은 이 요약 코멘트에는 적용되지 않습니다.

  • 선택 사항:

피드백을 검토하고 필요에 따라 지침을 수정합니다.

  • 패턴을 테스트해 의도한 파일과 일치하는지 확인합니다.

그룹에 커스텀 리뷰 지침 설정#

히스토리

템플릿으로 사용할 프로젝트를 지정해 그룹의 커스텀 리뷰 지침을 정의할 수 있습니다. 템플릿 프로젝트에는 그룹 및 하위 그룹의 모든 프로젝트에 적용되는 리뷰 지침이 담긴 .gitlab/duo/mr-review-instructions.yaml 파일이 있어야 합니다.

GitLab Duo가 코드 리뷰를 수행하면, 최상위 그룹의 지침과 개별 프로젝트에 정의된 지침을 결합합니다.

사전 요건:

  • 최상위 그룹에 대한 Owner 권한.

  • 그룹 내 프로젝트에 템플릿으로 사용할 커스텀 리뷰 지침이 포함되어 있어야 합니다.

그룹에 커스텀 리뷰 지침을 설정하려면:

  • 상단 바에서 Search or go to를 선택하고 최상위 그룹을 찾습니다.

  • 왼쪽 사이드바에서 Settings > General > GitLab Duo features를 선택합니다.

  • Custom review instructions for groups 아래에서 그룹의 리뷰 지침이 담긴 .gitlab/duo/mr-review-instructions.yaml 파일을 포함하는 프로젝트를 선택합니다.

  • Save changes를 선택합니다.

지침에서 파일 참조하기#

콘텐츠를 중복하는 대신 커스텀 지침에서 다른 파일을 참조할 수 있습니다. Code Review Flow는 사전 스캔 단계에서 참조된 파일을 읽고 관련 안내를 추출합니다.

커스텀 지침은 두 가지 파일 참조 패턴을 지원합니다:

  • 머지 리퀘스트와 동일한 프로젝트의 파일: docs/security-checklist.md와 같이 리포지터리 상대 경로를 사용합니다.

  • 동일한 GitLab 인스턴스의 다른 프로젝트에 있는 파일: 다음과 같이 완전한 GitLab blob URL을 사용합니다: https://gitlab.example.com/group/project/-/blob/main/docs/style-guide.md. URL은 머지 리퀘스트와 동일한 GitLab 인스턴스를 가리켜야 하며 /-/blob/<ref>/<path> 형식을 사용해야 합니다.

예시:

instructions:
  - name: Database Migrations
    fileFilters:
      - "db/migrate/**/*.rb"
    instructions: |
      1. Follow the migration guidelines in
         https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/development/database/avoiding_downtime_in_migrations.md
      2. Reference the team checklist in docs/db-checklist.md

파일 참조의 제한 사항#

파일 참조 해석에는 다음과 같은 제약이 있습니다:

  • 동일한 GitLab 인스턴스만 가능. 다른 GitLab 인스턴스, GitLab Self-Managed 인스턴스에서 공개 GitLab으로, 또는 Confluence나 공개 문서 사이트와 같은 비 GitLab 사이트를 가리키는 URL은 가져오지 않습니다.

  • /-/blob/<ref>/<path> 형식의 Blob URL만 가능. Wiki 페이지, 이슈, raw URL, 스니펫은 가져오지 않습니다.

  • 동일 프로젝트에서의 단순 경로. docs/security.md와 같은 단순 경로는 머지 리퀘스트와 동일한 프로젝트를 기준으로 해석됩니다. 다른 프로젝트의 파일을 참조하려면 완전한 GitLab blob URL을 사용하세요.

  • 최선의 노력이며 보장되지 않음. Code Review Flow는 지침 텍스트를 기반으로 가져올 참조를 결정합니다. 존재하지 않는 경로나 파서가 거부하는 URL처럼 해석에 실패한 참조는 조용히 건너뜁니다.

  • Code Review Flow는 원본 파일이 아닌 요약본을 사용. 사전 스캔 단계에서 가져온 콘텐츠를 요약하고 리뷰 중 해당 요약을 사용합니다. 동일한 머지 리퀘스트에 대한 두 번의 리뷰는 서로 다른 요약을 생성할 수 있습니다.

Code Review Flow가 요약본이 아닌 정확한 파일 내용을 사용하도록 하려면, 파일을 참조하는 대신 instructions: 필드에 직접 포함하세요. 인라인 지침은 작성된 그대로 사용됩니다.

모범 사례#

커스텀 리뷰 지침을 작성할 때:

  • 구체적이고 실행 가능하게 작성하세요. Code Review Flow는 각 규칙을 diff와 대조합니다. 예를 들어, "공개 메서드에 YARD 문서가 있는지 확인하세요"와 같이 구체적인 규칙은 유용한 코멘트를 생성하지만, "코드를 잘 문서화하세요"와 같은 추상적인 안내는 그렇지 않습니다.

  • 명확성을 위해 지침에 번호를 매기세요.

  • 가장 중요한 표준에 집중하세요. 모든 규칙의 텍스트는 리뷰 프롬프트의 일부가 되므로, 가치가 낮은 규칙의 긴 목록은 신호를 추가하지 않고 프롬프트만 늘립니다.

  • 도움이 될 때는 "왜"를 설명하세요.

  • 간단한 지침부터 시작하고 필요에 따라 복잡성을 추가하세요.

  • Code Review Flow가 기본적으로 적용하지 않는 프로젝트별 표준에 집중하세요. 커스텀 지침은 기존 리뷰 기준을 대체하는 것이 아니라 추가합니다. "오류 처리 추가" 또는 "의미 있는 이름 사용"과 같은 일반적인 조언은 이미 포함되어 있는 경우가 많습니다. 커스텀 지침은 프로젝트만이 알고 있는 것에 사용하세요: 내부 API, 아키텍처 규칙, 도메인별 패턴.

  • 지침은 지시가 아닌 안내로 작성하세요. 지침은 리뷰 동작을 형성하는 힌트이지, GitLab Duo가 반드시 따라야 하는 정책이 아닙니다. "항상 플래그 지정" 또는 "절대 허용하지 않음"과 같은 표현을 피하세요. 이런 표현은 협업자가 해당 동작이 보장된다고 오해할 수 있습니다.

  • 파일 패턴이 규칙의 실제 범위를 반영하도록 하세요. Code Review Flow는 각 fileFilters 참조와 함께 각 지침을 읽고 해당 패턴과 일치하는 파일에만 규칙을 적용합니다. 예를 들어, **/*.rb로 범위 지정된 "Rails controllers" 규칙은 컨트롤러뿐만 아니라 gem, 스크립트, 테스트에도 적용됩니다. 대신 app/controllers/**/*.rb를 사용하세요.

  • 정확한 표현이 중요하지 않은 지침에만 외부 파일 참조를 사용하고, 그렇지 않은 경우에는 instructions: 필드에 직접 규칙으로 포함하세요. Code Review Flow는 참조된 파일에 대해 요약을 생성하고 사용하지만, instructions에 정의된 정확한 표현을 사용합니다.

예시:

instructions: |
  1. All public functions must include docstrings with parameter descriptions
  2. Use parameterized queries to prevent SQL injection
  3. Validate user input before processing (check type, length, format)
  4. Include error handling for all external API calls
  5. Avoid hardcoded credentials - use environment variables

언어별 예시는 사용 사례 예시를 참조하세요.

파일 패턴 참조#

fileFilters에서 글로브 패턴을 사용해 특정 파일을 타깃으로 설정합니다.

예를 들어, Ruby 파일이 포함된 프로젝트의 경우:

Pattern Match
**/*.rb 모든 디렉터리의 Ruby 파일
*.rb 루트 디렉터리의 Ruby 파일만
lib/**/*.rb lib 디렉터리 및 하위 디렉터리의 Ruby 파일
!**/*.test.rb 모든 Ruby 테스트 파일 제외
!spec/**/*.rb spec 디렉터리 및 하위 디렉터리의 모든 Ruby 파일 제외
!tests/**/* tests 디렉터리 및 하위 디렉터리의 모든 파일 제외
**/*.{js,jsx} 모든 디렉터리의 JavaScript 및 JSX 파일 (GitLab 19.1 이상)

다음 예시는 **/*.rb*.rb의 차이를 보여줍니다:

project/
├── app.rb              ← matched by both *.rb and **/*.rb
├── lib/
│   └── helper.rb       ← matched only by **/*.rb
└── app/
    └── models/
        └── user.rb     ← matched only by **/*.rb
  • *.rb는 app.rb만 일치합니다.

  • **/*.rb는 세 파일 모두와 일치합니다.

mr-review-instructions.yaml 파일에서 **/*.rb를 사용하면 리뷰 지침이 루트 디렉터리뿐만 아니라 프로젝트 구조 어디에 있는 Ruby 파일에도 적용됩니다.

사용 사례 예시#

instructions:
  - name: Assembly Style Guide
    fileFilters:
      - "**/*.asm"
      - "**/*.s"
      - "**/*.S"
    instructions: |
      1. Document the target architecture (x86-64, ARM, RISC-V, AVR, etc.) at the top
      2. Use meaningful labels and comment all non-obvious instructions
      3. Document register usage and calling conventions
      4. Align code sections properly for readability
      5. Include memory layout and stack usage documentation
instructions:
  - name: C Style Guide
    fileFilters:
      - "**/*.c"
      - "**/*.h"
    instructions: |
      1. goto is not allowed
      2. Avoid using global variables
      3. Use meaningful variable names
      4. Add comments for complex logic
instructions:
  - name: C++ Style Guide
    fileFilters:
      - "**/*.cpp"
      - "**/*.{h,hpp}"
    instructions: |
      1. Ensure all methods have proper documentation
      2. Use smart pointers for dynamic memory management
      3. Avoid raw pointers
instructions:
  - name: C# Style Guide
    fileFilters:
      - "**/*.cs"
    instructions: |
      1. Follow Microsoft C# coding conventions
      2. Use XML documentation comments for public APIs
      3. Prefer async/await for asynchronous operations
      4. Use nullable reference types appropriately
      5. Follow .NET naming conventions (PascalCase for public members)
instructions:
  - name: COBOL Style Guide
    fileFilters:
      - "**/*.CBL"
      - "**/*.cbl"
      - "**/*.COB"
      - "**/*.cob"
    instructions: |
      1. Use clear and meaningful names for variables and procedures
      2. Prefer COBOL-85 syntax where possible
      3. Use proper division structure (IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE)
      4. Document all paragraphs and sections with meaningful comments
      5. Use 88-level condition names for boolean flags and status codes
      6. Avoid GO TO statements, prefer PERFORM for structured programming
      7. Use proper error handling with declaratives or status code checking
      8. Define working storage variables with appropriate PICTURE clauses
      9. Use meaningful paragraph names that describe the operation
      10. For mainframe integration, document JCL dependencies and file layouts
instructions:
  - name: Go Style Guide
    fileFilters:
      - "**/*.go"
    instructions: |
      1. Use idiomatic Go practices
      2. Ensure all public functions and types have documentation
      3. Prefer standard library packages over third-party ones when possible
instructions:
  - name: Java Style Guide
    fileFilters:
      - "**/*.java"
    instructions: |
      1. Do not modernize Java 8 code to Java 11+ features, unless there is a GitLab issue or task specifically requesting modernization
      2. All public classes must have Javadoc describing purpose and usage
      3. All public methods must have Javadoc with @param and @return tags
      4. Include code examples in main class Javadoc
      5. All public methods must have at least one test case
instructions:
  - name: JavaScript/TypeScript Files
    fileFilters:
      - "src/**/*.js"
      - "src/**/*.jsx"
      - "src/**/*.ts"
      - "src/**/*.tsx"
      - "!**/*.test.js"
      - "!**/*.test.ts"
      - "!**/*.spec.js"
      - "!**/*.spec.ts"
    instructions: |
      1. Use const/let instead of var
      2. Prefer async/await over promise chains
      3. Add JSDoc comments for complex functions
      4. Ensure proper error handling in async code
      5. Avoid any 'any' types in TypeScript
instructions:
  - name: Kotlin Style Guide
    fileFilters:
      - "**/*.kt"
      - "**/*.kts"
    instructions: |
      1. Follow Kotlin coding conventions
      2. Prefer immutability (val over var)
      3. Use coroutines for asynchronous operations
      4. Leverage Kotlin's null safety features
      5. Document public APIs with KDoc
instructions:
  - name: MATLAB Style Guide
    fileFilters:
      - "**/*.m"
    instructions: |
      1. Use descriptive variable and function names with camelCase convention
      2. Vectorize operations instead of using loops where possible
      3. Document functions with H1 line and help text comments
      4. Preallocate arrays before loops to improve performance
      5. Use proper error handling with try-catch blocks and error() function
instructions:
  - name: Perl Style Guide
    fileFilters:
      - "**/*.pl"
      - "**/*.pm"
    instructions: |
      1. Follow idiomatic Perl practices
      2. Ensure proper module documentation
      3. Use strict and warnings pragmas
instructions:
  - name: PHP Style Guide
    fileFilters:
      - "**/*.php"
    instructions: |
      1. Follow PSR-12 coding standard
      2. Use type declarations for function parameters and return types
      3. Ensure compatibility with PHP 8+
      4. Use proper error handling and exceptions
      5. Document classes and methods with PHPDoc
instructions:
  - name: Python Source Files
    fileFilters:
      - "**/*.py"
      - "!tests/**/*.py"
      - "!test_*.py"
    instructions: |
      1. All functions must have docstrings with parameters and return types
      2. Use type hints for function signatures
      3. Follow PEP 8 style conventions
      4. Ensure proper exception handling
      5. Avoid using bare 'except' clauses

  - name: Python Tests
    fileFilters:
      - "tests/**/*.py"
      - "test_*.py"
    instructions: |
      1. Use pytest fixtures for common setup
      2. Test names should clearly describe the scenario being tested
      3. Include assertions for both expected outcomes and edge cases
      4. Mock external dependencies appropriately
instructions:
  - name: Ruby Style Guide
    fileFilters:
      - "*.rb"
      - "lib/**/*.rb"
      - "!spec/**/*.rb"  # Exclude test files
    instructions: |
      1. Follow Ruby style guide conventions
      2. Prefer symbols over strings for hash keys
      3. Use snake_case for methods/variables, SCREAMING_SNAKE_CASE for constants, CamelCase for classes
      4. Prefer Ruby 3.0+ features (pattern matching, endless methods) where appropriate
      5. Use proper error handling - raise exceptions over returning nil for errors
      6. Write idiomatic Ruby - use blocks, enumerables, and Ruby idioms over procedural patterns
      7. Use meaningful method names - use ? for predicates, ! for dangerous methods
      8. Prefer keyword arguments for methods with multiple parameters
      9. All public methods should have corresponding RSpec/Minitest tests
      10. Manage dependencies with Gemfile and ensure version compatibility
      11. Document thread-safe code and use proper synchronization for concurrent operations
      12. Handle signals (SIGTERM, SIGINT) properly for daemon processes
instructions:
  - name: R Style Guide
    fileFilters:
      - "**/*.r"
      - "**/*.R"
    instructions: |
      1. Follow tidyverse style guide conventions
      2. Use snake_case for variable and function names
      3. Document functions with roxygen2 comments
      4. Prefer vectorized operations over loops
      5. Use proper error handling with tryCatch and stop()
instructions:
  - name: Rust Style Guide
    fileFilters:
      - "**/*.rs"
    instructions: |
      1. Follow Rust idioms and conventions
      2. Use proper error handling with Result and Option types
      3. Avoid unsafe code unless absolutely necessary and well-documented
      4. Ensure all public items have documentation comments
instructions:
  - name: Scala Style Guide
    fileFilters:
      - "**/*.scala"
    instructions: |
      1. Follow Scala style guide conventions
      2. Prefer immutable data structures (val over var)
      3. Use pattern matching effectively for control flow
      4. Document public APIs with ScalaDoc
      5. Use proper error handling with Try, Either, or Option types
instructions:
  - name: Shell Script Style Guide
    fileFilters:
      - "**/*.sh"
      - "**/*.bash"
      - "**/*.zsh"
      - "**/*.ksh"
    instructions: |
      1. Always quote variables to prevent word splitting ("$var" not $var)
      2. Use proper error handling with set -euo pipefail at script start
      3. Document script purpose, parameters, and exit codes in header comments
      4. Prefer [[ ]] over [ ] for conditional tests
      5. Use meaningful function names and avoid complex one-liners
instructions:
  - name: SQL Style Guide
    fileFilters:
      - "**/*.sql"
    instructions: |
      1. Use uppercase for SQL keywords (SELECT, FROM, WHERE, JOIN)
      2. Always specify column names explicitly instead of using SELECT *
      3. For PostgreSQL use SERIAL/RETURNING, for MySQL use AUTO_INCREMENT, for Oracle use SEQUENCE
      4. For NoSQL (MongoDB) use proper indexing and aggregation pipelines to avoid N+1 queries
      5. Document database-specific features and expected performance characteristics
      6. Use proper indentation for complex queries and subqueries
instructions:
  - name: VHDL Style Guide
    fileFilters:
      - "**/*.vhd"
      - "**/*.vhdl"
    instructions: |
      1. Follow IEEE VHDL coding standards
      2. Use meaningful signal and entity names with clear prefixes
      3. Document all entities, architectures, and processes with comments
      4. Use synchronous design practices with proper clock and reset handling
      5. Avoid combinational loops and ensure proper timing constraints
instructions:
  - name: Configuration Files
    fileFilters:
      - "*.yaml"
      - "*.yml"
      - "*.json"
      - "config/**/*"
      - "!.gitlab/**/*"
    instructions: |
      1. Do not include sensitive data (passwords, API keys)
      2. Use environment variables for environment-specific values
      3. Document all configuration options
      4. Validate configuration schema if possible
instructions:
  - name: Ansible Style Guide
    fileFilters:
      - "*.yaml"
      - "*.yml"
      - "playbooks/**/*.yaml"
      - "roles/**/*.yaml"
    instructions: |
      1. Use meaningful play and task names that describe the action
      2. Prefer modules over shell/command tasks when possible
      3. Use variables and defaults for reusability across environments
      4. Implement idempotency - tasks should be safe to run multiple times
      5. Use handlers for service restarts and notifications
      6. Document playbook purpose, required variables, and dependencies

  - name: Dockerfile Style Guide
    fileFilters:
      - "Dockerfile"
      - "*.dockerfile"
      - "Dockerfile.*"
    instructions: |
      1. Use specific base image tags, avoid 'latest'
      2. Minimize layers by combining RUN commands with && where logical
      3. Use multi-stage builds to reduce final image size
      4. Run containers as non-root user for security
      5. Use .dockerignore to exclude unnecessary files
      6. Document exposed ports, volumes, and environment variables

  - name: GitLab CI/CD Style Guide
    fileFilters:
      - ".gitlab-ci.yml"
      - "**/.gitlab-ci.yml"
    instructions: |
      1. Use job extends instead of YAML anchors for reusability
      2. Always use rules instead of only/except for job conditions
      3. Define appropriate caching strategies for dependencies
      4. Use stages to organize pipeline workflow logically
      5. Include security scanning templates (SAST, dependency scanning, secret detection)
      6. Document job purpose, required variables, and dependencies in comments

  - name: Helm Chart Style Guide
    fileFilters:
      - "Chart.yaml"
      - "values.yaml"
      - "templates/**/*.yaml"
    instructions: |
      1. Use semantic versioning for chart versions
      2. Provide sensible defaults in values.yaml with comments
      3. Use template functions for conditional logic and loops
      4. Include NOTES.txt with post-installation instructions
      5. Validate charts with helm lint before committing
      6. Document all configurable values and their purpose

  - name: Kubernetes Style Guide
    fileFilters:
      - "*.yaml"
      - "*.yml"
      - "k8s/**/*.yaml"
      - "kubernetes/**/*.yaml"
    instructions: |
      1. Use explicit API versions and avoid deprecated APIs
      2. Always define resource limits and requests for containers
      3. Use namespaces to organize resources logically
      4. Define liveness and readiness probes for all deployments
      5. Use ConfigMaps and Secrets instead of hardcoded values
      6. Document resource purpose and dependencies in metadata annotations

  - name: Terraform/OpenTofu Style Guide
    fileFilters:
      - "*.tf"
      - "*.tfvars"
    instructions: |
      1. Use consistent naming conventions for resources (environment_service_resource)
      2. Organize code into modules for reusability
      3. Use variables with descriptions and validation rules
      4. Define outputs for important resource attributes
      5. Use remote state with locking for team collaboration
      6. Document module purpose, inputs, outputs, and provider requirements

예시 프로젝트#

더 많은 커스텀 리뷰 지침 사용 사례는 다음 프로덕션 예시를 참조하세요:

문제 해결#

mr-review-instructions.yaml을 사용할 때 다음과 같은 문제가 발생할 수 있습니다.

Code Review Flow가 지침을 건너뛰거나 일반적인 리뷰를 반환함#

Code Review Flow가 커스텀 지침을 건너뛰거나 일반적인 리뷰를 반환하는 경우, 파일에 구조적 문제가 있을 수 있습니다. 커스텀 지침 린터를 사용해 문제를 파악하세요.

커스텀 지침 린터 실행#

커스텀 지침 린터는 mr-review-instructions.yaml 파일의 유효성을 검사하는 데 도움이 됩니다.

린터가 검사하는 항목:

  • 유효하지 않은 YAML 구문.

  • 누락되거나 예상치 못한 최상위 키.

  • 누락되거나 비어 있는 필수 필드(name, instructions).

  • instructions 대신 rules와 같이 지침 항목의 알 수 없는 키.

  • 목록이 아니거나 문자열이 아닌 값 또는 빈 항목이 포함된 fileFilters 값.

  • 누락되거나 비어 있는 fileFilters. 이 경우 지침이 모든 파일에 적용됩니다(정보).

  • 지침 항목 간의 중복된 name 값.

Note

린터는 파일을 읽기만 하며 수정하지 않습니다. GitLab 또는 Rails 의존성이 없으며 Ruby가 설치된 어디서든 실행할 수 있습니다.

사전 요건:

  • Ruby 3.0 이상.

GitLab 서버에서 Rake 작업으로 린터를 실행하려면, <path>mr-review-instructions.yaml 파일의 경로로 바꿉니다. 예시:

sudo gitlab-rake "gitlab:duo:lint_review_instructions[<path>]"

Ruby가 설치된 모든 머신에서 독립 실행형 스크립트로 린터를 실행하려면:

  • review_instructions_linter.rb를 다운로드합니다.

  • 린터를 실행합니다. <path>mr-review-instructions.yaml 파일의 경로로 바꿉니다.

ruby -r ./review_instructions_linter.rb -e '
  linter = Gitlab::Duo::Administration::ReviewInstructionsLinter.new(ARGV[0]).run
  linter.issues.each { |issue| puts issue }
  exit(linter.valid? ? 0 : 1)
' <path>

경로를 생략하면 린터는 작업 디렉터리의 .gitlab/duo/mr-review-instructions.yaml을 기본값으로 사용합니다. 오류가 없으면 린터는 상태 0으로 종료하고, 그렇지 않으면 1로 종료합니다. 경고 및 정보 메시지는 0이 아닌 종료를 유발하지 않습니다.

예를 들어, 이 유효하지 않은 파일은 instructions 대신 rules를 사용하고 fileFilters를 생략합니다:

instructions:
  - name: "General"
    rules: "Do something"

린터 보고 결과:

[ERROR E009] Field 'instructions' must be a non-empty string at instructions[0]
[WARNING W003] Unknown keys: "rules"; expected name, instructions, fileFilters at instructions[0]
[INFO I001] Missing 'fileFilters'; the instruction applies to every file at instructions[0]

보고된 오류를 수정하고 오류가 없을 때까지 린터를 다시 실행합니다.

린터 메시지 코드#

각 메시지에는 도움을 요청할 때 참조할 수 있는 안정적인 코드가 포함됩니다. E로 시작하는 코드는 오류, W로 시작하는 코드는 경고, I로 시작하는 코드는 유효하지만 알아둘 가치가 있는 동작에 대한 정보 노트입니다.

Code Description
E001 지정된 경로에 파일이 존재하지 않습니다.
E003 파일에 유효하지 않은 YAML 구문이 포함되어 있습니다.
E004 최상위 YAML 값이 매핑이 아닙니다.
E005 최상위 instructions 키가 누락되었습니다.
E006 instructions 값이 목록이 아닙니다.
E007 instructions 아래의 항목이 매핑이 아닙니다.
E008 항목의 name 필드가 누락되었거나, 비어 있거나, 문자열이 아닙니다.
E009 항목의 instructions 필드가 누락되었거나, 비어 있거나, 문자열이 아닙니다.
E011 항목의 fileFilters 값이 목록이 아닙니다.
E013 항목의 fileFilters에 숫자와 같은 문자열이 아닌 값이 포함되어 있습니다.
E014 항목의 fileFilters에 빈 문자열이 포함되어 있습니다.
W001 파일에 알 수 없는 최상위 키가 포함되어 있습니다.
W002 instructions 목록이 비어 있으므로 지침이 적용되지 않습니다.
W003 항목에 name, instructions, fileFilters 외의 키가 포함되어 있습니다.
W004 둘 이상의 항목이 동일한 name을 공유합니다.
W007 파일이 비어 있으므로 지침이 적용되지 않습니다.
I001 항목에 fileFilters 필드가 없으므로 지침이 모든 파일에 적용됩니다.
I002 항목의 fileFilters 목록이 비어 있으므로 지침이 모든 파일에 적용됩니다.

관련 항목#

Agent Platform의 커스텀 리뷰 지침 설정

GitLab v19.2
Tier: Premium, Ultimate
Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
원문 보기
요약

GitLab 18.3에서 기능 플래그 duo_code_review_custom_instructions가 기본으로 활성화됨. GitLab 18.4에서 기능 플래그 duo_code_review_custom_instructions가 제거됨.

히스토리
  • GitLab 18.2에서 duo_code_review_custom_instructions라는 플래그와 함께 베타도입됨. 기본적으로 비활성화됨.
  • GitLab 18.3에서 기능 플래그 duo_code_review_custom_instructions기본으로 활성화됨.

  • GitLab 18.4에서 기능 플래그 duo_code_review_custom_instructions제거됨.

  • GitLab 19.1에서 fileFilters의 유니온 패턴(예: {rb,ts})이 도입됨.

머지 리퀘스트를 리뷰할 때 GitLab Duo가 참조할 표준을 제공하는 커스텀 리뷰 지침을 생성합니다.

예를 들어, Ruby 파일에는 Ruby 스타일 규칙을, Go 파일에는 Go 스타일 규칙을 적용하도록 GitLab Duo를 안내할 수 있습니다.

Note

커스텀 리뷰 지침은 AI 리뷰어에 대한 안내이며, 강제되는 정책이 아닙니다. GitLab Duo는 이를 컨텍스트로 활용해 리뷰를 구성하지만, 모든 지침이 모든 경우에 적용된다고 보장할 수 없습니다. 일관된 적용이 필요한 보안 제어, 컴플라이언스 의무, 또는 기타 요건에는 커스텀 지침을 사용하지 마세요.

GitLab Duo는 기존 리뷰 기준을 대체하는 것이 아니라, 커스텀 리뷰 지침을 기존 기준에 추가합니다.

Code Review Flow는 특정 프로젝트 또는 그룹 내 모든 프로젝트에 설정된 커스텀 리뷰 지침을 지원합니다.

프로젝트에 커스텀 리뷰 지침 설정#

커스텀 머지 리퀘스트 리뷰 지침을 설정하려면:

  • 리포지터리 루트에 .gitlab/duo 디렉터리가 없으면 생성합니다.

  • .gitlab/duo 디렉터리에 mr-review-instructions.yaml 파일을 생성합니다.

  • 다음 형식으로 커스텀 지침을 추가합니다:

instructions:
  - name: <instruction_group_name>
    fileFilters:
      - <glob_pattern_1>
      - <glob_pattern_2>
      - !<exclude_pattern>  # Exclude files matching this pattern
    instructions: |
      <your_custom_review_instructions>

fileFilters 섹션은 선택 사항입니다. 이 섹션에서 글로브 패턴을 사용해 특정 파일에만 지침을 적용할 수 있습니다. fileFilters를 생략하거나 비워 두면 GitLab Duo는 머지 리퀘스트의 모든 파일에 해당 지침을 적용합니다.

예시:

instructions:
  - name: Ruby Style Guide
    fileFilters:
      - "*.rb"           # Ruby files in the root directory
      - "lib/**/*.rb"    # Ruby files in lib and its subdirectories
      - "!spec/**/*.rb"  # Exclude test files
    instructions: |
      1. Ensure all methods have proper documentation
      2. Follow Ruby style guide conventions
      3. Prefer symbols over strings for hash keys

  - name: TypeScript Source Files
    fileFilters:
      - "**/*.ts"        # Typescript files in any directory
      - "!**/*.test.ts"  # Exclude test files
      - "!**/*.spec.ts"  # Exclude spec files
    instructions: |
      1. Ensure proper TypeScript types (avoid 'any')
      2. Follow naming conventions
      3. Document complex functions

  - name: All Files Except Tests
    fileFilters:
      - "!**/*.test.*"   # Exclude all test files
      - "!**/*.spec.*"   # Exclude all spec files
      - "!test/**/*"     # Exclude test directories
      - "!spec/**/*"     # Exclude spec directories
    instructions: |
      1. Follow consistent code style
      2. Add meaningful comments for complex logic
      3. Ensure proper error handling

  - name: Test Coverage
    fileFilters:
      - "spec/**/*_spec.rb" # Ruby test files in spec directory
    instructions: |
      1. Test both happy paths and edge cases
      2. Include error scenarios
      3. Use shared examples to reduce duplication

  - name: Database Migrations
    fileFilters:
      - "db/migrate/**/*.rb"
      - "db/post_migrate/**/*.rb"
    instructions: |
      1. Follow the migration safety guidelines in
         https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/development/database/avoiding_downtime_in_migrations.md
      2. Apply the team checklist in docs/migrations-checklist.md

  - name: All Files
    fileFilters:
      - "**/*"   # All files in the repository
    instructions: |
      1. Explain the "why" behind each suggestion

지침에서 파일을 참조하는 방법은 지침에서 파일 참조하기를 참조하세요.

글로브 문법 예시는 파일 패턴 참조를 참조하세요.

  • 선택 사항: mr-review-instructions.yaml 파일 변경을 보호하기 위해 Code Owners 항목을 추가합니다.
[GitLab Duo]
.gitlab/duo @default-owner @tech-lead

GitLab Duo는 파일 패턴이 일치하면 커스텀 지침을 자동으로 적용합니다.

  • 여러 지침 그룹이 하나의 파일에 적용될 수 있습니다. 파일이 둘 이상의 그룹 fileFilters와 일치하면, Code Review Flow는 일치하는 모든 그룹의 지침을 적용합니다.

  • 커스텀 지침으로 트리거된 리뷰 코멘트의 경우, GitLab Duo는 다음 형식을 사용합니다:

According to custom instructions in '[instruction_name]': [feedback comments]

instruction_name 값은 .gitlab/duo/mr-review-instructions.yaml 파일의 name 속성에 해당합니다. GitLab Duo의 표준 코멘트는 이 형식을 사용하지 않습니다.

GitLab Duo가 문제를 발견하지 못한 경우에는 리뷰 요약 코멘트를 남깁니다. 커스텀 지침은 이 요약 코멘트에는 적용되지 않습니다.

  • 선택 사항:

피드백을 검토하고 필요에 따라 지침을 수정합니다.

  • 패턴을 테스트해 의도한 파일과 일치하는지 확인합니다.

그룹에 커스텀 리뷰 지침 설정#

히스토리

템플릿으로 사용할 프로젝트를 지정해 그룹의 커스텀 리뷰 지침을 정의할 수 있습니다. 템플릿 프로젝트에는 그룹 및 하위 그룹의 모든 프로젝트에 적용되는 리뷰 지침이 담긴 .gitlab/duo/mr-review-instructions.yaml 파일이 있어야 합니다.

GitLab Duo가 코드 리뷰를 수행하면, 최상위 그룹의 지침과 개별 프로젝트에 정의된 지침을 결합합니다.

사전 요건:

  • 최상위 그룹에 대한 Owner 권한.

  • 그룹 내 프로젝트에 템플릿으로 사용할 커스텀 리뷰 지침이 포함되어 있어야 합니다.

그룹에 커스텀 리뷰 지침을 설정하려면:

  • 상단 바에서 Search or go to를 선택하고 최상위 그룹을 찾습니다.

  • 왼쪽 사이드바에서 Settings > General > GitLab Duo features를 선택합니다.

  • Custom review instructions for groups 아래에서 그룹의 리뷰 지침이 담긴 .gitlab/duo/mr-review-instructions.yaml 파일을 포함하는 프로젝트를 선택합니다.

  • Save changes를 선택합니다.

지침에서 파일 참조하기#

콘텐츠를 중복하는 대신 커스텀 지침에서 다른 파일을 참조할 수 있습니다. Code Review Flow는 사전 스캔 단계에서 참조된 파일을 읽고 관련 안내를 추출합니다.

커스텀 지침은 두 가지 파일 참조 패턴을 지원합니다:

  • 머지 리퀘스트와 동일한 프로젝트의 파일: docs/security-checklist.md와 같이 리포지터리 상대 경로를 사용합니다.

  • 동일한 GitLab 인스턴스의 다른 프로젝트에 있는 파일: 다음과 같이 완전한 GitLab blob URL을 사용합니다: https://gitlab.example.com/group/project/-/blob/main/docs/style-guide.md. URL은 머지 리퀘스트와 동일한 GitLab 인스턴스를 가리켜야 하며 /-/blob/<ref>/<path> 형식을 사용해야 합니다.

예시:

instructions:
  - name: Database Migrations
    fileFilters:
      - "db/migrate/**/*.rb"
    instructions: |
      1. Follow the migration guidelines in
         https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/development/database/avoiding_downtime_in_migrations.md
      2. Reference the team checklist in docs/db-checklist.md

파일 참조의 제한 사항#

파일 참조 해석에는 다음과 같은 제약이 있습니다:

  • 동일한 GitLab 인스턴스만 가능. 다른 GitLab 인스턴스, GitLab Self-Managed 인스턴스에서 공개 GitLab으로, 또는 Confluence나 공개 문서 사이트와 같은 비 GitLab 사이트를 가리키는 URL은 가져오지 않습니다.

  • /-/blob/<ref>/<path> 형식의 Blob URL만 가능. Wiki 페이지, 이슈, raw URL, 스니펫은 가져오지 않습니다.

  • 동일 프로젝트에서의 단순 경로. docs/security.md와 같은 단순 경로는 머지 리퀘스트와 동일한 프로젝트를 기준으로 해석됩니다. 다른 프로젝트의 파일을 참조하려면 완전한 GitLab blob URL을 사용하세요.

  • 최선의 노력이며 보장되지 않음. Code Review Flow는 지침 텍스트를 기반으로 가져올 참조를 결정합니다. 존재하지 않는 경로나 파서가 거부하는 URL처럼 해석에 실패한 참조는 조용히 건너뜁니다.

  • Code Review Flow는 원본 파일이 아닌 요약본을 사용. 사전 스캔 단계에서 가져온 콘텐츠를 요약하고 리뷰 중 해당 요약을 사용합니다. 동일한 머지 리퀘스트에 대한 두 번의 리뷰는 서로 다른 요약을 생성할 수 있습니다.

Code Review Flow가 요약본이 아닌 정확한 파일 내용을 사용하도록 하려면, 파일을 참조하는 대신 instructions: 필드에 직접 포함하세요. 인라인 지침은 작성된 그대로 사용됩니다.

모범 사례#

커스텀 리뷰 지침을 작성할 때:

  • 구체적이고 실행 가능하게 작성하세요. Code Review Flow는 각 규칙을 diff와 대조합니다. 예를 들어, "공개 메서드에 YARD 문서가 있는지 확인하세요"와 같이 구체적인 규칙은 유용한 코멘트를 생성하지만, "코드를 잘 문서화하세요"와 같은 추상적인 안내는 그렇지 않습니다.

  • 명확성을 위해 지침에 번호를 매기세요.

  • 가장 중요한 표준에 집중하세요. 모든 규칙의 텍스트는 리뷰 프롬프트의 일부가 되므로, 가치가 낮은 규칙의 긴 목록은 신호를 추가하지 않고 프롬프트만 늘립니다.

  • 도움이 될 때는 "왜"를 설명하세요.

  • 간단한 지침부터 시작하고 필요에 따라 복잡성을 추가하세요.

  • Code Review Flow가 기본적으로 적용하지 않는 프로젝트별 표준에 집중하세요. 커스텀 지침은 기존 리뷰 기준을 대체하는 것이 아니라 추가합니다. "오류 처리 추가" 또는 "의미 있는 이름 사용"과 같은 일반적인 조언은 이미 포함되어 있는 경우가 많습니다. 커스텀 지침은 프로젝트만이 알고 있는 것에 사용하세요: 내부 API, 아키텍처 규칙, 도메인별 패턴.

  • 지침은 지시가 아닌 안내로 작성하세요. 지침은 리뷰 동작을 형성하는 힌트이지, GitLab Duo가 반드시 따라야 하는 정책이 아닙니다. "항상 플래그 지정" 또는 "절대 허용하지 않음"과 같은 표현을 피하세요. 이런 표현은 협업자가 해당 동작이 보장된다고 오해할 수 있습니다.

  • 파일 패턴이 규칙의 실제 범위를 반영하도록 하세요. Code Review Flow는 각 fileFilters 참조와 함께 각 지침을 읽고 해당 패턴과 일치하는 파일에만 규칙을 적용합니다. 예를 들어, **/*.rb로 범위 지정된 "Rails controllers" 규칙은 컨트롤러뿐만 아니라 gem, 스크립트, 테스트에도 적용됩니다. 대신 app/controllers/**/*.rb를 사용하세요.

  • 정확한 표현이 중요하지 않은 지침에만 외부 파일 참조를 사용하고, 그렇지 않은 경우에는 instructions: 필드에 직접 규칙으로 포함하세요. Code Review Flow는 참조된 파일에 대해 요약을 생성하고 사용하지만, instructions에 정의된 정확한 표현을 사용합니다.

예시:

instructions: |
  1. All public functions must include docstrings with parameter descriptions
  2. Use parameterized queries to prevent SQL injection
  3. Validate user input before processing (check type, length, format)
  4. Include error handling for all external API calls
  5. Avoid hardcoded credentials - use environment variables

언어별 예시는 사용 사례 예시를 참조하세요.

파일 패턴 참조#

fileFilters에서 글로브 패턴을 사용해 특정 파일을 타깃으로 설정합니다.

예를 들어, Ruby 파일이 포함된 프로젝트의 경우:

Pattern Match
**/*.rb 모든 디렉터리의 Ruby 파일
*.rb 루트 디렉터리의 Ruby 파일만
lib/**/*.rb lib 디렉터리 및 하위 디렉터리의 Ruby 파일
!**/*.test.rb 모든 Ruby 테스트 파일 제외
!spec/**/*.rb spec 디렉터리 및 하위 디렉터리의 모든 Ruby 파일 제외
!tests/**/* tests 디렉터리 및 하위 디렉터리의 모든 파일 제외
**/*.{js,jsx} 모든 디렉터리의 JavaScript 및 JSX 파일 (GitLab 19.1 이상)

다음 예시는 **/*.rb*.rb의 차이를 보여줍니다:

project/
├── app.rb              ← matched by both *.rb and **/*.rb
├── lib/
│   └── helper.rb       ← matched only by **/*.rb
└── app/
    └── models/
        └── user.rb     ← matched only by **/*.rb
  • *.rb는 app.rb만 일치합니다.

  • **/*.rb는 세 파일 모두와 일치합니다.

mr-review-instructions.yaml 파일에서 **/*.rb를 사용하면 리뷰 지침이 루트 디렉터리뿐만 아니라 프로젝트 구조 어디에 있는 Ruby 파일에도 적용됩니다.

사용 사례 예시#

instructions:
  - name: Assembly Style Guide
    fileFilters:
      - "**/*.asm"
      - "**/*.s"
      - "**/*.S"
    instructions: |
      1. Document the target architecture (x86-64, ARM, RISC-V, AVR, etc.) at the top
      2. Use meaningful labels and comment all non-obvious instructions
      3. Document register usage and calling conventions
      4. Align code sections properly for readability
      5. Include memory layout and stack usage documentation
instructions:
  - name: C Style Guide
    fileFilters:
      - "**/*.c"
      - "**/*.h"
    instructions: |
      1. goto is not allowed
      2. Avoid using global variables
      3. Use meaningful variable names
      4. Add comments for complex logic
instructions:
  - name: C++ Style Guide
    fileFilters:
      - "**/*.cpp"
      - "**/*.{h,hpp}"
    instructions: |
      1. Ensure all methods have proper documentation
      2. Use smart pointers for dynamic memory management
      3. Avoid raw pointers
instructions:
  - name: C# Style Guide
    fileFilters:
      - "**/*.cs"
    instructions: |
      1. Follow Microsoft C# coding conventions
      2. Use XML documentation comments for public APIs
      3. Prefer async/await for asynchronous operations
      4. Use nullable reference types appropriately
      5. Follow .NET naming conventions (PascalCase for public members)
instructions:
  - name: COBOL Style Guide
    fileFilters:
      - "**/*.CBL"
      - "**/*.cbl"
      - "**/*.COB"
      - "**/*.cob"
    instructions: |
      1. Use clear and meaningful names for variables and procedures
      2. Prefer COBOL-85 syntax where possible
      3. Use proper division structure (IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE)
      4. Document all paragraphs and sections with meaningful comments
      5. Use 88-level condition names for boolean flags and status codes
      6. Avoid GO TO statements, prefer PERFORM for structured programming
      7. Use proper error handling with declaratives or status code checking
      8. Define working storage variables with appropriate PICTURE clauses
      9. Use meaningful paragraph names that describe the operation
      10. For mainframe integration, document JCL dependencies and file layouts
instructions:
  - name: Go Style Guide
    fileFilters:
      - "**/*.go"
    instructions: |
      1. Use idiomatic Go practices
      2. Ensure all public functions and types have documentation
      3. Prefer standard library packages over third-party ones when possible
instructions:
  - name: Java Style Guide
    fileFilters:
      - "**/*.java"
    instructions: |
      1. Do not modernize Java 8 code to Java 11+ features, unless there is a GitLab issue or task specifically requesting modernization
      2. All public classes must have Javadoc describing purpose and usage
      3. All public methods must have Javadoc with @param and @return tags
      4. Include code examples in main class Javadoc
      5. All public methods must have at least one test case
instructions:
  - name: JavaScript/TypeScript Files
    fileFilters:
      - "src/**/*.js"
      - "src/**/*.jsx"
      - "src/**/*.ts"
      - "src/**/*.tsx"
      - "!**/*.test.js"
      - "!**/*.test.ts"
      - "!**/*.spec.js"
      - "!**/*.spec.ts"
    instructions: |
      1. Use const/let instead of var
      2. Prefer async/await over promise chains
      3. Add JSDoc comments for complex functions
      4. Ensure proper error handling in async code
      5. Avoid any 'any' types in TypeScript
instructions:
  - name: Kotlin Style Guide
    fileFilters:
      - "**/*.kt"
      - "**/*.kts"
    instructions: |
      1. Follow Kotlin coding conventions
      2. Prefer immutability (val over var)
      3. Use coroutines for asynchronous operations
      4. Leverage Kotlin's null safety features
      5. Document public APIs with KDoc
instructions:
  - name: MATLAB Style Guide
    fileFilters:
      - "**/*.m"
    instructions: |
      1. Use descriptive variable and function names with camelCase convention
      2. Vectorize operations instead of using loops where possible
      3. Document functions with H1 line and help text comments
      4. Preallocate arrays before loops to improve performance
      5. Use proper error handling with try-catch blocks and error() function
instructions:
  - name: Perl Style Guide
    fileFilters:
      - "**/*.pl"
      - "**/*.pm"
    instructions: |
      1. Follow idiomatic Perl practices
      2. Ensure proper module documentation
      3. Use strict and warnings pragmas
instructions:
  - name: PHP Style Guide
    fileFilters:
      - "**/*.php"
    instructions: |
      1. Follow PSR-12 coding standard
      2. Use type declarations for function parameters and return types
      3. Ensure compatibility with PHP 8+
      4. Use proper error handling and exceptions
      5. Document classes and methods with PHPDoc
instructions:
  - name: Python Source Files
    fileFilters:
      - "**/*.py"
      - "!tests/**/*.py"
      - "!test_*.py"
    instructions: |
      1. All functions must have docstrings with parameters and return types
      2. Use type hints for function signatures
      3. Follow PEP 8 style conventions
      4. Ensure proper exception handling
      5. Avoid using bare 'except' clauses

  - name: Python Tests
    fileFilters:
      - "tests/**/*.py"
      - "test_*.py"
    instructions: |
      1. Use pytest fixtures for common setup
      2. Test names should clearly describe the scenario being tested
      3. Include assertions for both expected outcomes and edge cases
      4. Mock external dependencies appropriately
instructions:
  - name: Ruby Style Guide
    fileFilters:
      - "*.rb"
      - "lib/**/*.rb"
      - "!spec/**/*.rb"  # Exclude test files
    instructions: |
      1. Follow Ruby style guide conventions
      2. Prefer symbols over strings for hash keys
      3. Use snake_case for methods/variables, SCREAMING_SNAKE_CASE for constants, CamelCase for classes
      4. Prefer Ruby 3.0+ features (pattern matching, endless methods) where appropriate
      5. Use proper error handling - raise exceptions over returning nil for errors
      6. Write idiomatic Ruby - use blocks, enumerables, and Ruby idioms over procedural patterns
      7. Use meaningful method names - use ? for predicates, ! for dangerous methods
      8. Prefer keyword arguments for methods with multiple parameters
      9. All public methods should have corresponding RSpec/Minitest tests
      10. Manage dependencies with Gemfile and ensure version compatibility
      11. Document thread-safe code and use proper synchronization for concurrent operations
      12. Handle signals (SIGTERM, SIGINT) properly for daemon processes
instructions:
  - name: R Style Guide
    fileFilters:
      - "**/*.r"
      - "**/*.R"
    instructions: |
      1. Follow tidyverse style guide conventions
      2. Use snake_case for variable and function names
      3. Document functions with roxygen2 comments
      4. Prefer vectorized operations over loops
      5. Use proper error handling with tryCatch and stop()
instructions:
  - name: Rust Style Guide
    fileFilters:
      - "**/*.rs"
    instructions: |
      1. Follow Rust idioms and conventions
      2. Use proper error handling with Result and Option types
      3. Avoid unsafe code unless absolutely necessary and well-documented
      4. Ensure all public items have documentation comments
instructions:
  - name: Scala Style Guide
    fileFilters:
      - "**/*.scala"
    instructions: |
      1. Follow Scala style guide conventions
      2. Prefer immutable data structures (val over var)
      3. Use pattern matching effectively for control flow
      4. Document public APIs with ScalaDoc
      5. Use proper error handling with Try, Either, or Option types
instructions:
  - name: Shell Script Style Guide
    fileFilters:
      - "**/*.sh"
      - "**/*.bash"
      - "**/*.zsh"
      - "**/*.ksh"
    instructions: |
      1. Always quote variables to prevent word splitting ("$var" not $var)
      2. Use proper error handling with set -euo pipefail at script start
      3. Document script purpose, parameters, and exit codes in header comments
      4. Prefer [[ ]] over [ ] for conditional tests
      5. Use meaningful function names and avoid complex one-liners
instructions:
  - name: SQL Style Guide
    fileFilters:
      - "**/*.sql"
    instructions: |
      1. Use uppercase for SQL keywords (SELECT, FROM, WHERE, JOIN)
      2. Always specify column names explicitly instead of using SELECT *
      3. For PostgreSQL use SERIAL/RETURNING, for MySQL use AUTO_INCREMENT, for Oracle use SEQUENCE
      4. For NoSQL (MongoDB) use proper indexing and aggregation pipelines to avoid N+1 queries
      5. Document database-specific features and expected performance characteristics
      6. Use proper indentation for complex queries and subqueries
instructions:
  - name: VHDL Style Guide
    fileFilters:
      - "**/*.vhd"
      - "**/*.vhdl"
    instructions: |
      1. Follow IEEE VHDL coding standards
      2. Use meaningful signal and entity names with clear prefixes
      3. Document all entities, architectures, and processes with comments
      4. Use synchronous design practices with proper clock and reset handling
      5. Avoid combinational loops and ensure proper timing constraints
instructions:
  - name: Configuration Files
    fileFilters:
      - "*.yaml"
      - "*.yml"
      - "*.json"
      - "config/**/*"
      - "!.gitlab/**/*"
    instructions: |
      1. Do not include sensitive data (passwords, API keys)
      2. Use environment variables for environment-specific values
      3. Document all configuration options
      4. Validate configuration schema if possible
instructions:
  - name: Ansible Style Guide
    fileFilters:
      - "*.yaml"
      - "*.yml"
      - "playbooks/**/*.yaml"
      - "roles/**/*.yaml"
    instructions: |
      1. Use meaningful play and task names that describe the action
      2. Prefer modules over shell/command tasks when possible
      3. Use variables and defaults for reusability across environments
      4. Implement idempotency - tasks should be safe to run multiple times
      5. Use handlers for service restarts and notifications
      6. Document playbook purpose, required variables, and dependencies

  - name: Dockerfile Style Guide
    fileFilters:
      - "Dockerfile"
      - "*.dockerfile"
      - "Dockerfile.*"
    instructions: |
      1. Use specific base image tags, avoid 'latest'
      2. Minimize layers by combining RUN commands with && where logical
      3. Use multi-stage builds to reduce final image size
      4. Run containers as non-root user for security
      5. Use .dockerignore to exclude unnecessary files
      6. Document exposed ports, volumes, and environment variables

  - name: GitLab CI/CD Style Guide
    fileFilters:
      - ".gitlab-ci.yml"
      - "**/.gitlab-ci.yml"
    instructions: |
      1. Use job extends instead of YAML anchors for reusability
      2. Always use rules instead of only/except for job conditions
      3. Define appropriate caching strategies for dependencies
      4. Use stages to organize pipeline workflow logically
      5. Include security scanning templates (SAST, dependency scanning, secret detection)
      6. Document job purpose, required variables, and dependencies in comments

  - name: Helm Chart Style Guide
    fileFilters:
      - "Chart.yaml"
      - "values.yaml"
      - "templates/**/*.yaml"
    instructions: |
      1. Use semantic versioning for chart versions
      2. Provide sensible defaults in values.yaml with comments
      3. Use template functions for conditional logic and loops
      4. Include NOTES.txt with post-installation instructions
      5. Validate charts with helm lint before committing
      6. Document all configurable values and their purpose

  - name: Kubernetes Style Guide
    fileFilters:
      - "*.yaml"
      - "*.yml"
      - "k8s/**/*.yaml"
      - "kubernetes/**/*.yaml"
    instructions: |
      1. Use explicit API versions and avoid deprecated APIs
      2. Always define resource limits and requests for containers
      3. Use namespaces to organize resources logically
      4. Define liveness and readiness probes for all deployments
      5. Use ConfigMaps and Secrets instead of hardcoded values
      6. Document resource purpose and dependencies in metadata annotations

  - name: Terraform/OpenTofu Style Guide
    fileFilters:
      - "*.tf"
      - "*.tfvars"
    instructions: |
      1. Use consistent naming conventions for resources (environment_service_resource)
      2. Organize code into modules for reusability
      3. Use variables with descriptions and validation rules
      4. Define outputs for important resource attributes
      5. Use remote state with locking for team collaboration
      6. Document module purpose, inputs, outputs, and provider requirements

예시 프로젝트#

더 많은 커스텀 리뷰 지침 사용 사례는 다음 프로덕션 예시를 참조하세요:

문제 해결#

mr-review-instructions.yaml을 사용할 때 다음과 같은 문제가 발생할 수 있습니다.

Code Review Flow가 지침을 건너뛰거나 일반적인 리뷰를 반환함#

Code Review Flow가 커스텀 지침을 건너뛰거나 일반적인 리뷰를 반환하는 경우, 파일에 구조적 문제가 있을 수 있습니다. 커스텀 지침 린터를 사용해 문제를 파악하세요.

커스텀 지침 린터 실행#

커스텀 지침 린터는 mr-review-instructions.yaml 파일의 유효성을 검사하는 데 도움이 됩니다.

린터가 검사하는 항목:

  • 유효하지 않은 YAML 구문.

  • 누락되거나 예상치 못한 최상위 키.

  • 누락되거나 비어 있는 필수 필드(name, instructions).

  • instructions 대신 rules와 같이 지침 항목의 알 수 없는 키.

  • 목록이 아니거나 문자열이 아닌 값 또는 빈 항목이 포함된 fileFilters 값.

  • 누락되거나 비어 있는 fileFilters. 이 경우 지침이 모든 파일에 적용됩니다(정보).

  • 지침 항목 간의 중복된 name 값.

Note

린터는 파일을 읽기만 하며 수정하지 않습니다. GitLab 또는 Rails 의존성이 없으며 Ruby가 설치된 어디서든 실행할 수 있습니다.

사전 요건:

  • Ruby 3.0 이상.

GitLab 서버에서 Rake 작업으로 린터를 실행하려면, <path>mr-review-instructions.yaml 파일의 경로로 바꿉니다. 예시:

sudo gitlab-rake "gitlab:duo:lint_review_instructions[<path>]"

Ruby가 설치된 모든 머신에서 독립 실행형 스크립트로 린터를 실행하려면:

  • review_instructions_linter.rb를 다운로드합니다.

  • 린터를 실행합니다. <path>mr-review-instructions.yaml 파일의 경로로 바꿉니다.

ruby -r ./review_instructions_linter.rb -e '
  linter = Gitlab::Duo::Administration::ReviewInstructionsLinter.new(ARGV[0]).run
  linter.issues.each { |issue| puts issue }
  exit(linter.valid? ? 0 : 1)
' <path>

경로를 생략하면 린터는 작업 디렉터리의 .gitlab/duo/mr-review-instructions.yaml을 기본값으로 사용합니다. 오류가 없으면 린터는 상태 0으로 종료하고, 그렇지 않으면 1로 종료합니다. 경고 및 정보 메시지는 0이 아닌 종료를 유발하지 않습니다.

예를 들어, 이 유효하지 않은 파일은 instructions 대신 rules를 사용하고 fileFilters를 생략합니다:

instructions:
  - name: "General"
    rules: "Do something"

린터 보고 결과:

[ERROR E009] Field 'instructions' must be a non-empty string at instructions[0]
[WARNING W003] Unknown keys: "rules"; expected name, instructions, fileFilters at instructions[0]
[INFO I001] Missing 'fileFilters'; the instruction applies to every file at instructions[0]

보고된 오류를 수정하고 오류가 없을 때까지 린터를 다시 실행합니다.

린터 메시지 코드#

각 메시지에는 도움을 요청할 때 참조할 수 있는 안정적인 코드가 포함됩니다. E로 시작하는 코드는 오류, W로 시작하는 코드는 경고, I로 시작하는 코드는 유효하지만 알아둘 가치가 있는 동작에 대한 정보 노트입니다.

Code Description
E001 지정된 경로에 파일이 존재하지 않습니다.
E003 파일에 유효하지 않은 YAML 구문이 포함되어 있습니다.
E004 최상위 YAML 값이 매핑이 아닙니다.
E005 최상위 instructions 키가 누락되었습니다.
E006 instructions 값이 목록이 아닙니다.
E007 instructions 아래의 항목이 매핑이 아닙니다.
E008 항목의 name 필드가 누락되었거나, 비어 있거나, 문자열이 아닙니다.
E009 항목의 instructions 필드가 누락되었거나, 비어 있거나, 문자열이 아닙니다.
E011 항목의 fileFilters 값이 목록이 아닙니다.
E013 항목의 fileFilters에 숫자와 같은 문자열이 아닌 값이 포함되어 있습니다.
E014 항목의 fileFilters에 빈 문자열이 포함되어 있습니다.
W001 파일에 알 수 없는 최상위 키가 포함되어 있습니다.
W002 instructions 목록이 비어 있으므로 지침이 적용되지 않습니다.
W003 항목에 name, instructions, fileFilters 외의 키가 포함되어 있습니다.
W004 둘 이상의 항목이 동일한 name을 공유합니다.
W007 파일이 비어 있으므로 지침이 적용되지 않습니다.
I001 항목에 fileFilters 필드가 없으므로 지침이 모든 파일에 적용됩니다.
I002 항목의 fileFilters 목록이 비어 있으므로 지침이 모든 파일에 적용됩니다.

관련 항목#