Skip to content

Commit

Permalink
Support pending reviews when pull request is checked out
Browse files Browse the repository at this point in the history
Co-authored-by: Ashi Krishnan <queerviolet@github.com>
  • Loading branch information
Rachel Macfarlane and Ashi Krishnan committed Jan 7, 2019
1 parent da61b12 commit cd7f73a
Show file tree
Hide file tree
Showing 13 changed files with 743 additions and 128 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": "0.3.2",
"publisher": "GitHub",
"engines": {
"vscode": "^1.30.0"
"vscode": "^1.31.0"
},
"categories": [
"Other"
Expand Down
5 changes: 5 additions & 0 deletions preview-src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ body .comment-container .review-comment-header a {
margin-left: auto;
}

.review-comment-header .pending {
color: inherit;
font-style: italic;
}

.comment-actions button {
background-color: transparent;
padding: 2px 6px 3px;
Expand Down
45 changes: 31 additions & 14 deletions preview-src/pullRequestOverviewRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,22 +341,33 @@ class CommentNode {
authorLink.href = this._comment.user.html_url;
authorLink.textContent = this._comment.user.login;

const timestamp: HTMLAnchorElement = document.createElement('a');
timestamp.className = 'timestamp';
timestamp.href = this._comment.html_url;
timestamp.textContent = dateFromNow(this._comment.created_at);
commentHeader.appendChild(authorLink);

const commentState = document.createElement('span');
commentState.textContent = 'commented';
const isPending = this._review && this._review.isPending();
if (isPending) {
const pendingTag = document.createElement('a');
pendingTag.className = 'pending';
pendingTag.href = this._comment.html_url;
pendingTag.textContent = 'Pending';

commentHeader.appendChild(pendingTag);
} else {
const timestamp: HTMLAnchorElement = document.createElement('a');
timestamp.className = 'timestamp';
timestamp.href = this._comment.html_url;
timestamp.textContent = dateFromNow(this._comment.created_at);

const commentState = document.createElement('span');
commentState.textContent = 'commented';

commentHeader.appendChild(commentState);
commentHeader.appendChild(timestamp);
}

this._commentBody.className = 'comment-body';

this._commentBody.innerHTML = md.render(emoji.emojify(this._comment.body));

commentHeader.appendChild(authorLink);
commentHeader.appendChild(commentState);
commentHeader.appendChild(timestamp);

if (this._comment.canEdit || this._comment.canDelete) {
this._actionsBar = new ActionsBar(this._commentContainer, this._comment as Comment, this._commentBody, this._messageHandler, (e) => { }, 'pr.edit-comment', 'pr.delete-comment', this._review);
const actionBarElement = this._actionsBar.render();
Expand Down Expand Up @@ -471,6 +482,10 @@ class ReviewNode {

constructor(private _review: ReviewEvent, private _messageHandler: MessageHandler) { }

isPending(): boolean {
return this._review.state === 'pending';
}

deleteCommentFromReview(comment: Comment): void {
const deletedCommentIndex = this._review.comments.findIndex(c => c.id.toString() === comment.id.toString());
this._review.comments.splice(deletedCommentIndex, 1);
Expand All @@ -497,9 +512,6 @@ class ReviewNode {
render(): HTMLElement | undefined {
// Ignore pending or empty reviews
const isEmpty = !this._review.body && !(this._review.comments && this._review.comments.length);
if (this._review.state === 'pending') {
return undefined;
}

this._commentContainer = document.createElement('div');
this._commentContainer.classList.add('comment-container', 'comment');
Expand Down Expand Up @@ -530,7 +542,12 @@ class ReviewNode {
const timestamp: HTMLAnchorElement = document.createElement('a');
timestamp.className = 'timestamp';
timestamp.href = this._review.html_url;
timestamp.textContent = dateFromNow(this._review.submitted_at);
const isPending = this.isPending();
timestamp.textContent = isPending ? 'Pending' : dateFromNow(this._review.submitted_at);

if (isPending) {
timestamp.classList.add('pending');
}

commentHeader.appendChild(userLogin);
commentHeader.appendChild(reviewState);
Expand Down
1 change: 1 addition & 0 deletions src/common/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface Comment extends Github.PullRequestsCreateCommentResponse {
diff_hunks?: DiffHunk[];
canEdit?: boolean;
canDelete?: boolean;
isDraft?: boolean;
}
6 changes: 4 additions & 2 deletions src/github/githubRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ export class GitHubRepository implements IGitHubRepository {
created_at,
updated_at,
head,
base
base,
node_id
}) => {
if (!head.repo) {
Logger.appendLine(
Expand All @@ -211,7 +212,8 @@ export class GitHubRepository implements IGitHubRepository {
comments: 0,
commits: 0,
head,
base
base,
node_id
};

return new PullRequestModel(this, this.remote, item);
Expand Down
8 changes: 6 additions & 2 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'
| 'node_id'
>;

export interface IRawFileChange {
Expand Down Expand Up @@ -133,11 +134,10 @@ export interface IPullRequestManager {
getPullRequestComments(pullRequest: IPullRequestModel): Promise<Comment[]>;
getPullRequestCommits(pullRequest: IPullRequestModel): Promise<Github.PullRequestsGetCommitsResponseItem[]>;
getCommitChangedFiles(pullRequest: IPullRequestModel, commit: Github.PullRequestsGetCommitsResponseItem): Promise<Github.ReposGetCommitResponseFilesItem[]>;
getReviewComments(pullRequest: IPullRequestModel, reviewId: number): Promise<Github.PullRequestsCreateCommentResponse[]>;
getTimelineEvents(pullRequest: IPullRequestModel): Promise<TimelineEvent[]>;
getIssueComments(pullRequest: IPullRequestModel): Promise<Github.IssuesGetCommentsResponseItem[]>;
createIssueComment(pullRequest: IPullRequestModel, text: string): Promise<Github.IssuesCreateCommentResponse>;
createCommentReply(pullRequest: IPullRequestModel, body: string, reply_to: string): Promise<Comment>;
createCommentReply(pullRequest: IPullRequestModel, body: string, reply_to: Comment): Promise<Comment>;
createComment(pullRequest: IPullRequestModel, body: string, path: string, position: number): Promise<Comment>;
getPullRequestDefaults(): Promise<PullRequestsCreateParams>;
createPullRequest(params: PullRequestsCreateParams): Promise<IPullRequestModel>;
Expand All @@ -154,6 +154,10 @@ export interface IPullRequestManager {
getPullRequestFileChangesInfo(pullRequest: IPullRequestModel): Promise<IRawFileChange[]>;
getPullRequestRepositoryDefaultBranch(pullRequest: IPullRequestModel): Promise<string>;
getStatusChecks(pullRequest: IPullRequestModel): Promise<Github.ReposGetCombinedStatusForRefResponse>;
inDraftMode(pullRequest: IPullRequestModel): Promise<boolean>;
deleteReview(pullRequest: IPullRequestModel): Promise<Comment[]>;
submitReview(pullRequest: IPullRequestModel): Promise<Comment[]>;
startReview(pullRequest: IPullRequestModel): Promise<void>;

/**
* Fullfill information for a pull request which we can't fetch with one single api call.
Expand Down
Loading

0 comments on commit cd7f73a

Please sign in to comment.