Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/lando/ui/jinja2/stack/pull_request.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends "partials/layout.html" %}
{% block page_title %}{{pull_request}}{% endblock %}

{% block main %}
<main class="StackPage container fullhd">
Comment thread
zzzeid marked this conversation as resolved.
<h1>Pull request {{ pull_request.number }}</h1>
<div class="StackPage-stack">
<table>
<tr>
<th>Pull request</th>
<td>{{ pull_request.number }}</td>
</tr>
<tr>
<th>Target Lando Repo</th>
<td>{{ target_repo }}</td>
</tr>
<tr>
<th>GitHub repo</th>
<td>{{ pull_request.head_repo_git_url }}</td>
</tr>
<tr>
<th>Author</th>
<td>{{ pull_request.user_login }}</td>
</tr>
<tr>
<th>State</th>
<td>{{ pull_request.state}}</td>
</tr>
<tr>
<th>Title</th>
<td><a href="{{ pull_request.html_url }}">{{ pull_request.title }}</a></td>
</tr>
<tr>
<th>Description</th>
<td>{{ pull_request.body }}</td>
</tr>
</table>
</div>
</main>
{% endblock %}
33 changes: 33 additions & 0 deletions src/lando/ui/pull_requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging

from django.core.handlers.wsgi import WSGIRequest
from django.template.response import TemplateResponse

from lando.main.models import Repo
from lando.ui.views import LandoView
from lando.utils.github import GitHubAPIClient, PullRequest

logger = logging.getLogger(__name__)


class PullRequestView(LandoView):
"""A class-based view to handle pull requests in the Lando UI."""

def get(
self, request: WSGIRequest, repo_name: str, number: int, *args, **kwargs
) -> TemplateResponse:
"""Handle the GET request for the pull request view."""
target_repo = Repo.objects.get(name=repo_name)
client = GitHubAPIClient(target_repo)
pull_request = PullRequest(client.get_pull_request(number))

context = {
"target_repo": target_repo,
"pull_request": pull_request,
}

return TemplateResponse(
request=request,
template="stack/pull_request.html",
context=context,
)
7 changes: 6 additions & 1 deletion src/lando/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from lando.try_api.api import (
api as try_api,
)
from lando.ui import jobs
from lando.ui import jobs, pull_requests
from lando.ui.legacy import pages, revisions, user_settings

urlpatterns = [
Expand All @@ -52,6 +52,11 @@
path(
"D<int:revision_id>/", revisions.RevisionView.as_view(), name="revisions-page"
),
path(
"pulls/<str:repo_name>/<int:number>/",
pull_requests.PullRequestView.as_view(),
name="pull-request",
),
path("manage_api_key/", user_settings.manage_api_key, name="user-settings"),
path("uplift/", revisions.UpliftRequestView.as_view(), name="uplift-page"),
path(
Expand Down
57 changes: 57 additions & 0 deletions src/lando/utils/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,60 @@ def list_pull_requests(self) -> list:
def get_pull_request(self, pull_number: int) -> dict:
"""Get a specific pull request from the repo."""
return self._get(f"{self.repo_base_url}/pulls/{pull_number}")

def get_diff(self, url: str) -> str:
pass
Comment thread
zzzeid marked this conversation as resolved.


class PullRequest:
"""A class that parses data returned from the GitHub API for pull requests."""

def __repr__(self) -> str:
return f"Pull request #{self.number} ({self.head_repo_git_url})"

def __init__(self, data: dict):
self.url = data["url"]
self.base_ref = data["base"]["ref"] # "source" branch name
self.base_sha = data["base"]["sha"] # "source" branch sha
self.base_user_login = data["base"]["user"]["login"]
self.base_user_id = data["base"]["user"]["id"]
self.created_at = data["created_at"]
self.updated_at = data["updated_at"]
self.closed_at = data["closed_at"]
self.merged_at = data["merged_at"]
self.diff_url = data["diff_url"]
self.patch_url = data["patch_url"]
self.body = data["body"] # description
self.is_draft = data["draft"]
self.comments_url = data["comments_url"]
self.commits_url = data["commits_url"]

self.head_ref = data["head"]["ref"] # "destination" branch name
self.head_sha = data["head"]["sha"]
self.head_repo_git_url = data["head"]["repo"][
"git_url"
] # e.g., git://github.com/mozilla-conduit/test-repo.git
self.html_url = data["html_url"]
self.id = data["id"]
self.number = data["number"]
self.requested_reviewers = [
{"id": r["id"], "html_url": r["html_url"], "login": r["login"]}
for r in data["requested_reviewers"]
]
self.requested_teams = [
{
"id": r["id"],
"html_url": r["html_url"],
"name": r["name"],
"slug": r["slug"],
"description": r["description"],
}
for r in data["requested_teams"]
]

self.state = data["state"] # e.g., "open"
self.title = data["title"]

self.user_id = data["user"]["id"]
self.user_html_url = data["user"]["html_url"]
self.user_login = data["user"]["login"]