Skip to content

Commit

Permalink
Ran black
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdailis committed Nov 8, 2023
1 parent 75a0f90 commit 47842a3
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 56 deletions.
1 change: 1 addition & 0 deletions cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import click


@click.group()
def cli():
pass
5 changes: 4 additions & 1 deletion commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from os.path import dirname, basename, isfile, join
import glob

modules = glob.glob(join(dirname(__file__), "*.py"))
__all__ = [ basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')]
__all__ = [
basename(f)[:-3] for f in modules if isfile(f) and not f.endswith("__init__.py")
]
31 changes: 26 additions & 5 deletions commands/backlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,39 @@
from sprint_is_active import sprint_is_active
from opt import opt


@cli.command()
@click.option("--by-assignee", is_flag=True, help="group items by assignee")
@click.option("--clipper", is_flag=True, help="show only clipper items")
@click.option("--bugs", is_flag=True, help="show only bugs")
def backlog(by_assignee, clipper, bugs):
items = db.retrieve()["project_items"]["items"]
items = [item for item in items if not ("sprint" in item and sprint_is_active(item["sprint"])) and not item["status"] == "Done"]
items = [
item
for item in items
if not ("sprint" in item and sprint_is_active(item["sprint"]))
and not item["status"] == "Done"
]
if clipper:
items = [item for item in items if "labels" in item and "clipper" in item["labels"]]
items = [
item for item in items if "labels" in item and "clipper" in item["labels"]
]
if bugs:
items = [item for item in items if "labels" in item and "bug" in item["labels"]]
if by_assignee:
grouped = sorted(group_by(items, opt("assignees", lambda x: map(login_to_name, x), tuple, sorted,
lambda x: ", ".join(x), default="Unassigned")).items())
grouped = sorted(
group_by(
items,
opt(
"assignees",
lambda x: map(login_to_name, x),
tuple,
sorted,
lambda x: ", ".join(x),
default="Unassigned",
),
).items()
)
else:
grouped = sorted(
group_by(
Expand All @@ -34,4 +53,6 @@ def backlog(by_assignee, clipper, bugs):
),
).items()
)
print_items(grouped, opt("milestone", "title", default="No milestone"), status_first=False)
print_items(
grouped, opt("milestone", "title", default="No milestone"), status_first=False
)
10 changes: 5 additions & 5 deletions commands/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
import db
from opt import opt


@cli.command()
def csv():
items = db.retrieve()["project_items"]["items"]
columns = [
lambda item: opt("milestone", "title", default="No milestone")(item),
opt("title"),
lambda x: x["repository"].split("/")[-1]
+ " #"
+ str(x["content"]["number"]),
lambda x: x["repository"].split("/")[-1] + " #" + str(x["content"]["number"]),
opt("labels", lambda x: ",".join(x), default=""),
opt("status")
opt("status"),
]
import csv

with open("pm.csv", "w") as f:
writer = csv.writer(f)
for item in items:
writer.writerow(column(item) for column in columns)
writer.writerow(column(item) for column in columns)
17 changes: 13 additions & 4 deletions commands/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

from repos import repos


@cli.command()
@click.option("--items", is_flag=True, help="also fetch items. This may take a little while")
@click.option(
"--items", is_flag=True, help="also fetch items. This may take a little while"
)
def fetch(items):
fetch_items = items
try:
Expand All @@ -21,7 +24,9 @@ def fetch(items):
new_issues = []
new_prs = []
for repo in repos:
cached_issue_update_times = [issue["updatedAt"] for issue in issues if issue["repo"] == repo]
cached_issue_update_times = [
issue["updatedAt"] for issue in issues if issue["repo"] == repo
]
if cached_issue_update_times:
last_updated = max(cached_issue_update_times)
else:
Expand All @@ -37,7 +42,11 @@ def fetch(items):
new_prs.append(pr)

updated_issues = {(issue["repo"], issue["number"]) for issue in new_issues}
issues = [issue for issue in issues if (issue["repo"], issue["number"]) not in updated_issues]
issues = [
issue
for issue in issues
if (issue["repo"], issue["number"]) not in updated_issues
]

print(f"Updated issues ({len(new_issues)}):")
print_issues(new_issues)
Expand All @@ -57,4 +66,4 @@ def fetch(items):
print("Using cached items only")
project_items = db.retrieve()["project_items"]

db.store({"issues": issues, "project_items": project_items, "prs": prs})
db.store({"issues": issues, "project_items": project_items, "prs": prs})
1 change: 1 addition & 0 deletions commands/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import db
from print_issues import print_issues


@cli.command()
@click.option("--show-closed", is_flag=True, help="include closed issues in output")
@click.option(
Expand Down
10 changes: 2 additions & 8 deletions commands/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ def items(by_milestone, by_sprint, show_done):
issues = db.retrieve()["issues"]

# Issues are easier to keep in sync - prefer the issue's milestone if available
issue_dict = {
(issue["repo"], issue["number"]): issue
for issue in issues
}
issue_dict = {(issue["repo"], issue["number"]): issue for issue in issues}

for item in items:
repo = item["repository"].split("/")[-1]
Expand All @@ -39,7 +36,7 @@ def items(by_milestone, by_sprint, show_done):
if by_milestone:
grouped = sorted(
group_by(items, opt("milestone", "title", default="No milestone")).items(),
key=lambda x: milestone_sorter(x[0])
key=lambda x: milestone_sorter(x[0]),
)
other_column = opt("sprint", "title", default="No sprint")
else:
Expand All @@ -56,6 +53,3 @@ def items(by_milestone, by_sprint, show_done):
other_column = opt("milestone", "title", default="No milestone")

print_items(grouped, other_column)



22 changes: 19 additions & 3 deletions commands/standup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
@cli.command()
def standup():
items = db.retrieve()["project_items"]["items"]
items = [item for item in items if "sprint" in item and sprint_is_active(item["sprint"])]
items_by_assignee = group_by(items, opt("assignees", lambda x: map(login_to_name, x), tuple, sorted, lambda x: ", ".join(x), default=tuple()))
print_items(sorted(items_by_assignee.items()), opt("milestone", "title", default="No milestone"), include_assignees=False)
items = [
item for item in items if "sprint" in item and sprint_is_active(item["sprint"])
]
items_by_assignee = group_by(
items,
opt(
"assignees",
lambda x: map(login_to_name, x),
tuple,
sorted,
lambda x: ", ".join(x),
default=tuple(),
),
)
print_items(
sorted(items_by_assignee.items()),
opt("milestone", "title", default="No milestone"),
include_assignees=False,
)
7 changes: 5 additions & 2 deletions commands/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
"-a", "--aerie", is_flag=True, help="specify that this issue should be from aerie"
)
@click.option(
"-d", "--docs", is_flag=True, help="specify that this issue should be from aerie-docs"
"-d",
"--docs",
is_flag=True,
help="specify that this issue should be from aerie-docs",
)
def view(issue_number, ui, aerie, docs):
issues = db.retrieve()["issues"]
Expand Down Expand Up @@ -94,4 +97,4 @@ def utc_to_pdt(utc):
res = res + " (Yesterday)"
else:
res = res + f" ({days_ago} days ago)"
return res
return res
1 change: 0 additions & 1 deletion console.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from rich.console import Console

_console = Console()

12 changes: 3 additions & 9 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
db_location = pm_directory / "pm.json"


empty_db = {
"issues": [],
"prs": [],
"project_items": {
"items": []
}
}
empty_db = {"issues": [], "prs": [], "project_items": {"items": []}}


def retrieve():
Expand All @@ -29,6 +23,6 @@ def store(contents):
def ensure_pm_directory_exists():
pm_directory.mkdir(parents=True, exist_ok=True)
if not db_location.is_file():
print("Creating empty database at" , db_location)
print("Creating empty database at", db_location)
with open(db_location, "w") as f:
json.dump(empty_db, f)
json.dump(empty_db, f)
16 changes: 13 additions & 3 deletions gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def get_issues(repo, updated_after=None):
)
)
else:
return json.loads(run(f'gh issue -R {repo} list --json {",".join(issue_columns)} --limit 100000 -s all --search "updated:>{updated_after}"'))
return json.loads(
run(
f'gh issue -R {repo} list --json {",".join(issue_columns)} --limit 100000 -s all --search "updated:>{updated_after}"'
)
)


def get_project_items(org, project_id):
Expand All @@ -96,12 +100,18 @@ def get_prs(repo, updated_after=None):
)
)
else:
return json.loads(run(f'gh pr -R {repo} list --json {",".join(pr_columns)} --limit 1500 -s all --search "updated:>{updated_after}"'))
return json.loads(
run(
f'gh pr -R {repo} list --json {",".join(pr_columns)} --limit 1500 -s all --search "updated:>{updated_after}"'
)
)


def run(command_str):
print(command_str)
return subprocess.run([cmd.strip('"') for cmd in command_str.split()], stdout=subprocess.PIPE).stdout
return subprocess.run(
[cmd.strip('"') for cmd in command_str.split()], stdout=subprocess.PIPE
).stdout


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion login_to_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def login_to_name(login):
"joswig": "Chet Joswig",
"cartermak": "Carter Mak",
"jeffpamer": "Jeff Pamer",
"sschaffe": "Steve Schaffer"
"sschaffe": "Steve Schaffer",
}
if login in logins:
return logins[login]
Expand Down
2 changes: 1 addition & 1 deletion make_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def make_table(columns, items, sort_by=None):
else:
row.append(col(issue))
table.append(row)
return table
return table
10 changes: 7 additions & 3 deletions print_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ def print_issues(issues, show_state=True):
"repo",
"number",
"title",
lambda issue: ",".join(label["name"] for label in issue["labels"]) if "labels" in issue else "",
lambda issue: ",".join(label["name"] for label in issue["labels"])
if "labels" in issue
else "",
]
if show_state:
columns.append("state")
print(
f"### {milestone}:\n"
+ tabulate(make_table(columns, issues, sort_by=opt("updatedAt", default="3000")))
)
+ tabulate(
make_table(columns, issues, sort_by=opt("updatedAt", default="3000"))
)
)
21 changes: 13 additions & 8 deletions print_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
from opt import opt
from sorters import get_label_sort, status_sort, milestone_sorter

def print_items(grouped, other_column, print=print, include_assignees=True, status_first=True):

def print_items(
grouped, other_column, print=print, include_assignees=True, status_first=True
):
for category, items in grouped:
print()
print(f"{category}:")
columns = ["status"] if status_first else [lambda item: other_column(item)[:40]]
columns.extend([
"title",
lambda x: x["repository"].split("/")[-1]
+ " #"
+ str(x["content"]["number"]),
opt("labels", lambda x: ",".join(x))
])
columns.extend(
[
"title",
lambda x: x["repository"].split("/")[-1]
+ " #"
+ str(x["content"]["number"]),
opt("labels", lambda x: ",".join(x)),
]
)
if status_first and include_assignees:
columns.append(opt("assignees", lambda x: ", ".join(map(login_to_name, x))))

Expand Down
2 changes: 1 addition & 1 deletion sorters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def get_label_sort(item):
return 0
if "icebox" in labels:
return 1
return 0
return 0
10 changes: 9 additions & 1 deletion sprint_is_active.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import datetime


def sprint_is_active(sprint):
format = "%Y-%m-%d"
return 0 < (datetime.datetime.utcnow() - datetime.datetime.strptime(sprint["startDate"], format)).days < sprint["duration"]
return (
0
< (
datetime.datetime.utcnow()
- datetime.datetime.strptime(sprint["startDate"], format)
).days
< sprint["duration"]
)

0 comments on commit 47842a3

Please sign in to comment.