From d444571542e30bc645475ecfeb5c86c68737cfd7 Mon Sep 17 00:00:00 2001 From: Syeda Zainab <83520846+srzainab@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:21:30 -0800 Subject: [PATCH 1/8] update version for breaking change --- .vscode/launch.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 7c181ad..8b3049c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,7 +3,7 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 { - "version": "1.3.0", + "version": "2.0.0", "configurations": [ { "name": "Run Extension", diff --git a/package.json b/package.json index 4155e63..0af4e6b 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "publisher": "Pullflow", "displayName": "Pullflow", "description": "Code review collaboration across GitHub, Slack, and VS Code.", - "version": "1.3.0", + "version": "2.0.0", "preview": true, "license": "MIT", "engines": { From 5b908e4577fb8851edfe96d6d43de46937543e0a Mon Sep 17 00:00:00 2001 From: Syeda Zainab <83520846+srzainab@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:22:17 -0800 Subject: [PATCH 2/8] updated spaceUsersForVscode API to match Pullflow 2.0 --- src/api/spaceUsersApi.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api/spaceUsersApi.ts b/src/api/spaceUsersApi.ts index 86cc70e..a6e2cb5 100644 --- a/src/api/spaceUsersApi.ts +++ b/src/api/spaceUsersApi.ts @@ -4,8 +4,8 @@ import { PullflowApi } from '../utils/pullflowApi' const module = 'spaceUsersApi.ts' -const SPACE_USERS_QUERY = `query spaceUsersForVscode { - spaceUsersForVscode { +const SPACE_USERS_QUERY = `query spaceUsersForVscode($codeReviewId: String!) { + spaceUsersForVscode(codeReviewId: $codeReviewId) { message spaceUsers { name @@ -16,17 +16,19 @@ const SPACE_USERS_QUERY = `query spaceUsersForVscode { ` export const SpaceUsersApi = { get: async ({ - context, authToken, + codeReviewId, + context, }: { authToken: string + codeReviewId: string context: ExtensionContext }) => { log.info(`fetching space users`, module) const pullflowApi = new PullflowApi(context, authToken) try { - const data = await pullflowApi.fetch(SPACE_USERS_QUERY) + const data = await pullflowApi.fetch(SPACE_USERS_QUERY, { codeReviewId }) return data.spaceUsersForVscode } catch (e) { log.error(`error in fetching space users, ${e}`, module) From 21382034f1ea04aefa35a4af07227cc29252f5fc Mon Sep 17 00:00:00 2001 From: Syeda Zainab <83520846+srzainab@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:22:27 -0800 Subject: [PATCH 3/8] add SpaceUsers model for fetching users --- src/models/spaceUsers.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/models/spaceUsers.ts diff --git a/src/models/spaceUsers.ts b/src/models/spaceUsers.ts new file mode 100644 index 0000000..6d4ec60 --- /dev/null +++ b/src/models/spaceUsers.ts @@ -0,0 +1,29 @@ +import { ExtensionContext, window } from 'vscode' +import { Authorization } from '../utils/authorization' +import { SpaceUsersApi } from '../api/spaceUsersApi' + +export const SpaceUsers = { + get: async ({ + context, + codeReviewId, + }: { + context: ExtensionContext + codeReviewId: string + }) => { + const session = await Authorization.currentSession(context) + const response = await SpaceUsersApi.get({ + codeReviewId, + authToken: session?.accessToken ?? '', + context, + }) + + if (!response || response.message || response.error) { + window.showInformationMessage( + `Failed to fetch space users, please try again.` + ) + return false + } + + return response.spaceUsers + }, +} From fb26577394efc6e812413732a797d756d7c30f31 Mon Sep 17 00:00:00 2001 From: Syeda Zainab <83520846+srzainab@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:22:49 -0800 Subject: [PATCH 4/8] remove space users call from initialize --- src/utils/initialize.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/utils/initialize.ts b/src/utils/initialize.ts index 8ab082b..f8c20a3 100644 --- a/src/utils/initialize.ts +++ b/src/utils/initialize.ts @@ -2,7 +2,6 @@ import { ExtensionContext, StatusBarItem, WindowState, - commands, window, workspace, } from 'vscode' @@ -11,9 +10,7 @@ import { log } from './logger' import { StatusBar } from '../views/statusBar/statusBar' import { Authorization } from './authorization' import { StatusBarState } from './types' -import { SpaceUsersApi } from '../api/spaceUsersApi' import { PullRequestState } from './pullRequestsState' -import { Command } from './commands' import { trackUserPresence } from '../userPresence/trackUserPresence' const POLLING_TIME = 60000 // in ms @@ -103,21 +100,8 @@ const setSpaceUsers = async ({ return } - const spaceUsers = await SpaceUsersApi.get({ - authToken: session?.accessToken ?? '', - context, - }) - if (spaceUsers.error || spaceUsers.message) { - window.showInformationMessage( - `Error in fetching space users ${spaceUsers.error || spaceUsers.message}` - ) - commands.executeCommand(Command.signOut) - return - } - await Store.set(context, { isFocused: window.state.focused, - spaceUsers: spaceUsers.spaceUsers, }) } From 8b0f1721e6036c60dc1c04a72fc51a4a7522e97a Mon Sep 17 00:00:00 2001 From: Syeda Zainab <83520846+srzainab@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:22:59 -0800 Subject: [PATCH 5/8] explicitly pass users to picker --- src/views/quickpicks/spaceUserPicker.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/views/quickpicks/spaceUserPicker.ts b/src/views/quickpicks/spaceUserPicker.ts index d7d0a49..cbfcd51 100644 --- a/src/views/quickpicks/spaceUserPicker.ts +++ b/src/views/quickpicks/spaceUserPicker.ts @@ -1,5 +1,4 @@ -import { ExtensionContext, window } from 'vscode' -import { Store } from '../../utils/store' +import { ExtensionContext } from 'vscode' import { SpaceUser, SpaceUserSelectionItem } from '../../utils' import { QuickPick } from './quickPick' @@ -8,6 +7,7 @@ export const spaceUserPicker = ({ placeholder, title, onDidChangeSelection, + spaceUsers, }: { context: ExtensionContext placeholder: string @@ -15,12 +15,8 @@ export const spaceUserPicker = ({ onDidChangeSelection: ( item: readonly SpaceUserSelectionItem[] ) => Promise + spaceUsers: SpaceUser[] }) => { - const spaceUsers = Store.get(context)?.spaceUsers - if (!spaceUsers) { - window.showInformationMessage(`Failed to find space users`) - return - } const spaceUsersItems = spaceUsers.map((user: SpaceUser) => { return { label: user.name, From 3f3a3850cae8a6d015806e7cf3bcef58f8c81d3e Mon Sep 17 00:00:00 2001 From: Syeda Zainab <83520846+srzainab@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:23:10 -0800 Subject: [PATCH 6/8] add space users call in pull request quick actions --- .../pullRequestQuickActions.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/pullRequestQuickActions/pullRequestQuickActions.ts b/src/pullRequestQuickActions/pullRequestQuickActions.ts index e2901e1..ba17918 100644 --- a/src/pullRequestQuickActions/pullRequestQuickActions.ts +++ b/src/pullRequestQuickActions/pullRequestQuickActions.ts @@ -7,6 +7,7 @@ import { Presence } from '../models/presence' import { TimeSelectionItem, timePicker } from '../views/quickpicks/timePicker' import moment = require('moment') import { PullRequestState } from '../utils/pullRequestsState' +import { SpaceUsers } from '../models/spaceUsers' export const PullRequestQuickActions = { applyLabel: async ({ @@ -118,10 +119,19 @@ export const PullRequestQuickActions = { context: ExtensionContext statusBar: StatusBarItem }) => { + const spaceUsers = await SpaceUsers.get({ + context, + codeReviewId: codeReview.id, + }) + if (!spaceUsers) { + return false + } + spaceUserPicker({ context, placeholder: 'Select a user', title: 'Add assignee to pull request', + spaceUsers, onDidChangeSelection: async (item) => { if (!item[0].description) return false @@ -156,6 +166,7 @@ export const PullRequestQuickActions = { context, statusBar, }) + return true }, requestReview: async ({ @@ -167,10 +178,19 @@ export const PullRequestQuickActions = { context: ExtensionContext statusBar: StatusBarItem }) => { + const spaceUsers = await SpaceUsers.get({ + context, + codeReviewId: codeReview.id, + }) + if (!spaceUsers) { + return false + } + spaceUserPicker({ context, placeholder: 'Select a user', title: 'Add reviewer to pull request', + spaceUsers, onDidChangeSelection: async (item) => { if (!item[0].description) return false @@ -209,6 +229,7 @@ export const PullRequestQuickActions = { context, statusBar, }) + return true }, refresh: async ({ From f514c47c1c8e2c3fd228d9fbcd5105bf2ba13c5f Mon Sep 17 00:00:00 2001 From: Syeda Zainab <83520846+srzainab@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:26:00 -0800 Subject: [PATCH 7/8] fixed breaking spec --- .../pullRequestQuickActions.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pullRequestQuickActions/pullRequestQuickActions.test.ts b/src/pullRequestQuickActions/pullRequestQuickActions.test.ts index bbde735..6d25b72 100644 --- a/src/pullRequestQuickActions/pullRequestQuickActions.test.ts +++ b/src/pullRequestQuickActions/pullRequestQuickActions.test.ts @@ -39,6 +39,7 @@ describe('Pull Request Quick Actions', () => { }) it('adds assignee to pull request', async () => { + mockSpaceUsers.SpaceUsers.get.mockReturnValue([]) await subject().addAssignee({ codeReview: mockModel, context: mockModel, @@ -49,6 +50,7 @@ describe('Pull Request Quick Actions', () => { context: mockModel, placeholder: 'Select a user', title: 'Add assignee to pull request', + spaceUsers: [], }) ) expect(mockPresence.Presence.set).toBeCalled() @@ -56,6 +58,7 @@ describe('Pull Request Quick Actions', () => { }) it('adds reviewer on pull request', async () => { + mockSpaceUsers.SpaceUsers.get.mockReturnValue([]) await subject().requestReview({ codeReview: mockModel, context: mockModel, @@ -66,6 +69,7 @@ describe('Pull Request Quick Actions', () => { context: mockModel, placeholder: 'Select a user', title: 'Add reviewer to pull request', + spaceUsers: [], }) ) expect(mockPresence.Presence.set).toBeCalled() @@ -84,6 +88,7 @@ const subject = () => { jest.mock('../utils/pullRequestsState', () => mockPullRequestState) jest.mock('../views/quickpicks/spaceUserPicker', () => mockSpaceUserPicker) jest.mock('../views/quickpicks/timePicker', () => mockTimerPicker) + jest.mock('../models/spaceUsers', () => mockSpaceUsers) return require('./pullRequestQuickActions').PullRequestQuickActions } @@ -109,6 +114,11 @@ const mockPullRequestState = { updateWithDelay: jest.fn(), }, } +const mockSpaceUsers = { + SpaceUsers: { + get: jest.fn(), + }, +} const mockSpaceUserPicker = { spaceUserPicker: jest.fn(), } From 767189163a7a1eb8d0383b46777fab29bea28f3e Mon Sep 17 00:00:00 2001 From: Syeda Zainab <83520846+srzainab@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:31:45 -0800 Subject: [PATCH 8/8] version bump --- .vscode/launch.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 7c181ad..8b3049c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,7 +3,7 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 { - "version": "1.3.0", + "version": "2.0.0", "configurations": [ { "name": "Run Extension", diff --git a/package.json b/package.json index 4155e63..0af4e6b 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "publisher": "Pullflow", "displayName": "Pullflow", "description": "Code review collaboration across GitHub, Slack, and VS Code.", - "version": "1.3.0", + "version": "2.0.0", "preview": true, "license": "MIT", "engines": {