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
1 change: 1 addition & 0 deletions preview-src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface PullRequest {
pendingCommentText?: string;
pendingCommentDrafts?: { [key: string]: string; };
status: ReposGetCombinedStatusForRefResponse;
mergeable; boolean;
}

export function getState(): PullRequest {
Expand Down
10 changes: 10 additions & 0 deletions preview-src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ body .comment-container .review-comment-header a {
margin-left: 15px;
}

.status-item {
display: flex;
padding-top: 12px;
}

.status-item a {
margin-left: 10px;
cursor: pointer;
}

#status-checks {
margin-top: 5px;
}
Expand Down
2 changes: 1 addition & 1 deletion preview-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function renderPullRequest(pr: PullRequest): void {
renderTimelineEvents(pr);
setTitleHTML(pr);
setTextArea();
renderStatusChecks(pr.status);
renderStatusChecks(pr);
updateCheckoutButton(pr.isCurrentlyCheckedOut);
updatePullRequestState(pr.state);

Expand Down
73 changes: 52 additions & 21 deletions preview-src/pullRequestOverviewRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TimelineEvent, CommitEvent, ReviewEvent, CommentEvent, EventType, isCom
import { PullRequestStateEnum } from '../src/github/interface';
import md from './mdRenderer';
import { MessageHandler } from './message';
import { getState, updateState } from './cache';
import { getState, updateState, PullRequest } from './cache';
import { Comment } from '../src/common/comment';

const commitIconSvg = require('../resources/icons/commit_icon.svg');
Expand Down Expand Up @@ -82,46 +82,77 @@ function getStateIcon(state: string) {
}
}

export function renderStatusChecks(statusInfo: any) {
const statusContainer: HTMLDetailsElement = document.getElementById('status-checks') as HTMLDetailsElement;
export function renderStatusChecks(pr: PullRequest) {
const statusContainer = document.getElementById('status-checks') as HTMLDivElement;
statusContainer.innerHTML = '';

if (!statusInfo.statuses.length) {
statusContainer.classList.add('hidden');
return;
} else {
statusContainer.classList.remove('hidden');
}
const { status, mergeable } = pr;

statusContainer.open = statusInfo.state !== 'success';
const statusCheckInformationContainer = document.createElement('div');

const statusSummary = document.createElement('summary');
const statusSummaryIcon = document.createElement('span');
const statusSummaryText = document.createElement('span');
statusSummaryIcon.innerHTML = getStateIcon(statusInfo.state);
const statusSummary = document.createElement('div');
statusSummary.classList.add('status-item');
const statusSummaryIcon = document.createElement('div');
const statusSummaryText = document.createElement('div');
statusSummaryIcon.innerHTML = getStateIcon(status.state);
statusSummary.appendChild(statusSummaryIcon);
statusSummaryText.textContent = getSummaryLabel(statusInfo.statuses);
statusSummaryText.textContent = getSummaryLabel(status.statuses);
statusSummary.appendChild(statusSummaryText);
statusContainer.appendChild(statusSummary);
statusCheckInformationContainer.appendChild(statusSummary);

const statusesToggle = document.createElement('a');
statusesToggle.textContent = status.state === 'success' ? 'Show' : 'Hide';
statusesToggle.addEventListener('click', () => {
if (statusList.classList.contains('hidden')) {
statusList.classList.remove('hidden');
statusesToggle.textContent = 'Hide';
} else {
statusList.classList.add('hidden');
statusesToggle.textContent = 'Show';
}
});

statusSummary.appendChild(statusesToggle);

statusInfo.statuses.forEach(status => {
if (!status.statuses.length) {
statusCheckInformationContainer.classList.add('hidden');
}

const statusList = document.createElement('div');
if (status.state === 'success') {
statusList.classList.add('hidden');
}
statusCheckInformationContainer.appendChild(statusList);
statusContainer.appendChild(statusCheckInformationContainer);

status.statuses.forEach(s => {
const statusElement: HTMLDivElement = document.createElement('div');
statusElement.className = 'status-check';

const state: HTMLSpanElement = document.createElement('span');
state.innerHTML = getStateIcon(status.state);
state.innerHTML = getStateIcon(s.state);

statusElement.appendChild(state);

const statusIcon = renderUserIcon(status.url, status.avatar_url);
const statusIcon = renderUserIcon(s.url, s.avatar_url);
statusElement.appendChild(statusIcon);

const statusDescription = document.createElement('span');
statusDescription.textContent = `${status.context} - ${status.description}`;
statusDescription.textContent = `${s.context} - ${s.description}`;
statusElement.appendChild(statusDescription);

statusContainer.appendChild(statusElement);
statusList.appendChild(statusElement);
});

const mergeableSummary = document.createElement('div');
mergeableSummary.classList.add('status-item');
const mergeableSummaryIcon = document.createElement('div');
const mergeableSummaryText = document.createElement('div');
mergeableSummaryIcon.innerHTML = mergeable ? checkIcon : deleteIcon;
mergeableSummary.appendChild(mergeableSummaryIcon);
mergeableSummaryText.textContent = mergeable ? 'This branch has no conflicts with the base branch' : 'This branch has conflicts that must be resolved';
mergeableSummary.appendChild(mergeableSummaryText);
statusContainer.appendChild(mergeableSummary);
}

function renderUserIcon(iconLink: string, iconSrc: string): HTMLElement {
Expand Down
2 changes: 2 additions & 0 deletions src/github/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type PullRequest = Pick<
| 'commits'
| 'head'
| 'base'
| 'mergeable'
>;

export interface IRawFileChange {
Expand Down Expand Up @@ -103,6 +104,7 @@ export interface IPullRequestModel {
userAvatarUri: vscode.Uri;
body: string;
labels: string[];
prItem: PullRequest;
update(prItem: Github.PullRequestsGetResponse): void;
equals(other: IPullRequestModel): boolean;
}
Expand Down
5 changes: 3 additions & 2 deletions src/github/pullRequestOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ export class PullRequestOverviewPanel {
commitsCount: this._pullRequest.commitCount,
repositoryDefaultBranch: defaultBranch,
canEdit: canEdit,
status: status
status: status,
mergeable: this._pullRequest.prItem.mergeable
}
});
}).catch(e => {
Expand Down Expand Up @@ -476,7 +477,7 @@ export class PullRequestOverviewPanel {
<script nonce="${nonce}" src="${scriptUri}"></script>
<div id="title" class="title"></div>
<div id="timeline-events" class="discussion" aria-live="polite"></div>
<details id="status-checks" class="hidden"></details>
<div id="status-checks"></div>
<div id="comment-form" class="comment-form"></div>
</body>
</html>`;
Expand Down