Skip to content

Automation - Integrate gitStream with Java

Approve Java Log Output Changes

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

approve Java log output

Configuration Description

Conditions (all must be true):

  • All files end in .java
  • 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 Java Log Output Changes

# -*- mode: yaml -*-

manifest:
  version: 1.0

automations:
  approve_java_log_output:
    # Triggered for Java changes that only affect the logger method
    if: 
      - {{ files | extensions | match(term='java') | every }}
      - {{ source.diff.files | matchDiffLines(regex=r/^.*logger\.(trace|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 Java Tests

Automatically request changes for Java PRs that lack test files.

Review Missing Java Tests

Configuration Description

Conditions (all must be true):

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

Automation Actions:

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

Review Missing Java Tests

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

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

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

automations:
  review_missing_java_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 Java 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 Java Test Names

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

Review Java Test Name

Configuration Description

Conditions (all must be true):

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

Automation Actions:

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

Review Java Test Name

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

automations:
  review_java_test_name:
    if:
       - {{ newTestsCount > 0}}     
       - {{ source.diff.files | filter(attr='new_file', regex=r/^src\/test\/) | match(attr='new_file', regex=r/Test.java$/) | nope }}

    run: 
      - action: request-changes@v1
        args:
          comment: |
              The test file name does not follow the Java test name conventions. A test file name needs to have the word Test at the end of class name. For example, if you are testing a class called Data then the test file name has to be DataTest.java.

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.