Dotfiles/site-modules/core/files/bin/sl-push-bookmakrs
Ade Attwood a39b844c63 feat(sapling): display the pr link if we have already created one
When pushing your stack we show all the branches we have pushed to with
a compare link to github. When we create a PR the compare link is no
longer relevant. Now we will show a link to the PR that is associated
with that branch.
2024-06-08 18:00:16 +01:00

32 lines
967 B
Bash
Executable file

#!/bin/bash
default_path="$(sl config paths.default)"
url="${default_path%*.git}"
project="$(basename $(dirname "$url"))/$(basename "$url")"
# "top % public()" => non-public commits in my stack
# "top" => from the top of my stack
# "% X" => except not in X
# "public()" => public commits
#
previous_bookmark_query=""
previous_bookmark=""
for i in $(sl log -r "top % public()" -T "{bookmarks} "); do
commits="$(sl log -T" - {firstline(desc)} ({node|short})\n" -r "::$i % public()$previous_bookmark_query")"
pr_url="$(gh pr view -R "$project" --json "url" --jq '.url' "$i" 2>&1)"
if [[ "$pr_url" != "no pull requests found for branch"* ]]; then
echo "$pr_url"
elif [[ -z "$previous_bookmark" ]]; then
echo "$url/compare/$i"
else
echo "$url/compare/$previous_bookmark...$i"
fi
echo "$commits"
sl push -f -r "$i" --to "remote/$i" 2>&1 | grep -E "[\+\*]"
echo ""
previous_bookmark_query=" % ::$i"
previous_bookmark="$i"
done