From 47842a384e77413757f9e40cc1536d826634b52d Mon Sep 17 00:00:00 2001 From: Matthew Dailis Date: Tue, 7 Nov 2023 21:23:45 -0800 Subject: [PATCH] Ran black --- cli.py | 1 + commands/__init__.py | 5 ++++- commands/backlog.py | 31 ++++++++++++++++++++++++++----- commands/csv.py | 10 +++++----- commands/fetch.py | 17 +++++++++++++---- commands/issues.py | 1 + commands/items.py | 10 ++-------- commands/standup.py | 22 +++++++++++++++++++--- commands/view.py | 7 +++++-- console.py | 1 - db.py | 12 +++--------- gh.py | 16 +++++++++++++--- login_to_name.py | 2 +- make_table.py | 2 +- print_issues.py | 10 +++++++--- print_items.py | 21 +++++++++++++-------- sorters.py | 2 +- sprint_is_active.py | 10 +++++++++- 18 files changed, 124 insertions(+), 56 deletions(-) diff --git a/cli.py b/cli.py index a7929b6..21966a2 100644 --- a/cli.py +++ b/cli.py @@ -1,5 +1,6 @@ import click + @click.group() def cli(): pass diff --git a/commands/__init__.py b/commands/__init__.py index 13632cb..ecf5ec1 100644 --- a/commands/__init__.py +++ b/commands/__init__.py @@ -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") +] diff --git a/commands/backlog.py b/commands/backlog.py index 7e646e7..12053a1 100644 --- a/commands/backlog.py +++ b/commands/backlog.py @@ -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( @@ -34,4 +53,6 @@ def backlog(by_assignee, clipper, bugs): ), ).items() ) - print_items(grouped, opt("milestone", "title", default="No milestone"), status_first=False) \ No newline at end of file + print_items( + grouped, opt("milestone", "title", default="No milestone"), status_first=False + ) diff --git a/commands/csv.py b/commands/csv.py index f930580..b03c37c 100644 --- a/commands/csv.py +++ b/commands/csv.py @@ -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) \ No newline at end of file + writer.writerow(column(item) for column in columns) diff --git a/commands/fetch.py b/commands/fetch.py index 255d520..20a3cdb 100644 --- a/commands/fetch.py +++ b/commands/fetch.py @@ -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: @@ -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: @@ -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) @@ -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}) \ No newline at end of file + db.store({"issues": issues, "project_items": project_items, "prs": prs}) diff --git a/commands/issues.py b/commands/issues.py index 63b2e6c..63c3088 100644 --- a/commands/issues.py +++ b/commands/issues.py @@ -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( diff --git a/commands/items.py b/commands/items.py index 9b05fc1..f43eebe 100644 --- a/commands/items.py +++ b/commands/items.py @@ -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] @@ -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: @@ -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) - - - diff --git a/commands/standup.py b/commands/standup.py index a8beb03..d5dcb03 100644 --- a/commands/standup.py +++ b/commands/standup.py @@ -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) \ No newline at end of file + 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, + ) diff --git a/commands/view.py b/commands/view.py index e20208b..3ed6699 100644 --- a/commands/view.py +++ b/commands/view.py @@ -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"] @@ -94,4 +97,4 @@ def utc_to_pdt(utc): res = res + " (Yesterday)" else: res = res + f" ({days_ago} days ago)" - return res \ No newline at end of file + return res diff --git a/console.py b/console.py index 368e968..4707a6b 100644 --- a/console.py +++ b/console.py @@ -1,4 +1,3 @@ from rich.console import Console _console = Console() - diff --git a/db.py b/db.py index 1aa512e..ad74de7 100644 --- a/db.py +++ b/db.py @@ -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(): @@ -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) \ No newline at end of file + json.dump(empty_db, f) diff --git a/gh.py b/gh.py index ca432d5..156eb71 100644 --- a/gh.py +++ b/gh.py @@ -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): @@ -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__": diff --git a/login_to_name.py b/login_to_name.py index 23e9589..47e749a 100644 --- a/login_to_name.py +++ b/login_to_name.py @@ -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] diff --git a/make_table.py b/make_table.py index 5a01b7b..f36b129 100644 --- a/make_table.py +++ b/make_table.py @@ -14,4 +14,4 @@ def make_table(columns, items, sort_by=None): else: row.append(col(issue)) table.append(row) - return table \ No newline at end of file + return table diff --git a/print_issues.py b/print_issues.py index cc83636..3314378 100644 --- a/print_issues.py +++ b/print_issues.py @@ -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"))) - ) \ No newline at end of file + + tabulate( + make_table(columns, issues, sort_by=opt("updatedAt", default="3000")) + ) + ) diff --git a/print_items.py b/print_items.py index ff0014f..c1c016d 100644 --- a/print_items.py +++ b/print_items.py @@ -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)))) diff --git a/sorters.py b/sorters.py index bad8722..70dda07 100644 --- a/sorters.py +++ b/sorters.py @@ -24,4 +24,4 @@ def get_label_sort(item): return 0 if "icebox" in labels: return 1 - return 0 \ No newline at end of file + return 0 diff --git a/sprint_is_active.py b/sprint_is_active.py index b16e10b..1956ab8 100644 --- a/sprint_is_active.py +++ b/sprint_is_active.py @@ -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"] + )