gitea_get_notifications.sh: split outputs into pices
This commit is contained in:
parent
19a803edf6
commit
2301757eb9
|
@ -1,64 +1,76 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
myuser="${1}"
|
myuser="${1}"
|
||||||
|
gettype="${2:-merged}"
|
||||||
|
|
||||||
markmineread=false
|
markmineread=false
|
||||||
open_count=0
|
open_count=0
|
||||||
merge_count=0
|
merge_count=0
|
||||||
open_notis_count=0
|
open_notis_count=0
|
||||||
|
fcount=0
|
||||||
|
|
||||||
open_noti=$(tea notification ls --mine | grep -E "^\| +[0-9]+.* Pull .* open " | sed -E 's/[ \|]/@@/g;s/@@+/@@/g;s/^@@//g;s/@@$//g')
|
if [ "${gettype}" == "merged" ]; then
|
||||||
|
open_noti=$(tea notification ls --mine | grep -E "^\| +[0-9]+.* Pull .* open " | sed -E 's/[ \|]/@@/g;s/@@+/@@/g;s/^@@//g;s/@@$//g')
|
||||||
|
|
||||||
for merged_noti in $(tea notification ls --mine | grep -E "^\| +[0-9]+.* Pull .* merged " | sed -E 's/[ \|]/@@/g;s/@@+/@@/g;s/^@@//g;s/@@$//g'); do
|
for merged_noti in $(tea notification ls --mine | grep -E "^\| +[0-9]+.* Pull .* merged " | sed -E 's/[ \|]/@@/g;s/@@+/@@/g;s/^@@//g;s/@@$//g'); do
|
||||||
mark_read=false
|
mark_read=false
|
||||||
noti_id="$(grep -oE "^[0-9]+" <<<"${merged_noti}")"
|
noti_id="$(grep -oE "^[0-9]+" <<<"${merged_noti}")"
|
||||||
noti_pr_id="$(grep -oE '@@#[0-9]+@@' <<<"${merged_noti}" | sed -e 's/[@#]//g')"
|
noti_pr_id="$(grep -oE '@@#[0-9]+@@' <<<"${merged_noti}" | sed -e 's/[@#]//g')"
|
||||||
noti_repo="$(grep -oE '@[a-z0-9]+/[a-z0-9]+$' <<<"${merged_noti}" | sed -e 's/@//g')"
|
noti_repo="$(grep -oE '@[a-z0-9]+/[a-z0-9]+$' <<<"${merged_noti}" | sed -e 's/@//g')"
|
||||||
|
|
||||||
pr_info=$(tea pr ls --state all --repo "${noti_repo}" | grep -E "^\| +${noti_pr_id} .* closed ")
|
pr_info=$(tea pr ls --state all --repo "${noti_repo}" | grep -E "^\| +${noti_pr_id} .* closed ")
|
||||||
if grep -qE " closed +\| +${myuser} +\|" <<<"${pr_info}"; then
|
if grep -qE " closed +\| +${myuser} +\|" <<<"${pr_info}"; then
|
||||||
if $markmineread ; then
|
if $markmineread ; then
|
||||||
|
mark_read=true
|
||||||
|
else
|
||||||
|
let merge_count+=1
|
||||||
|
fi
|
||||||
|
elif grep -qE " closed +\| +[a-zA-Z]+ [a-zA-Z]+ +\|" <<<"${pr_info}"; then
|
||||||
mark_read=true
|
mark_read=true
|
||||||
else
|
|
||||||
let merge_count+=1
|
|
||||||
fi
|
fi
|
||||||
elif grep -qE " closed +\| +[a-zA-Z]+ [a-zA-Z]+ +\|" <<<"${pr_info}"; then
|
|
||||||
mark_read=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $mark_read ; then
|
if $mark_read ; then
|
||||||
tea notification read ${noti_id} &>/dev/null
|
tea notification read ${noti_id} &>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if open_merge_noti=$(grep -q " #${noti_pr_id} " <<<"${open_noti}"); then
|
if open_merge_noti=$(grep -q " #${noti_pr_id} " <<<"${open_noti}"); then
|
||||||
tea notification read $(sed -E 's/^\| +([0-9]+) .*/\1/g' <<<"${open_merge_noti}") &>/dev/null
|
tea notification read $(sed -E 's/^\| +([0-9]+) .*/\1/g' <<<"${open_merge_noti}") &>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
open_notis=$(tea notification ls --mine | grep -E "^\| +[0-9]+.* Pull .* open " | sed -E 's/[ \|]/@@/g;s/@@+/@@/g;s/^@@//g;s/@@$//g')
|
|
||||||
if [ -n "${open_notis}" ]; then
|
|
||||||
open_notis_count=$(wc -l <<<"${open_notis}")
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for open_noti in ${open_notis}; do
|
if [ "${gettype}" == "open_all" ]; then
|
||||||
noti_id="$(grep -oE "^[0-9]+" <<<"${open_noti}")"
|
open_notis=$(tea notification ls --mine | grep -E "^\| +[0-9]+.* Pull .* open " | sed -E 's/[ \|]/@@/g;s/@@+/@@/g;s/^@@//g;s/@@$//g')
|
||||||
noti_pr_id="$(grep -oE '@@#[0-9]+@@' <<<"${open_noti}" | sed -e 's/[@#]//g')"
|
if [ -n "${open_notis}" ]; then
|
||||||
noti_repo="$(grep -oE '@[a-z0-9_-]+.[a-z0-9_-]+$' <<<"${open_noti}" | sed -e 's/@//g')"
|
open_notis_count=$(wc -l <<<"${open_notis}")
|
||||||
|
|
||||||
pr_info=$(tea pr ls --state all --repo "${noti_repo}" | grep -E "^\| +${noti_pr_id} .* open ")
|
|
||||||
if grep -qE " open +\| +${myuser} +\|" <<<"${pr_info}"; then
|
|
||||||
let open_count+=1
|
|
||||||
fi
|
fi
|
||||||
done
|
fi
|
||||||
|
|
||||||
|
if [ "${gettype}" == "open" ]; then
|
||||||
|
open_notis=$(tea notification ls --mine | grep -E "^\| +[0-9]+.* Pull .* open " | sed -E 's/[ \|]/@@/g;s/@@+/@@/g;s/^@@//g;s/@@$//g')
|
||||||
|
for open_noti in ${open_notis}; do
|
||||||
|
noti_id="$(grep -oE "^[0-9]+" <<<"${open_noti}")"
|
||||||
|
noti_pr_id="$(grep -oE '@@#[0-9]+@@' <<<"${open_noti}" | sed -e 's/[@#]//g')"
|
||||||
|
noti_repo="$(grep -oE '@[a-z0-9_-]+.[a-z0-9_-]+$' <<<"${open_noti}" | sed -e 's/@//g')"
|
||||||
|
|
||||||
|
pr_info=$(tea pr ls --state all --repo "${noti_repo}" | grep -E "^\| +${noti_pr_id} .* open ")
|
||||||
|
if grep -qE " open +\| +${myuser} +\|" <<<"${pr_info}"; then
|
||||||
|
let open_count+=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
i3status_state="Idle"
|
i3status_state="Idle"
|
||||||
|
|
||||||
if [ $merge_count -gt 0 ]; then
|
if [ $merge_count -gt 0 ]; then
|
||||||
i3status_state="Critical"
|
i3status_state="Critical"
|
||||||
|
fcount=${merge_count}
|
||||||
elif [ $open_count -gt 0 ]; then
|
elif [ $open_count -gt 0 ]; then
|
||||||
open_notis_count=$((open_notis_count - open_count))
|
|
||||||
i3status_state="Warning"
|
i3status_state="Warning"
|
||||||
|
fcount=${open_count}
|
||||||
elif [ $open_notis_count -gt 0 ]; then
|
elif [ $open_notis_count -gt 0 ]; then
|
||||||
i3status_state="Info"
|
i3status_state="Info"
|
||||||
|
fcount=${open_notis_count}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "{\"state\":\"${i3status_state}\", \"text\":\"GT: ${open_notis_count}/${open_count}/${merge_count}\"}"
|
echo "{\"state\":\"${i3status_state}\", \"text\":\"${fcount}\"}"
|
||||||
|
|
Loading…
Reference in New Issue