Automation - Integrate gitStream with Golang
Approve Golang Log Output Changes
Approve changes to Golang files that only affect lines of code that invoke the logger object.
Configuration Description
Conditions (all must be true):
- All files end in
.go
- The changes only affect lines of code that invoke the
log
object.
Automation Actions:
- Apply a
log-output-only
label - Approve the PR
- Post a comment explaining that the change only affects logging output.
Approve Golang Log Output Changes
# -*- mode: yaml -*-
manifest:
version: 1.0
automations:
approve_golang_log_output:
# Triggered for Golang changes that only affect the console.log() method
if:
- {{ files | extensions | match(term='go') | every }}
- {{ source.diff.files | matchDiffLines(regex=r/^.*log\.Println/, 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 Golang Tests
Automatically request changes for Golang PRs that are missing tests.
Configuration Description
Conditions (all must be true):
- The PR creates one or more new Golang files
- The PR lacks new test files that match the name of the Golang files
Automation Actions:
- The PR lacks new test files that match the name of the Golang files
- Apply a red missing-tests label
Review Missing Golang Tests
# -*- mode: yaml -*-
manifest:
version: 1.0
newFiles: {{ source.diff.files | filter(attr='new_file', regex=r/^(pkg|internal)\/(?!.*\_test\.go$).*\.go$/) | filter(attr='original_file', regex=r/^$/) | map(attr='new_file') }}
newTests: {{ source.diff.files | filter(attr='new_file', regex=r/.*\_test\.go$/) | filter(attr='original_file', regex=r/^$/) | map(attr='new_file') }}
newFilesCount: {{ source.diff.files | filter(attr='new_file', regex=r/^(pkg|internal)\/(?!.*\_test\.go$).*\.go$/) | filter(attr='original_file', regex=r/^$/) | length }}
newTestsCount: {{ source.diff.files | filter(attr='new_file', regex=r/.*\_test\.go$/) | filter(attr='original_file', regex=r/^$/) | length }}
automations:
review_missing_golang_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 Golang 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'
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.