zaquestion / lab

Lab wraps Git or Hub, making it simple to clone, fork, and interact with repositories on GitLab
https://zaquestion.github.io/lab
Creative Commons Zero v1.0 Universal
1.11k stars 102 forks source link

provide an easy way to check if MR already exists for the current branch #847

Closed sding3 closed 1 year ago

sding3 commented 1 year ago

There doesn't appear to be an easy to check if there already an MR associated with the current branch.

This is currently how I'm doing it, which is a bit cumbersome.

function labmrexists() {(
    set +e

    output="$(lab mr show --no-pager 2>&1)"
    if [[ $? -eq 0 ]]; then
        echo yes # exists
        return 0
    fi
    if [[ $output == *"cannot determine MR id"* ]]; then
        echo no # does not exist
        return 0
    fi
    echo $output # not sure
    return 1
)}

It would be helpful if lab mr show can use different exit codes when there is no MR v.s. when it failed to perform the check due to some errors.

Additionally, it would be great if there is a command for me to get at the MR URL, e.g. lab mr show --format '{{.mr.url}}' or something like that.