Skip to content

Instantly share code, notes, and snippets.

@MattSegal
Last active October 11, 2022 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattSegal/46cf6ca0d326ce96c88dc2894b9a7909 to your computer and use it in GitHub Desktop.
Save MattSegal/46cf6ca0d326ce96c88dc2894b9a7909 to your computer and use it in GitHub Desktop.
function gitlab {
# Find the branch we're on.
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
# Find whether there is an MR open for this branch.
# Requires the Gitlab CLI: https://gitlab.com/gitlab-org/cli
MR_ID=$(glab mr list --author=@me | grep "← ($BRANCH_NAME" | cut -f1)
MR_ID=${MR_ID:1}
# Find the git remote URL.
REMOTE=$(git remote -v | head -1 | cut -f2 | cut -f1 -d' ')
REMOTE=${REMOTE:4:-4}
REMOTE=${REMOTE/:/\/}
if [[ -z "$MR_ID" ]]; then
# There is no MR, open the branch page.
URL="https://${REMOTE}/-/tree/${BRANCH_NAME}"
else
# If there is an MR, open the MR page.
URL="https://${REMOTE}/-/merge_requests/${MR_ID}"
fi
# Open the URL in Google Chrome
google-chrome $URL
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment