Skip to content

Commit

Permalink
VERY simple placeholder UI output for review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gizmo385 committed Jun 26, 2024
1 parent 3db29f6 commit 9b645c0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lazy_github/ui/screens/primary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
53 changes: 29 additions & 24 deletions lazy_github/ui/widgets/pull_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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()

0 comments on commit 9b645c0

Please sign in to comment.