From a00a52cfb79829b80386e8d43249cd94df63c57e Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Fri, 25 Oct 2024 15:13:31 +0200 Subject: chore: rename shell scripts to *.sh --- po.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 po.sh (limited to 'po.sh') diff --git a/po.sh b/po.sh new file mode 100755 index 0000000..75faecb --- /dev/null +++ b/po.sh @@ -0,0 +1,57 @@ +#!/bin/sh +set -eu + +if [ ! -d .osc ] && [ ! -d .git ] ; then + echo 'This program must be run from an project directory.' + exit 42 +fi + +which_pr() { + TOKEN=$(pass show dev/github.com|awk '/^token:/ {print $2}') + ORIG_USER=$(git remote get-url origin 2>/dev/null|awk -F/ '{print $4}') + REPO=$(git remote get-url origin 2>/dev/null|awk -F'[/.]' '{print $6}') + USER=$(git remote get-url github 2>/dev/null|awk -F/ '{print $4}') + BRANCH=$(git rev-parse --abbrev-ref HEAD) + + curl -s -L \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/$ORIG_USER/$REPO/pulls?head=mcepl:$BRANCH" \ + | jq -r .[].html_url 2>/dev/null +} + +o_url="" +if [ -f .osc/_packages ] ; then + apiurl=$(cat .osc/_apiurl) + project=$(cat .osc/_project) + o_url="${apiurl}/project/show/${project}" +elif [ -f .osc/_package ] ; then + apiurl=$(cat .osc/_apiurl) + project=$(cat .osc/_project) + package=$(cat .osc/_package) + o_url="${apiurl}/package/show/${project}/${package}" +fi + +if [ -z "$o_url" ] ; then + pr_url="$(which_pr)" || true + if [ -n "$pr_url" ] ; then + o_url="$pr_url" + elif [ -d .git ] ; then + if git remote show gitlab >/dev/null 2>&1 ; then + o_url="$(git remote get-url gitlab)" + elif git remote show github >/dev/null 2>&1 ; then + o_url="$(git remote get-url github)" + elif git remote show sourcehut >/dev/null 2>&1 ; then + o_url="$(git remote get-url sourcehut)" + elif git remote show myrepo >/dev/null 2>&1 ; then + o_url="$(git remote get-url myrepo)" + elif git remote show origin >/dev/null 2>&1 ; then + o_url="$(git remote get-url origin)" + else + exit 0 + fi + fi +fi + +[ -z "$o_url" ] || xdg-open "$o_url" >/dev/null 2>&1 -- cgit