Skip to content

Instantly share code, notes, and snippets.

@Arnavion
Created March 23, 2024 17:46
Show Gist options
  • Save Arnavion/26268d88aaa09d743f868358ab9e09d7 to your computer and use it in GitHub Desktop.
Save Arnavion/26268d88aaa09d743f868358ab9e09d7 to your computer and use it in GitHub Desktop.
mrhlpr wrapper that works directly on the user branch
#!/bin/bash
set -euo pipefail
shopt -s inherit_errexit
mkdir -p ~/.cache/mrhlpr
case "${1:-}" in
'fixmsg')
if [ -n "$(git status --porcelain)" ]; then
echo 'There are unstaged changes.'
exit 1
fi
mr_id="$2"
echo "{ \"gitlab.com\": { \"postmarketOS/pmaports\": { \"mrhlpr/$mr_id\": $mr_id } } }" >~/.cache/mrhlpr/mrdb.json
current_branch="$(git rev-parse --abbrev-ref HEAD)"
git checkout -b "mrhlpr/$mr_id"
set +e
~/src/mrhlpr/mrhlpr.py fixmsg
exit_code="$?"
set -e
git checkout "$current_branch"
if (( exit_code == 0 )); then
git reset --hard "mrhlpr/$mr_id"
fi
git branch -D "mrhlpr/$mr_id"
exit "$exit_code"
;;
'status')
if [ -n "$(git status --porcelain)" ]; then
echo 'There are unstaged changes.'
exit 1
fi
mr_id="$2"
echo "{ \"gitlab.com\": { \"postmarketOS/pmaports\": { \"mrhlpr/$mr_id\": $mr_id } } }" >~/.cache/mrhlpr/mrdb.json
current_branch="$(git rev-parse --abbrev-ref HEAD)"
git checkout -b "mrhlpr/$mr_id"
set +e
~/src/mrhlpr/mrhlpr.py "$@"
exit_code="$?"
set -e
git checkout "$current_branch"
git branch -D "mrhlpr/$mr_id"
exit "$exit_code"
;;
*)
exec ~/src/mrhlpr/mrhlpr.py "$@"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment