Last active
October 11, 2022 23:00
-
-
Save MattSegal/46cf6ca0d326ce96c88dc2894b9a7909 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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