Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mrhlpr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anjan Momi
mrhlpr
Commits
c4fd5172
Commit
c4fd5172
authored
4 months ago
by
Anjan Momi
Browse files
Options
Downloads
Patches
Plain Diff
add color to NOK, OK, ???, and error prints
parent
dbb8411e
No related branches found
No related tags found
No related merge requests found
Pipeline
#210430
failed
4 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mrhlpr/frontend.py
+72
-34
72 additions, 34 deletions
mrhlpr/frontend.py
with
72 additions
and
34 deletions
mrhlpr/frontend.py
+
72
−
34
View file @
c4fd5172
...
...
@@ -3,6 +3,7 @@
"""
Pretty outputs and such.
"""
import
argparse
from
enum
import
StrEnum
,
unique
import
logging
import
sys
from
typing
import
Any
...
...
@@ -19,6 +20,39 @@ from . import mr
from
.
import
version
@unique
class
ColorCode
(
StrEnum
):
OKGREEN
=
'
\033
[1;32m
'
ORANGE
=
'
\033
[93m
'
RED
=
'
\033
[91m
'
ENDC
=
'
\033
[0m
'
@unique
class
ActionType
(
StrEnum
):
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
print_action
(
msg_type
:
ActionType
,
message
:
str
)
->
None
:
print
(
f
"
{
msg_type
.
color
}{
msg_type
}
{
message
}{
ColorCode
.
ENDC
}
"
)
def
print_error
(
message
:
str
)
->
None
:
print
(
f
"
{
ColorCode
.
RED
}{
message
}{
ColorCode
.
ENDC
}
"
)
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 +100,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
'
)
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment