From 9b645c04ec541807511be1a8150adc85bba425dd Mon Sep 17 00:00:00 2001 From: gizmo385 Date: Wed, 26 Jun 2024 07:36:55 +0000 Subject: [PATCH] VERY simple placeholder UI output for review comments --- lazy_github/ui/screens/primary.py | 2 +- lazy_github/ui/widgets/pull_requests.py | 53 ++++++++++++++----------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/lazy_github/ui/screens/primary.py b/lazy_github/ui/screens/primary.py index 9b90e89..d189560 100644 --- a/lazy_github/ui/screens/primary.py +++ b/lazy_github/ui/screens/primary.py @@ -158,7 +158,7 @@ async def on_pull_request_selected(self, message: PullRequestSelected) -> None: tabbed_content.clear_panes() tabbed_content.add_pane(PrOverviewTabPane(full_pr)) tabbed_content.add_pane(PrDiffTabPane(self.client, full_pr)) - tabbed_content.add_pane(PrConversationTabPane(full_pr)) + tabbed_content.add_pane(PrConversationTabPane(self.client, full_pr)) tabbed_content.focus() diff --git a/lazy_github/ui/widgets/pull_requests.py b/lazy_github/ui/widgets/pull_requests.py index 7a158e0..824b918 100644 --- a/lazy_github/ui/widgets/pull_requests.py +++ b/lazy_github/ui/widgets/pull_requests.py @@ -2,15 +2,15 @@ from textual import on, work from textual.app import ComposeResult -from textual.containers import ScrollableContainer +from textual.containers import Container, ScrollableContainer from textual.coordinate import Coordinate -from textual.widgets import Label, ListView, Markdown, RichLog, Rule, TabPane +from textual.widgets import Label, ListItem, ListView, Markdown, RichLog, Rule, TabPane from lazy_github.lib.github.client import GithubClient -from lazy_github.lib.github.pull_requests import get_diff +from lazy_github.lib.github.pull_requests import get_diff, get_reviews from lazy_github.lib.messages import IssuesAndPullRequestsFetched, PullRequestSelected from lazy_github.lib.string_utils import bold, link, pluralize -from lazy_github.models.github import FullPullRequest, PartialPullRequest +from lazy_github.models.github import FullPullRequest, PartialPullRequest, Review, ReviewState from lazy_github.ui.widgets.command_log import log_event from lazy_github.ui.widgets.common import LazyGithubContainer, LazyGithubDataTable @@ -140,9 +140,28 @@ def on_mount(self) -> None: self.fetch_diff() +class PrReview(Container): + def __init__(self, review: Review) -> None: + super().__init__() + self.review = review + + def compose(self) -> ComposeResult: + # TODO: Color the review text baesd on the state + if self.review.state == ReviewState.APPROVED: + pass + yield Label(f"Review from {self.review.user.login} ({self.review.state.title()}") + yield Markdown(self.review.body) + for comment in self.review.comments: + if comment.user: + created_at = comment.created_at.strftime("%x at %X") + yield Label(f"Comment from {comment.user.login} at {created_at}") + yield Markdown(comment.body) + + class PrConversationTabPane(TabPane): - def __init__(self, pr: FullPullRequest) -> None: + def __init__(self, client: GithubClient, pr: FullPullRequest) -> None: super().__init__("Conversation", id="conversation_pane") + self.client = client self.pr = pr def compose(self) -> ComposeResult: @@ -152,22 +171,6 @@ def compose(self) -> ComposeResult: def conversation_elements(self) -> ListView: return self.query_one("#conversation_elements", ListView) - @work - async def render_conversation( - self, - # pr_comments: Iterable[IssueComment], - # reviews: Iterable[PullRequestReview], - # review_comments: Iterable[PullRequestComment], - ) -> None: - pass - # conversation_elements = self.conversation_elements - # reviews_by_id = {r.id: r for r in reviews} - # review_comments_by_id = {rc.id: rc for rc in review_comments} - # pr_comments_by_id = {prc.id: prc for prc in pr_comments} - - # for review in review_comments: - # conversation_elements.append(ListItem(Label(f"{review.user.login}\n{review.body}"))) - @work async def fetch_conversation(self): # TODO: Okay, so the review API in Github is weird. There are 3 APIs we might need to leverage here. @@ -178,12 +181,14 @@ async def fetch_conversation(self): # necessary to setup a list of distinct threads of a review conversation that are happening. # 3. The review comments API, which pulls comments for a particular review. It doesn't look like the reviews API # actually has the full conversation associated with a review, so might need to query this as well :( - pass + reviews = await get_reviews(self.client, self.pr) + for review in reviews: + log_event(f"Adding review to the view with {len(review.comments)} comments") + self.conversation_elements.append(ListItem(PrReview(review))) # comments = self.pr.get_issue_comments() # reviews = self.pr.get_reviews() # review_comments = self.pr.get_review_comments() # self.render_conversation(comments, reviews, review_comments) def on_mount(self) -> None: - pass - # self.fetch_conversation() + self.fetch_conversation()