Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/automator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The following is a list of supported options for `automator.sh`. If an option is
| `--verbose` | | Enable verbose output. Print commands and their arguments as they are executed. **WARNING**: this has the potential to print sensitive data to standard output. | |
| `--strict` | | Enable strict mode. When enabled, if the command does not produce a [git diff] it will exit with a non-zero exit code. | |
| `--dry-run` | | Enable dry run mode. When enabled, the command will terminate early and **NOT** perform a commit, push, or pull request for any changes. This is useful for local testing/debugging or when concerned only with the [git diff] or exit code of the command. | |
| `--git-exclude` | string | Added to `git diff` to exclude a file/path when detrining changes | `common` |

### Environment Variables

Expand Down
16 changes: 12 additions & 4 deletions tools/automator/automator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cleanup() {
}

get_opts() {
if opt="$(getopt -o '' -l branch:,org:,repo:,title:,match-title:,body:,labels:,user:,email:,modifier:,script-path:,cmd:,token-path:,token:,merge-repository:,merge-branch:,strict,dry-run,verbose -n "$(basename "$0")" -- "$@")"; then
if opt="$(getopt -o '' -l branch:,org:,repo:,title:,match-title:,body:,labels:,user:,email:,modifier:,script-path:,cmd:,token-path:,token:,merge-repository:,merge-branch:,git-exclude:,strict,dry-run,verbose -n "$(basename "$0")" -- "$@")"; then
eval set -- "$opt"
else
print_error_and_exit "unable to parse options"
Expand Down Expand Up @@ -117,6 +117,10 @@ get_opts() {
dry_run=true
shift
;;
--git-exclude)
git_exclude=(":^$2")
shift 2
;;
--)
shift
script_args=("$@")
Expand Down Expand Up @@ -190,6 +194,10 @@ validate_opts() {
if [ -z "${email:-}" ] && ! $dry_run; then
email="$(curl -sSfLH "Authorization: token $token" "https://api.github.com/user" | jq --raw-output ".email")"
fi

if [ -z "${git_exclude:-}" ]; then
git_exclude=()
fi
}

evaluate_opts() {
Expand Down Expand Up @@ -229,7 +237,7 @@ add_labels() {

commit() {
if $dry_run; then
git diff --cached
git diff --cached "${git_exclude[@]}"
return 0
fi

Expand Down Expand Up @@ -259,7 +267,7 @@ merge() {
else
print_error "No changes to merge" 0
fi
fi
fi
}

work() { (
Expand Down Expand Up @@ -287,7 +295,7 @@ work() { (

git add --all

if ! git diff --cached --quiet --exit-code; then
if ! git diff --cached --quiet --exit-code "${git_exclude[@]}"; then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this including the file, not excluding it? I may be understanding wrong though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exclude happens because I prefixed the string with :^ above. Maybe I didn't explain that enough in the code.

commit
elif $strict; then
print_error "no diff for $repo" 1
Expand Down