Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • postmarketOS/mrhlpr
  • longnoserob/mrhlpr
  • earboxer/mrhlpr
  • magdesign/mrhlpr
  • fossdd/mrhlpr
  • anjandev/mrhlpr
6 results
Show changes
Commits on Source (3)
  • Anjan Momi's avatar
    8647dd3b
  • Pablo Correa Gomez's avatar
    ci: allow mypyc job to fail · 351b1731
    Pablo Correa Gomez authored
    mypyc is not yet completely stable, and might fail for things that are
    correct Python (see
    !61 (comment 456440)),
    so don't make it a requirement that it passes for merging
    Unverified
    351b1731
  • Newbyte's avatar
    mrhlpr.frontend: Fix string representation of ActionType · d49a1ccf
    Newbyte authored
    Previously, the string representation for ActionType would be something
    like ActionType.OK instead of [OK ] as intended. This resulted in
    commands like `$ mrhlpr status` getting an output like this:
    
        ActionType.OK Changes allowed
        ActionType.OK Clean worktree
        ActionType.NOK Rebase on master
        ActionType.NOK MR-ID in commit msgs
        ActionType.NOK Commit subjects follow format
           668526 doesn't match any regex
        ActionType.NOK Commits are signed
    
    instead of the intended
    
        [OK ] Changes allowed
        [OK ] Clean worktree
        [NOK] Rebase on master
        [NOK] MR-ID in commit msgs
        [NOK] Commit subjects follow format
           668526 doesn't match any regex
        [NOK] Commits are signed
    
    Fixes 8647dd3b
    Verified
    d49a1ccf
......@@ -18,6 +18,7 @@ native-build:
- adduser -D build
script:
- .ci/native-build.sh
allow_failure: true
docs:
stage: test
......
......@@ -3,6 +3,7 @@
"""Pretty outputs and such."""
import argparse
from enum import Enum, unique
import logging
import sys
from typing import Any
......@@ -19,6 +20,44 @@ from . import mr
from . import version
@unique
class ColorCode(str, Enum):
OKGREEN = "\033[1;32m"
ORANGE = "\033[93m"
RED = "\033[91m"
ENDC = "\033[0m"
@unique
class ActionType(str, Enum):
OK = "[OK ]"
NOK = "[NOK]"
UNKNOWN = "[???]"
@property
def color(self) -> ColorCode:
match self:
case self.NOK:
return ColorCode.RED
case self.OK:
return ColorCode.OKGREEN
case self.UNKNOWN:
return ColorCode.ORANGE
case _:
raise ValueError(f"No defined color for action {self}")
def __str__(self) -> str:
return self.value
def print_action(msg_type: ActionType, message: str) -> None:
print(f"{msg_type.color.value}{msg_type} {message}{ColorCode.ENDC.value}")
def print_error(message: str) -> None:
print(f"{ColorCode.RED.value}{message}{ColorCode.ENDC.value}")
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
......@@ -66,103 +105,107 @@ def print_status(mr_id: int, no_cache: bool = False) -> None:
print()
if status.state == "closed":
print("ERROR: MR has been closed.")
print_error("ERROR: MR has been closed.")
exit(1)
elif status.state == "merged":
print("ERROR: MR has been merged.")
print_error("ERROR: MR has been merged.")
exit(1)
# Changes allowed by maintainers
if status.allow_push:
print("[OK ] Changes allowed")
action = ActionType.OK
else:
print("[NOK] Changes allowed")
action = ActionType.NOK
print_action(action, "Changes allowed")
# Clean worktree
if clean_worktree is None:
print("[???] Clean worktree")
action = ActionType.UNKNOWN
elif clean_worktree:
print("[OK ] Clean worktree")
action = ActionType.OK
else:
print("[NOK] Clean worktree")
action = ActionType.NOK
print_action(action, "Clean worktree")
# Rebase on target branch
if is_rebased is None:
print(f"[???] Rebase on {target_branch}")
action = ActionType.UNKNOWN
elif is_rebased:
print(f"[OK ] Rebase on {target_branch}")
action = ActionType.OK
else:
print(f"[NOK] Rebase on {target_branch}")
action = ActionType.NOK
print_action(action, f"Rebase on {target_branch}")
# MR-ID in all commit messages
if commits_have_id is None:
print("[???] MR-ID in commit msgs")
action = ActionType.UNKNOWN
elif commits_have_id:
print("[OK ] MR-ID in commit msgs")
action = ActionType.OK
else:
print("[NOK] MR-ID in commit msgs")
action = ActionType.NOK
print_action(action, "MR-ID in commit msgs")
# All commits follow formatting
if commits_follow_format is None:
print("[???] Commit subjects follow format")
for line in subj_err:
print(" " + line)
action = ActionType.UNKNOWN
elif commits_follow_format:
print("[OK ] Commit subjects follow format")
action = ActionType.OK
else:
print("[NOK] Commit subjects follow format")
for line in subj_err:
print(" " + line)
action = ActionType.NOK
print_action(action, "Commit subjects follow format")
for line in subj_err:
print(" " + line)
# Commits are signed
if commits_are_signed is None:
print("[???] Commits are signed")
action = ActionType.UNKNOWN
elif commits_are_signed:
print("[OK ] Commits are signed")
action = ActionType.OK
else:
print("[NOK] Commits are signed")
action = ActionType.NOK
print_action(action, "Commits are signed")
# Checklist
print()
print("Checklist:")
if not status.allow_push:
print(
print_error(
"* Ask MR author to tick 'Allow commits from members who can"
" merge to the target branch.'"
)
print("* Check again ('mrhlpr -n status')")
print_error("* Check again ('mrhlpr -n status')")
return
if not is_checked_out:
print("* Checkout this MR ('mrhlpr checkout " + str(mr_id) + "')")
print_error("* Checkout this MR ('mrhlpr checkout " + str(mr_id) + "')")
return
if not clean_worktree:
print("* Commit or stash changes in your worktree")
print("* Check again ('mrhlpr status')")
print_error("* Commit or stash changes in your worktree")
print_error("* Check again ('mrhlpr status')")
return
if len(commits) > 1:
print(
print_error(
f"* {len(commits)} commits: consider squashing"
f" ('git rebase -i origin/{target_branch}')"
)
if not is_rebased:
print(f"* Rebase on {target_branch} ('git" f" rebase origin/{target_branch}')")
print("* Check again ('mrhlpr status')")
print_error(f"* Rebase on {target_branch} ('git" f" rebase origin/{target_branch}')")
print_error("* Check again ('mrhlpr status')")
return
if not commits_have_id or not commits_are_signed:
print("* Add the MR-ID to all commits and sign them ('mrhlpr fixmsg')")
print_error("* Add the MR-ID to all commits and sign them ('mrhlpr fixmsg')")
return
if commits_follow_format is False:
print("* Fix commit subjects that don't follow the correct formatting")
print_error("* Fix commit subjects that don't follow the correct formatting")
return
if commits_follow_format is None:
print("* Manually check if the commit subjects are correct")
print_error("* Manually check if the commit subjects are correct")
print("* Pretty 'git log -" + str(len(commits)) + " --pretty'?" + " (consider copying MR desc)")
print("* Finish the MR: push, approve, merge, comment ('mrhlpr finish')")
......