Skip to content

Commit

Permalink
Added watched and draft commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Sep 20, 2020
1 parent 3d4cec5 commit a1576d7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
47 changes: 40 additions & 7 deletions gri/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, ctx, server=None, user=None):
self.reviews = list()
term.print(self.header())

def query(self, query):
def run_query(self, query):
"""Performs a query and stores result inside reviews attribute"""
self.reviews = list()
for item in self.servers:
Expand All @@ -87,11 +87,11 @@ def header(self):
def report(self, query=None, title="Reviews", max_score=1, action=None):
"""Produce a table report based on a query."""
if query:
self.query(query)
self.run_query(query)

cnt = 0

table = Table(title=title, border_style="grey15", box=box.MINIMAL)
table = Table(title=title, border_style="grey15", box=box.MINIMAL, expand=True)
table.add_column("Review", justify="right")
table.add_column("Age")
table.add_column("Project/Subject")
Expand All @@ -115,6 +115,7 @@ def report(self, query=None, title="Reviews", max_score=1, action=None):

# Printing empty tables makes no sense
if cnt:
term.print()
term.print(table)

extra = f" from: [cyan]{query}[/]" if query else ""
Expand Down Expand Up @@ -191,6 +192,14 @@ def cli(ctx, debug, server, force, user, output):
term.save_html(path=output, theme=TERMINAL_THEME)


@cli.resultcallback()
def process_result(result, **kwargs): # pylint: disable=unused-argument
output = kwargs["output"]
if kwargs["output"]:
term.save_html(path=output, theme=TERMINAL_THEME)
LOG.info("Report saved to %s", output)


@cli.command()
@click.pass_context
def owned(ctx):
Expand All @@ -207,9 +216,9 @@ def owned(ctx):
@cli.command()
@click.pass_context
def incoming(ctx):
"""Incoming reviews (not mine)"""
"""Incoming reviews"""
query = f"reviewer:{ctx.obj.user} status:open"
ctx.obj.report(query=query, title="Merged Reviews")
ctx.obj.report(query=query, title=incoming.__doc__)


@cli.command()
Expand All @@ -220,13 +229,37 @@ def incoming(ctx):
help="Number of days to look back, adds -age:NUM",
)
def merged(ctx, age):
"""merged in the last number of days"""
"""Merged in the last number of days"""
query = f" status:merged -age:{age}d"
query += f" owner:{ctx.obj.user}"

ctx.obj.report(query=query, title=f"Merged Reviews ({age}d)")


# @cli.command()
# @click.pass_context
# def custom(ctx):
# """Custom query"""
# query = f"cc:{ctx.obj.user} status:open"
# ctx.obj.report(query=query, title="Custom query")


@cli.command()
@click.pass_context
def watched(ctx):
"""Watched reviews based on server side filters"""
query = f"watchedby:{ctx.obj.user} status:open"
ctx.obj.report(query=query, title=watched.__doc__)


@cli.command()
@click.pass_context
def draft(ctx):
"""Draft reviews or with draft comments."""
query = "status:open owner:self has:draft OR draftby:self"
ctx.obj.report(query=query, title=draft.__doc__)


@cli.command()
@click.pass_context
@click.option(
Expand All @@ -244,7 +277,7 @@ def abandon(ctx, age):
ctx.obj.report(
query=query,
title=f"Reviews to abandon ({age}d)",
max_score=0.4,
max_score=0.1,
action="abandon",
)

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ deps =
pip == 19.1.1
whitelist_externals = bash
commands =
python -m gri
gri -o report.html owned incoming merged abandon draft watched

[testenv:lint]
basepython = python3.7
Expand Down

0 comments on commit a1576d7

Please sign in to comment.