Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.0.0 #68

Merged
merged 9 commits into from
Feb 26, 2024
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 .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 6 additions & 4 deletions src/api/spaceUsersApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions src/models/spaceUsers.ts
Original file line number Diff line number Diff line change
@@ -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
},
}
10 changes: 10 additions & 0 deletions src/pullRequestQuickActions/pullRequestQuickActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -49,13 +50,15 @@ describe('Pull Request Quick Actions', () => {
context: mockModel,
placeholder: 'Select a user',
title: 'Add assignee to pull request',
spaceUsers: [],
})
)
expect(mockPresence.Presence.set).toBeCalled()
expect(mockPullRequestState.PullRequestState.updateWithDelay).toBeCalled()
})

it('adds reviewer on pull request', async () => {
mockSpaceUsers.SpaceUsers.get.mockReturnValue([])
await subject().requestReview({
codeReview: mockModel,
context: mockModel,
Expand All @@ -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()
Expand All @@ -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
}

Expand All @@ -109,6 +114,11 @@ const mockPullRequestState = {
updateWithDelay: jest.fn(),
},
}
const mockSpaceUsers = {
SpaceUsers: {
get: jest.fn(),
},
}
const mockSpaceUserPicker = {
spaceUserPicker: jest.fn(),
}
Expand Down
21 changes: 21 additions & 0 deletions src/pullRequestQuickActions/pullRequestQuickActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ({
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -156,6 +166,7 @@ export const PullRequestQuickActions = {
context,
statusBar,
})
return true
},

requestReview: async ({
Expand All @@ -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

Expand Down Expand Up @@ -209,6 +229,7 @@ export const PullRequestQuickActions = {
context,
statusBar,
})
return true
},

refresh: async ({
Expand Down
16 changes: 0 additions & 16 deletions src/utils/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
ExtensionContext,
StatusBarItem,
WindowState,
commands,
window,
workspace,
} from 'vscode'
Expand All @@ -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
Expand Down Expand Up @@ -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,
})
}

Expand Down
10 changes: 3 additions & 7 deletions src/views/quickpicks/spaceUserPicker.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -8,19 +7,16 @@ export const spaceUserPicker = ({
placeholder,
title,
onDidChangeSelection,
spaceUsers,
}: {
context: ExtensionContext
placeholder: string
title: string
onDidChangeSelection: (
item: readonly SpaceUserSelectionItem[]
) => Promise<boolean>
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,
Expand Down
Loading