Display a list of PRs for the selected path

This commit is contained in:
Yuri Sizov
2023-03-04 17:29:32 +01:00
parent 33165dcf5b
commit 29ef016116
6 changed files with 563 additions and 41 deletions

View File

@@ -355,11 +355,42 @@ class DataProcessor {
// Add changed files.
let files = mapNodes(item.files);
const visitedPaths = [];
if (typeof this._pullsByFile[pr.target_branch] === "undefined") {
this._pullsByFile[pr.target_branch] = {};
}
files.forEach((fileItem) => {
pr.files.push({
"path": fileItem.path,
"changeType": fileItem.changeType,
});
let currentPath = fileItem.path;
while (currentPath !== "") {
if (visitedPaths.includes(currentPath)) {
// Go one level up.
const pathBits = currentPath.split("/");
pathBits.pop();
currentPath = pathBits.join("/");
continue;
}
visitedPaths.push(currentPath);
pr.files.push({
"path": currentPath,
"changeType": (currentPath === fileItem.path ? fileItem.changeType : ""),
"type": (currentPath === fileItem.path ? "file" : "folder"),
});
// Cache the pull information for every file and folder that it includes.
if (typeof this._pullsByFile[pr.target_branch][currentPath] === "undefined") {
this._pullsByFile[pr.target_branch][currentPath] = [];
}
this._pullsByFile[pr.target_branch][currentPath].push(pr.public_id);
// Go one level up.
const pathBits = currentPath.split("/");
pathBits.pop();
currentPath = pathBits.join("/");
}
});
pr.files.sort((a, b) => {
if (a.name > b.name) return 1;
@@ -368,17 +399,6 @@ class DataProcessor {
});
this.pulls.push(pr);
// Cache the pull information for every file that it includes.
if (typeof this._pullsByFile[pr.target_branch] === "undefined") {
this._pullsByFile[pr.target_branch] = {};
}
pr.files.forEach((file) => {
if (typeof this._pullsByFile[pr.target_branch][file.path] === "undefined") {
this._pullsByFile[pr.target_branch][file.path] = [];
}
this._pullsByFile[pr.target_branch][file.path].push(pr.public_id);
})
});
} catch (err) {
console.error(" Error parsing pull request data: " + err);
@@ -406,19 +426,15 @@ class DataProcessor {
file.parent = parentPath.join("/");
}
// Fetch the PRs touching this file or files in this folder from the cache.
if (typeof this._pullsByFile[targetBranch] !== "undefined") {
for (let filePath in this._pullsByFile[targetBranch]) {
if (filePath !== file.path && filePath.indexOf(file.path + "/") < 0) {
continue;
}
// Fetch the PRs touching this file or folder from the cache.
if (typeof this._pullsByFile[targetBranch] !== "undefined"
&& typeof this._pullsByFile[targetBranch][file.path] !== "undefined") {
this._pullsByFile[targetBranch][filePath].forEach((pullNumber) => {
if (!file.pulls.includes(pullNumber)) {
file.pulls.push(pullNumber);
}
});
}
this._pullsByFile[targetBranch][file.path].forEach((pullNumber) => {
if (!file.pulls.includes(pullNumber)) {
file.pulls.push(pullNumber);
}
});
}
this.files[targetBranch].push(file);

View File

@@ -51,25 +51,34 @@ export default class FileList extends LitElement {
@property({ type: String }) selectedRepository = "godotengine/godot";
@property({ type: String }) selectedBranch = "master";
@property({ type: String }) selectedPath = "";
@property({ type: Array }) selectedFolders = [];
constructor() {
super();
}
_onItemClicked(entryType, entryPath) {
if (entryType !== "folder") {
return;
_onItemClicked(entryType, entryPath, entryPulls) {
if (entryType === "root") {
this.selectedFolders = [];
this.requestUpdate();
} else if (entryType === "folder") {
const entryIndex = this.selectedFolders.indexOf(entryPath);
if (entryIndex >= 0) {
this.selectedFolders.splice(entryIndex, 1);
} else {
this.selectedFolders.push(entryPath);
}
this.requestUpdate();
}
const entryIndex = this.selectedFolders.indexOf(entryPath);
if (entryIndex >= 0) {
this.selectedFolders.splice(entryIndex, 1);
} else {
this.selectedFolders.push(entryPath);
}
this.requestUpdate();
this.dispatchEvent(greports.util.createEvent("pathclicked", {
"type": entryType,
"path": entryPath,
"pulls": entryPulls,
}));
}
renderFolder(branchFiles, folderFiles) {
@@ -84,8 +93,8 @@ export default class FileList extends LitElement {
.name="${item.name}"
.type="${item.type}"
.pull_count="${item.pulls.length}"
?active="${this.selectedFolders.includes(item.path)}"
@click="${this._onItemClicked.bind(this, item.type, item.path)}"
?active="${this.selectedPath.indexOf(item.path) === 0}"
@click="${this._onItemClicked.bind(this, item.type, item.path, item.pulls)}"
></gr-file-item>
${(this.selectedFolders.includes(item.path)) ?
@@ -110,6 +119,7 @@ export default class FileList extends LitElement {
<gr-root-item
.repository="${this.selectedRepository}"
.branch="${this.selectedBranch}"
@click="${this._onItemClicked.bind(this, "root", "", [])}"
></gr-root-item>
${this.renderFolder(branchFiles, topLevel)}

View File

@@ -6,9 +6,11 @@ export default class RootItem extends LitElement {
return css`
/** Colors and variables **/
:host {
--tab-hover-background-color: rgba(0, 0, 0, 0.14);
}
@media (prefers-color-scheme: dark) {
:host {
--tab-hover-background-color: rgba(255, 255, 255, 0.14);
}
}
@@ -19,12 +21,16 @@ export default class RootItem extends LitElement {
:host .root-item {
color: var(--g-font-color);
cursor: pointer;
display: flex;
flex-direction: row;
gap: 8px;
padding: 6px 12px 6px 6px;
align-items: center;
}
:host .root-item:hover {
background-color: var(--tab-hover-background-color);
}
:host .root-icon {
background-image: url('/filesystem.svg');

View File

@@ -0,0 +1,286 @@
import { LitElement, html, css, customElement, property } from 'lit-element';
@customElement('gr-pull-request')
export default class PullRequestItem extends LitElement {
static get styles() {
return css`
/** Colors and variables **/
:host {
--pr-border-color: #fcfcfa;
--draft-font-color: #ffcc31;
--draft-background-color: #9db3c0;
--ghost-font-color: #738b99;
}
@media (prefers-color-scheme: dark) {
:host {
--pr-border-color: #0d1117;
--draft-font-color: #e0c537;
--draft-background-color: #1e313c;
--ghost-font-color: #495d68;
}
}
/** Component styling **/
:host {
border-bottom: 3px solid var(--pr-border-color);
display: block;
padding: 14px 12px 20px 12px;
}
:host a {
color: var(--link-font-color);
text-decoration: none;
}
:host a:hover {
color: var(--link-font-color-hover);
}
:host .pr-title {
display: inline-block;
font-size: 20px;
margin-top: 6px;
margin-bottom: 12px;
}
:host .pr-title-name {
color: var(--g-font-color);
line-height: 24px;
word-break: break-word;
}
:host .pr-title-draft {
background-color: var(--draft-background-color);
border-radius: 6px 6px;
color: var(--draft-font-color);
font-size: 14px;
padding: 1px 6px;
vertical-align: bottom;
}
:host .pr-meta {
color: var(--dimmed-font-color);
display: flex;
flex-direction: row;
justify-content: space-between;
font-size: 13px;
}
:host .pr-labels {
display: flex;
flex-flow: column wrap;
padding: 4px 0;
max-height: 60px;
}
:host .pr-label {
padding-right: 8px;
}
:host .pr-label-dot {
border-radius: 4px;
box-shadow: rgb(0 0 0 / 28%) 0 0 3px 0;
display: inline-block;
width: 8px;
height: 8px;
}
:host .pr-label-name {
padding-left: 3px;
}
:host .pr-milestone-value {
font-weight: 700;
}
:host .pr-time {
}
:host .pr-time-value {
border-bottom: 1px dashed var(--g-font-color);
cursor: help;
font-weight: 700;
}
:host .pr-author {
}
:host .pr-author-value {
}
:host .pr-author-value--hot:before {
content: "★";
color: var(--draft-font-color);
}
:host .pr-author-value--ghost {
color: var(--ghost-font-color);
font-weight: 600;
}
:host .pr-review {
display: flex;
justify-content: space-between;
font-size: 13px;
margin-top: 14px;
}
:host .pr-review-team {
color: var(--light-font-color);
white-space: nowrap;
}
:host .pr-review-team + .pr-review-team:before {
content: "· ";
white-space: break-spaces;
}
@media only screen and (max-width: 900px) {
:host {
padding: 14px 0 20px 0;
}
:host .pr-meta {
flex-wrap: wrap;
}
:host .pr-labels {
width: 100%;
justify-content: space-between;
}
}
`;
}
@property({ type: String }) id = '';
@property({ type: String }) title = '';
@property({ type: String, reflect: true }) url = '';
@property({ type: String, reflect: true }) diff_url = '';
@property({ type: String, reflect: true }) patch_url = '';
@property({ type: Boolean }) draft = false;
@property({ type: Array }) labels = [];
@property({ type: String, reflect: true }) milestone = '';
@property({ type: String, reflect: true }) branch = '';
@property({ type: String }) created_at = '';
@property({ type: String }) updated_at = '';
@property({ type: Object }) author = null;
render(){
const authorClassList = [ "pr-author-value" ];
if (this.author.pull_count > 40) {
authorClassList.push("pr-author-value--hot");
}
if (this.author.id === "") {
authorClassList.push("pr-author-value--ghost");
}
// Keep it to two columns, but if there isn't enough labels, keep it to one.
let labels_height = Math.ceil(this.labels.length / 2) * 20;
if (labels_height < 60) {
labels_height = 60;
}
return html`
<div class="pr-container">
<a
class="pr-title"
href="${this.url}"
target="_blank"
>
${(this.draft ? html`
<span class="pr-title-draft">draft</span>
` : '')}
<span class="pr-title-id">#${this.id}</span> <span class="pr-title-name">${this.title}</span>
</a>
<div class="pr-meta">
<div class="pr-labels" style="max-height:${labels_height}px">
${this.labels.map((item) => {
return html`
<span
class="pr-label"
>
<span
class="pr-label-dot"
style="background-color: ${item.color}"
></span>
<span
class="pr-label-name"
>
${item.name}
</span>
</span>
`;
})}
</div>
<div class="pr-milestone">
<div>
<span>milestone: </span>
${(this.milestone != null) ? html`
<a
href="${this.milestone.url}"
target="_blank"
>
${this.milestone.title}
</a>
` : html`
<span>none</span>
`}
</div>
<div>
<span>branch: </span>
<span class="pr-milestone-value">
${this.branch}
</span>
</div>
</div>
<div class="pr-timing">
<div class="pr-time">
<span>created: </span>
<span
class="pr-time-value"
title="${greports.format.formatTimestamp(this.created_at)}"
>
${greports.format.formatDate(this.created_at)}
</span>
</div>
<div class="pr-time">
<span>updated: </span>
<span
class="pr-time-value"
title="${greports.format.formatTimestamp(this.updated_at)}"
>
${greports.format.formatDate(this.updated_at)}
</span>
</div>
<div class="pr-author">
<span>author: </span>
<a
class="${authorClassList.join(" ")}"
href="https://github.com/godotengine/godot/pulls/${this.author.user}"
target="_blank"
title="Open ${this.author.pull_count} ${(this.author.pull_count > 1) ? 'PRs' : 'PR'} by ${this.author.user}"
>
${this.author.user}
</a>
</div>
</div>
</div>
<div class="pr-review">
<div class="pr-download">
<span>download changeset: </span>
<a
href="${this.diff_url}"
target="_blank"
>
diff
</a> |
<a
href="${this.patch_url}"
target="_blank"
>
patch
</a>
</div>
</div>
</div>
`;
}
}

View File

@@ -0,0 +1,162 @@
import { LitElement, html, css, customElement, property } from 'lit-element';
import PullRequestItem from "./PullRequestItem";
@customElement('gr-pull-list')
export default class PullRequestList extends LitElement {
static get styles() {
return css`
/** Colors and variables **/
:host {
--pulls-background-color: #e5edf8;
--pulls-toolbar-color: #9bbaed;
--pulls-toolbar-accent-color: #5a6f90;
}
@media (prefers-color-scheme: dark) {
:host {
--pulls-background-color: #191d23;
--pulls-toolbar-color: #222c3d;
--pulls-toolbar-accent-color: #566783;
}
}
/** Component styling **/
:host {
flex-grow: 1;
}
:host input[type=checkbox] {
margin: 0;
vertical-align: bottom;
}
:host select {
background: var(--pulls-background-color);
border: 1px solid var(--pulls-background-color);
color: var(--g-font-color);
font-size: 12px;
outline: none;
min-width: 60px;
}
:host .team-pulls {
background-color: var(--pulls-background-color);
border-radius: 0 4px 4px 0;
padding: 8px 12px;
max-width: 760px;
min-height: 200px;
}
:host .team-pulls-toolbar {
background: var(--pulls-toolbar-color);
border-radius: 4px;
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 10px 14px;
margin-bottom: 6px;
}
:host .pulls-count {
font-size: 15px;
}
:host .pulls-count strong {
font-size: 18px;
}
:host .pulls-count-total {
color: var(--dimmed-font-color);
}
@media only screen and (max-width: 900px) {
:host .team-pulls {
padding: 8px;
max-width: 95%;
margin: 0px auto;
}
:host .team-pulls-toolbar {
flex-wrap: wrap;
}
:host .pulls-count {
font-size: 17px;
margin-bottom: 12px;
text-align: center;
width: 100%;
}
:host .pulls-count strong {
font-size: 20px;
}
}
`;
}
@property({ type: Array }) pulls = [];
@property({ type: Object }) authors = {};
@property({ type: String }) selectedBranch = "";
@property({ type: String }) selectedPath = "";
@property({ type: Array }) selectedPulls = [];
render(){
if (this.selectedPath === "") {
return html``;
}
let pulls = [].concat(this.pulls);
pulls = pulls.filter((item) => {
if (item.target_branch !== this.selectedBranch) {
return false;
}
if (!this.selectedPulls.includes(item.public_id)) {
return false;
}
return true;
});
const total_pulls = this.pulls.length;
const filtered_pulls = pulls.length
return html`
<div class="team-pulls">
<div class="team-pulls-toolbar">
<div class="pulls-count">
<span>PRs affecting this path: </span>
<strong>${filtered_pulls}</strong>
${(filtered_pulls !== total_pulls) ? html`
<span class="pulls-count-total"> (out of ${total_pulls})</span>
` : ''
}
</div>
</div>
${pulls.map((item) => {
let author = null;
if (typeof this.authors[item.authored_by] != "undefined") {
author = this.authors[item.authored_by];
}
return html`
<gr-pull-request
.id="${item.public_id}"
.title="${item.title}"
.url="${item.url}"
?draft="${item.is_draft}"
.labels="${item.labels}"
.milestone="${item.milestone}"
.branch="${item.target_branch}"
.created_at="${item.created_at}"
.updated_at="${item.updated_at}"
.author="${author}"
.diff_url="${item.diff_url}"
.patch_url="${item.patch_url}"
/>
`;
})}
</div>
`;
}
}

View File

@@ -5,6 +5,7 @@ import IndexHeader from "./components/IndexHeader";
import IndexDescription from "./components/IndexDescription";
import FileList from "./components/files/FileList";
import PullList from "./components/pulls/PullRequestList"
@customElement('entry-component')
export default class EntryComponent extends LitElement {
@@ -23,7 +24,14 @@ export default class EntryComponent extends LitElement {
}
:host .files {
margin-top: 16px;
display: flex;
padding: 24px 0;
}
@media only screen and (max-width: 900px) {
:host .files {
flex-wrap: wrap;
}
}
`;
}
@@ -35,8 +43,15 @@ export default class EntryComponent extends LitElement {
this._isLoading = true;
this._generatedAt = null;
this._authors = {};
this._branches = [];
this._files = {};
this._pulls = [];
this._selectedRepository = "godotengine/godot";
this._selectedBranch = "master";
this._selectedPath = "";
this._selectedPathPulls = [];
this._requestData();
}
@@ -56,6 +71,8 @@ export default class EntryComponent extends LitElement {
if (data) {
this._generatedAt = data.generated_at;
this._authors = data.authors;
this._pulls = data.pulls;
data.branches.forEach((branch) => {
if (typeof data.files[branch] === "undefined") {
@@ -98,14 +115,27 @@ export default class EntryComponent extends LitElement {
} else {
this._generatedAt = null;
this._authors = {};
this._branches = [];
this._files = {};
this._pulls = [];
this._selectedRepository = "godotengine/godot";
this._selectedBranch = "master";
this._selectedPath = "";
this._selectedPathPulls = [];
}
this._isLoading = false;
this.requestUpdate();
}
_onPathClicked(event) {
this._selectedPath = event.detail.path;
this._selectedPathPulls = event.detail.pulls;
this.requestUpdate();
}
render(){
return html`
<page-content>
@@ -119,7 +149,19 @@ export default class EntryComponent extends LitElement {
<gr-file-list
.branches="${this._branches}"
.files="${this._files}"
.selectedRepository="${this._selectedRepository}"
.selectedBranch="${this._selectedBranch}"
.selectedPath="${this._selectedPath}"
@pathclicked="${this._onPathClicked}"
></gr-file-list>
<gr-pull-list
.pulls="${this._pulls}"
.authors="${this._authors}"
.selectedBranch="${this._selectedBranch}"
.selectedPath="${this._selectedPath}"
.selectedPulls="${this._selectedPathPulls}"
></gr-pull-list>
</div>
`)}
</page-content>