Skip to content

Instantly share code, notes, and snippets.

@stuartleeks
Last active February 8, 2022 14:42
Show Gist options
  • Save stuartleeks/1d579f042fac3a4cdb6663ca10dc97de to your computer and use it in GitHub Desktop.
Save stuartleeks/1d579f042fac3a4cdb6663ca10dc97de to your computer and use it in GitHub Desktop.
ghrun.sh

Accompanying scripts for https//stuartleeks/posts/wsl-github-cli-windows-notifications-part-2/

Abbreviated setup notes

Enjoy!

#!/bin/bash
set -e
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Get the latest run for the current branch
# (update to use JSON output once implemented - see https://github.com/cli/cli/issues/3477)
run_id=$(gh run list | grep $(git rev-parse --abbrev-ref HEAD) | cut -d$'\t' -f 8 | head -n 1)
# Watch the run progress
gh run watch $run_id
# Create a temp file to capture the url in via a fake browser
# (update to use JSON output once implemented - see https://github.com/cli/cli/issues/3477)
temp_filename=$(mktemp)
# clean up the temp file on exit
function finish {
rm "$temp_filename"
}
trap finish EXIT
# Use fake browser to capture run url
exit_code=$(BROWSER="$dir/save-args.sh \"$temp_filename\"" gh run view $run_id --web --exit-status > /dev/null; echo $?)
run_url=$(cat "$temp_filename" | head -n 1)
if [[ $exit_code == "0" ]]; then
title="Run completed successfully"
else
title="Run completed with exit code $exit_code"
fi
toast.exe \
--app-id "GitHub" \
--title "$title" \
--message "$PWD" \
--action "Open browser" --action-arg "$run_url"
#!/bin/bash
#
# Usage:
# save-args.sh <filename> arg1 arg2 ...
#
# save-args will write arg1, arg2, ... to <filename> (one arg per line)
#
filename=$1
if [[ -z "$1" ]]; then
echo "Need a minimum of one argument specifying the output filename"
exit 1
fi
if [[ -f "$filename" ]]; then
rm "$filename"
fi
touch "$filename"
for i in "${@:2}"; do
echo "$i" >> "$filename"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment