Skip to content
Snippets Groups Projects
Verified Commit b067a9ff authored by Newbyte's avatar Newbyte :snowflake:
Browse files

mrhlpr.mr: Move no MR checked out error handling to mr.checked_out()

None of the code paths actually make use of the case where it returns
None for anything other than displaying the same error message, if they
display one at all. Some just attempted to use None as if it was an
integer. As such, just display the error in mr.checked_out() to simplify
and deduplicate code.
parent 6a45e034
No related branches found
No related tags found
1 merge request!53CI: Build native libraries for mrhlpr and mrtest via mypyc
Pipeline #208298 passed
......@@ -5,7 +5,7 @@
import argparse
import logging
import sys
from typing import Any, Optional
from typing import Any
try:
import argcomplete
......@@ -18,7 +18,7 @@ from . import gitlab
from . import mr
def print_status(mr_id: Optional[int], no_cache: bool = False) -> None:
def print_status(mr_id: int, no_cache: bool = False) -> None:
"""Print the merge request status. Most info is only visible, when the
branch is checked out locally. Always display a checklist of things to
do next, in order to get the MR shipped.
......@@ -26,13 +26,6 @@ def print_status(mr_id: Optional[int], no_cache: bool = False) -> None:
:param mr_id: merge request ID
:param no_cache: do not cache the API result for the merge request data
"""
if not mr_id:
print(
"ERROR: can't associate the current branch with a merge request"
" ID. Run 'mrhlpr checkout N' first (N is the MR-ID)."
)
exit(1)
status = mr.get_status(mr_id, no_cache)
is_checked_out = mr.checked_out() == mr_id
is_rebased = None
......
......@@ -25,11 +25,16 @@ from . import mrdb
from . import pipeline
def checked_out() -> Optional[int]:
def checked_out() -> int:
""":returns: checked out MR ID or None"""
origin = gitlab.parse_git_origin()
branch = git.branch_current()
return mrdb.get(origin.host, origin.project_id, branch)
mr_id = mrdb.get(origin.host, origin.project_id, branch)
if not mr_id:
print("ERROR: no merge request is currently checked out.")
print("Run 'mrhlpr checkout N' first (N is the MR-ID).")
exit(1)
return mr_id
@dataclass
......@@ -478,10 +483,6 @@ def fixmsg(
"""Add the MR-ID in each commit of the MR.
:param mr_id: merge request ID"""
if not mr_id:
print("ERROR: no merge request is currently checked out.")
print("Run 'mrhlpr checkout N' first.")
exit(1)
target_branch = get_status(mr_id).target_branch
ret = git.run(["rev-parse", "--show-toplevel"])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment