Skip to content

Commit

Permalink
fix(run): errors opening logs from notification
Browse files Browse the repository at this point in the history
Resolve a couple problems with the actions in the dunst notifications
created by the experimental `notify-run-completed` util.

- Remove double quotes around the run-id, which caused an error due to
  fzf already wrapping it in single quotes
  surrounded it with single quotes
- Use the widely supported xterm style "-e" flag to open a new terminal
  window with the logs
- Fallback to writing the logs to /tmp and using xdg-open
  • Loading branch information
benelan committed May 30, 2024
1 parent a5c3c50 commit 922fb4b
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions gh-fzf
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ Filters > (alt-p: public) (alt-s: secret)
}

# --------------------------------------------------------------------- }}}
# Command > util {{{
# Command > util {{{
# --------------------------------------------------------------------- {|}

# arg1: issue number
Expand Down Expand Up @@ -656,24 +656,34 @@ notify_run_completed() {

if has dunstify; then
[ -n "$urgency" ] &&
conditional_action="rerun,Rerun failed jobs" ||
conditional_action="download,Download artifacts"
conditional_action="rerun,rerun failed jobs" ||
conditional_action="download,download artifacts"

action_response=$(
dunstify "$title" "$body" ${urgency:+-u "$urgency"} \
${GH_FZF_NOTIFY_ICON:+-i "$GH_FZF_NOTIFY_ICON"} -a "gh-fzf" \
-A "web,Open in browser" -A "$conditional_action" -A "log,View logs"
-A "web,wpen in browser" -A "log,view logs" -A "$conditional_action"
)

case $action_response in
log) $TERMINAL -- sh -c "cd \"$PWD\" && gh run view --log \"$run_id\"" ;;
web) gh run view --web "$run_id" & ;;
download) gh run download "$run_id" ;;
web) gh run view --web $run_id & ;;
download) gh run download $run_id ;;
rerun)
gh run rerun --failed "$run_id"
gh fzf util notify-run-completed "$run_id"
gh run rerun --failed $run_id
gh fzf util notify-run-completed $run_id
;;
log)
case $TERMINAL in
x-terminal-emulator | xterm | wezterm | kitty | gnome-terminal | alacritty | konsole | foot | eterm | st)
$TERMINAL -e sh -c "gh run view --log $run_id $repo_flag" &
;;
*)
tmp="$(mktemp)"
gh run view $run_id --log $repo_flag >$tmp
xdg-open "$tmp" &
;;
esac
;;
*) exit ;;
esac
elif has notify-send; then
notify-send "$title" "$body${url:+: \n$url}" ${urgency:+-u "$urgency"} \
Expand Down

0 comments on commit 922fb4b

Please sign in to comment.