Fix comment button not disabling while attestation is added by alexr00 · Pull Request #9078 · microsoft/vscode-pull-request-github · GitHub
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
2 changes: 1 addition & 1 deletion src/github/activityBarViewProvider.ts
2 changes: 1 addition & 1 deletion src/github/pullRequestOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode

private async approvePullRequestCommand(context: SubmitReviewArgs): Promise<void> {
const result = context.addAttestation
? await addAttestationCommit(this._folderRepositoryManager, this._item)
? await PullRequestReviewCommon.addAttestationForReviewCommand(this.getReviewContext(), ReviewType.Approve)
: undefined;
if (context.addAttestation && !result) {
return;
Expand Down
24 changes: 23 additions & 1 deletion src/github/pullRequestReviewCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'use strict';

import * as vscode from 'vscode';
import { addAttestationCommit } from './attestationCommit';
import { FolderRepositoryManager } from './folderRepositoryManager';
import { GithubItemStateEnum, IAccount, isITeam, ITeam, MergeMethod, PullRequestMergeability, reviewerId, ReviewState } from './interface';
import { BranchInfo } from './pullRequestGitHelper';
Expand All @@ -13,7 +14,7 @@ import { ConvertToDraftReply, PullRequest, ReadyForReviewReply, ReviewType, Stac
import Logger from '../common/logger';
import { DEFAULT_DELETION_METHOD, DELETE_BRANCH_AFTER_MERGE, PR_SETTINGS_NAMESPACE, SELECT_LOCAL_BRANCH, SELECT_REMOTE, SELECT_WORKTREE } from '../common/settingKeys';
import { assertStacksEnabled } from '../common/settingsUtils';
import { ReviewEvent, TimelineEvent } from '../common/timelineEvent';
import { CommitEvent, ReviewEvent, TimelineEvent } from '../common/timelineEvent';
import { Schemes } from '../common/uri';
import { formatError } from '../common/utils';
import { IRequestMessage } from '../common/webview';
Expand Down Expand Up @@ -129,6 +130,27 @@ export namespace PullRequestReviewCommon {
}
}

/**
* Adds an attestation commit ahead of a review submitted through a webview
* context-menu command. Signing and pushing can take a while, so the webview
* is marked busy up front rather than only once the review itself is sent.
* If the attestation fails, the busy state is cleared and `undefined` is returned.
*/
export async function addAttestationForReviewCommand(
ctx: ReviewContext,
reviewType: ReviewType,
): Promise<{ sha: string; event: CommitEvent } | undefined> {
await ctx.postMessage({
command: 'pr.submitting-review',
lastReviewType: reviewType
});
const result = await addAttestationCommit(ctx.folderRepositoryManager, ctx.item);
if (!result) {
await ctx.postMessage({ command: 'pr.append-review' });
}
return result;
Comment on lines +147 to +151
}

export async function doReviewMessage(
ctx: ReviewContext,
message: IRequestMessage<string>,
Expand Down
1 change: 1 addition & 0 deletions src/github/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export interface PullRequest extends Issue {
emailForCommit?: string;
pendingReviewType?: ReviewType;
pendingReviewSummaryText?: string;
pendingAttestation?: boolean;
status: PullRequestChecks | null;
reviewRequirement: PullRequestReviewRequirement | null;
canUpdateBranch: boolean;
Expand Down
1 change: 1 addition & 0 deletions webviews/common/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function setState(pullRequest: PullRequest | undefined): void {
if (oldPullRequest && oldPullRequest.number && oldPullRequest.number === pullRequest?.number) {
pullRequest.pendingCommentText = oldPullRequest.pendingCommentText;
pullRequest.pendingReviewSummaryText = oldPullRequest.pendingReviewSummaryText;
pullRequest.pendingAttestation = oldPullRequest.pendingAttestation;
}

if (pullRequest) {
Expand Down
1 change: 1 addition & 0 deletions webviews/common/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ export class PRContext {
state.pendingCommentText = '';
state.pendingReviewSummaryText = '';
state.pendingReviewType = undefined;
state.pendingAttestation = false;
this.updatePR(state);
}

Expand Down
11 changes: 6 additions & 5 deletions webviews/components/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,12 @@ export function AddComment({
repo,
number,
attestationCommitsEnabled,
isCurrentlyCheckedOut
isCurrentlyCheckedOut,
pendingAttestation
}: PullRequest) {
const { updatePR, requestChanges, approve, close, openOnGitHub, submit, uploadFilesIntoPendingComment, uploadPastedFilesIntoPendingComment } = useContext(PullRequestContext);
const [isBusy, setBusy] = useState(false);
const [addAttestation, setAddAttestation] = useState(false);
const addAttestation = !!pendingAttestation;
const form = useRef<HTMLFormElement>();
const textareaRef = useRef<HTMLTextAreaElement>();

Expand Down Expand Up @@ -628,7 +629,7 @@ export function AddComment({
name="add-attestation"
checked={addAttestation}
disabled={isBusy || busy}
onChange={(e) => setAddAttestation(e.currentTarget.checked)}
onChange={(e) => updatePR({ pendingAttestation: e.currentTarget.checked })}
/>
<label htmlFor="attestation-checkbox" className="attestation-checkbox-label">Add attestation</label>
</div>
Expand Down Expand Up @@ -719,7 +720,7 @@ const makeCommentMenuContext = (owner: string, repo: string, number: number, ava
export const AddCommentSimple = (pr: PullRequest) => {
const { updatePR, requestChanges, approve, submit, openOnGitHub, uploadFilesIntoPendingComment, uploadPastedFilesIntoPendingComment } = useContext(PullRequestContext);
const [isBusy, setBusy] = useState(false);
const [addAttestation, setAddAttestation] = useState(false);
const addAttestation = !!pr.pendingAttestation;
const textareaRef = useRef<HTMLTextAreaElement>();
let currentSelection: ReviewType = pr.lastReviewType ?? (pr.currentUserReviewState === 'APPROVED' ? ReviewType.Approve : (pr.currentUserReviewState === 'CHANGES_REQUESTED' ? ReviewType.RequestChanges : ReviewType.Comment));

Expand Down Expand Up @@ -807,7 +808,7 @@ export const AddCommentSimple = (pr: PullRequest) => {
name="add-attestation"
checked={addAttestation}
disabled={isBusy || pr.busy}
onChange={(e) => setAddAttestation(e.currentTarget.checked)}
onChange={(e) => updatePR({ pendingAttestation: e.currentTarget.checked })}
/>
<label htmlFor="attestation-checkbox-simple" className="attestation-checkbox-label">Add attestation</label>
</div>
Expand Down
4 changes: 2 additions & 2 deletions webviews/components/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function AddReviewSummaryComment() {
const comment = useRef<HTMLTextAreaElement>();
const [isBusy, setBusy] = useState(false);
const commentText = pr.pendingReviewSummaryText ?? '';
const [addAttestation, setAddAttestation] = useState(false);
const addAttestation = !!pr.pendingAttestation;

const showAttestationCheckbox = !isAuthor && !!pr?.attestationCommitsEnabled && !!pr?.isCurrentlyCheckedOut;

Expand Down Expand Up @@ -385,7 +385,7 @@ function AddReviewSummaryComment() {
name="add-attestation"
checked={addAttestation}
disabled={isBusy || pr?.busy}
onChange={(e) => setAddAttestation(e.currentTarget.checked)}
onChange={(e) => updatePR({ pendingAttestation: e.currentTarget.checked })}
/>
<label htmlFor="attestation-checkbox-summary" className="attestation-checkbox-label">Add attestation</label>
</div>
Expand Down
84 changes: 84 additions & 0 deletions webviews/editorWebview/test/attestation.test.tsx
Loading