Automation - Integrate gitStream with JavaScript
Auto-Approve JavaScript Log Output Changes
Approve changes to JavaScript files that only affect lines of code that invoke the console.log() method.
Configuration Description
Conditions (all must be true):
- All files must end in .js or .ts
- The changes only affect lines of code that invoke console.log()
Automation Actions:
- Applies a
log-output-only
label - Approves the PR
- Posts a comment explaining that the change only affects logging output.
Approve JavaScript Log Output Changes
# -*- mode: yaml -*-
manifest:
version: 1.0
automations:
approve_javascript_log_output:
# Triggered for JavaScript changes that only affect the console.log() method
if:
- {{ files | match(regex=r/\.js$|\.ts$/) | every }}
- {{ source.diff.files | matchDiffLines(regex=r/^[+-].*console\.log/, 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
Auto-Approve JavaScript Formatting Change
Approve PRs that only contain formatting changes to JavaScript or TypeScript files.
Configuration Description
Conditions (all must be true):
- All of the files end in
.js
or.ts
- All changes are non-functional
Automation Actions:
- Approve the PR
- Apply a
code-formatting
label. - Post a comment that explains the automation.
Approve JavaScript Formatting Change
# -*- mode: yaml -*-
manifest:
version: 1.0
automations:
approve_javascript_formatting:
if:
- {{ files | extensions | match(list=['js', 'ts']) | every }}
- {{ source.diff.files | isFormattingChange }}
run:
- action: approve@v1
- action: add-label@v1
args:
label: code-formatting
- action: add-comment@v1
args:
comment: |
This PR only contains formatting changes and has been approved.
Review Missing JavaScript Tests
Request changes for JavaScript PRs that lack test files.
Configuration Description
Conditions (all must be true):
- The PR creates one or more new JavaScript files
- The PR lacks new test files that match the name of the JavaScript files
Automation Actions:
- Apply a red
missing-tests
label - Request changes and post a comment listing the files that need tests.
Review Missing JavaScript Tests
# -*- mode: yaml -*-
manifest:
version: 1.0
newFiles: {{ source.diff.files | filter(attr='new_file', regex=r/^src\/(?!.*\.test\.js$).*\.js$/) | filter(attr='original_file', regex=r/^$/) | map(attr='new_file') }}
newTests: {{ source.diff.files | filter(attr='new_file', regex=r/src\/.*\.test\.js$/) | filter(attr='original_file', regex=r/^$/) | map(attr='new_file') }}
newFilesCount: {{ source.diff.files | filter(attr='new_file', regex=r/^src\/(?!.*\.test\.js$).*\.js$/) | filter(attr='original_file', regex=r/^$/) | length }}
newTestsCount: {{ source.diff.files | filter(attr='new_file', regex=r/src\/.*\.test\.js$/) | filter(attr='original_file', regex=r/^$/) | length }}
automations:
review_missing_javascript_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 JavaScript 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 JavaScript Test Name
Automatically request changes for JavaScript test files that fail to match the required naming convention.
Configuration Description
Conditions (all must be true):
- The PR creates one or more new JavaScript test files
- The JavaScript test fails to match the required naming convention.
Automation Actions:
- Request changes and post a comment that explains the JavaScript test name requirements.
Review JavaScript Test Name
# -*- mode: yaml -*-
manifest:
version: 1.0
newTests: {{ source.diff.files | filter(attr='new_file', regex=r/^test/) }}
newTestsCount: {{ source.diff.files | filter(attr='new_file', regex=r/^test/) | length }}
automations:
review_javascript_test_name:
if:
- {{ newTestsCount > 0}}
- {{ source.diff.files | filter(attr='new_file', regex=r/^test/) | match(attr='new_file', regex=r/.test.js$/) | nope }}
run:
- action: request-changes@v1
args:
comment: |
The test file name does not follow the JavaScript test name conventions. A test file name needs to have the suffix .test after class name. For example, if you are testing a class file called Data.js then the test file name has to be data.test.js.
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.