Skip to content

Automation - Integrate gitStream with Ruby

Approve Ruby Log Output Changes

Approve changes to Ruby files that only affect lines of code that invoke the logger object.

approve Ruby log output

Configuration Description

Conditions (all must be true):

  • All files end in .rb
  • The changes only affect lines of code that invoke logger object.

Automation Actions:

  • Apply a log-output-only label
  • Approve the PR
  • Post a comment explaining that the change only affects logging output.

Approve Ruby Log Output Changes

# -*- mode: yaml -*-

manifest:
  version: 1.0

automations:
  approve_ruby_log_output:
    # Triggered for Ruby changes that only affect the logger method
    if: 
      - {{ files | extensions | match(term='rb') | every }}
      - {{ source.diff.files | matchDiffLines(regex=r/^.*logger\.(fatal|debug|info|warn|error)/, ignoreWhiteSpaces=true) | every }}
    run: 
      - action: add-label@v1
        args:
          label: 'log-output-only'
      - action: approve@v1
      - action: add-comment@v1
        args:
          comment: |
            This PR has been approved because it only contains changes to log output

Review Missing Ruby Tests

Automatically request changes for Ruby PRs that lack test files.

Review Missing Ruby Tests

Configuration Description

Conditions (all must be true):

  • The PR creates one or more new Ruby files
  • The PR lacks new test files that match the name of the Ruby files

Automation Actions:

  • Apply a red missing-tests label
  • Request changes and post a comment listing the files that need tests.

Review Missing Ruby Tests

# -*- mode: yaml -*-
manifest:
  version: 1.0

newFiles: {{ source.diff.files | filter(attr='new_file', regex=r/^app\/(?!.*\_spec\.rb$).*\.rb$/) | filter(attr='original_file', regex=r/^$/) | map(attr='new_file') }}
newTests: {{ source.diff.files | filter(attr='new_file', regex=r/spec\/.*\_spec\.rb$/) | filter(attr='original_file', regex=r/^$/) | map(attr='new_file') }}

newFilesCount: {{ source.diff.files | filter(attr='new_file', regex=r/^app\/(?!.*\_spec\.rb$).*\.rb$/) | filter(attr='original_file', regex=r/^$/) | length }}
newTestsCount: {{ source.diff.files | filter(attr='new_file', regex=r/spec\/.*\_spec\.rb$/) | filter(attr='original_file', regex=r/^$/) | length }}

automations:
  review_missing_ruby_tests:
    if:
      - {{ newFilesCount != newTestsCount }}
    run: 
      - action: add-label@v1
        args:
            label: "⚠️ Missing Tests"
            color: {{ colors.orange }}    
      - action: request-changes@v1
        args:
          comment: |
            Some of your new Ruby files are missing corresponding tests. Please ensure that all new files have a corresponding test file.

            **New Files**: {{ newFilesCount }}
            {{ newFiles }}

            **New Tests**: {{ newTestsCount }}
            {{ newTests }}
colors:
  orange: 'd93f0b'

Review Ruby Test Name

Automatically request changes for Ruby test files that fail to match the required naming convention.

Review Ruby Test Name

Configuration Description

Conditions (all must be true):

  • The PR creates one or more new Ruby test files
  • The Ruby test fails to match the required naming convention.

Automation Actions:

  • Request changes and post a comment that explains the Ruby test name requirements.

Review Ruby Test Name

# -*- mode: yaml -*-
manifest:
  version: 1.0
newTests: {{ source.diff.files | filter(attr='new_file', regex=r/^spec/) }}
newTestsCount: {{ source.diff.files | filter(attr='new_file', regex=r/^spec/) | length }}

automations:
  review_ruby_test_name:
    if:
      - {{ newTestsCount > 0}}     
      - {{ source.diff.files | filter(attr='new_file', regex=r/^spec/) | match(attr='new_file', regex=r/_spec.rb$/) | nope }}
    run: 
      - action: request-changes@v1
        args:
          comment: |
              The test file name does not follow the Ruby test name conventions. A test file name needs to have the suffix _spec after class name. For example, if you are testing a class file called data.rb then the test file name has to be data_spec.rb.

Additional Resources

gitStream is a workflow automation tool that enables you to use YAML configuration files to optimize your code review process. Add context to PRs, find code experts for reviews, and automate the merge process to maximize developer productivity.

Learn More about how gitStream Works.

More Automations can be found on the Automation Library and Integrations pages.

Special thanks to Boemo W Mmopelwa for providing these examples.