Skip to content

Commit

Permalink
Merge pull request #44 from pullflow/release/1.2.2
Browse files Browse the repository at this point in the history
🚂 Release 1.2.2
  • Loading branch information
srzainab authored Jan 14, 2024
2 parents 34dd444 + 4b1e154 commit b3b3d6b
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 35 deletions.
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.2.1",
"version": "1.2.2",
"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.2.1",
"version": "1.2.2",
"preview": true,
"license": "MIT",
"engines": {
Expand Down
1 change: 1 addition & 0 deletions src/__mocks__/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export enum QuickPickItemKind {

export const window = {
showInformationMessage: jest.fn(),
showInputBox: jest.fn(),
}
10 changes: 9 additions & 1 deletion src/commands/activePullRequests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExtensionContext, StatusBarItem } from 'vscode'
import { ExtensionContext, StatusBarItem, window } from 'vscode'
import { Store } from '../utils/store'
import { ActivePullRequestItems } from '../views/quickpicks/items/activePullRequestItems'
import { pullRequestActionPicker } from '../views/quickpicks/pullRequestActionPicker'
Expand All @@ -12,6 +12,14 @@ export const ActivePullRequests = (
const codeReviews = Store.get(context)
if (!codeReviews) return

if (
!codeReviews?.pendingUserCodeReviews?.length &&
!codeReviews?.userAuthoredCodeReviews?.length
) {
window.showInformationMessage('Pullflow: You have no PRs waiting for you.')
return
}

const activePullRequestItems = ActivePullRequestItems.get(codeReviews)

QuickPick.create({
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import { ActivePullRequests } from './commands/activePullRequests'
import { Authorization } from './utils/authorization'
import { ToggleFlowState } from './commands/toggleFlowState'
import { Welcome } from './views/webviews/welcome/welcome'
import { UserPresence } from './userPresence/userPresence'

const module = 'extension.ts'

export async function activate(context: ExtensionContext) {
log.info('activating extension', module)

checkFirstActivation(context)
await UserPresence.resetState(context)

const statusBar: StatusBarItem = await StatusBar.activate(context)
const { pollIntervalId, focusStateEvent, presenceInterval } =
Expand Down
122 changes: 122 additions & 0 deletions src/pullRequestQuickActions/pullRequestQuickActions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { describe, expect, it, jest } from '@jest/globals'
import { window } from '../__mocks__/vscode'

describe('Pull Request Quick Actions', () => {
beforeEach(() => {
jest.resetAllMocks()
mockAuthorization.Authorization.currentSession.mockReturnValue(mockSession)
})
it('applies labels to pull request', async () => {
const mockLabel = 'mock_label'
window.showInputBox.mockReturnValue(mockLabel)
await subject().applyLabel({
codeReview: mockModel,
context: mockModel,
statusBar: mockStatusBar,
})
expect(mockPresence.Presence.set).toBeCalled()
expect(mockPullRequestState.PullRequestState.updateWithDelay).toBeCalled()
})

it('approves pull request', async () => {
const mockText = 'mock_approve'
window.showInputBox.mockReturnValue(mockText)
await subject().approve({
codeReview: mockModel,
context: mockModel,
statusBar: mockStatusBar,
})
expect(
mockPullRequestQuickActionsApi.PullRequestQuickActionsApi.approve
).toHaveBeenCalledWith({
body: mockText,
codeReviewId: mockModel.id,
authToken: mockSession.accessToken,
context: mockModel,
})
expect(mockPresence.Presence.set).toBeCalled()
expect(mockPullRequestState.PullRequestState.updateWithDelay).toBeCalled()
})

it('adds assignee to pull request', async () => {
await subject().addAssignee({
codeReview: mockModel,
context: mockModel,
statusBar: mockStatusBar,
})
expect(mockSpaceUserPicker.spaceUserPicker).toBeCalledWith(
expect.objectContaining({
context: mockModel,
placeholder: 'Select a user',
title: 'Add assignee to pull request',
})
)
expect(mockPresence.Presence.set).toBeCalled()
expect(mockPullRequestState.PullRequestState.updateWithDelay).toBeCalled()
})

it('adds reviewer on pull request', async () => {
await subject().requestReview({
codeReview: mockModel,
context: mockModel,
statusBar: mockStatusBar,
})
expect(mockSpaceUserPicker.spaceUserPicker).toBeCalledWith(
expect.objectContaining({
context: mockModel,
placeholder: 'Select a user',
title: 'Add reviewer to pull request',
})
)
expect(mockPresence.Presence.set).toBeCalled()
expect(mockPullRequestState.PullRequestState.updateWithDelay).toBeCalled()
})
})

export {}
const subject = () => {
jest.mock('../utils/authorization', () => mockAuthorization)
jest.mock(
'../api/pullRequestQuickActionsApi',
() => mockPullRequestQuickActionsApi
)
jest.mock('../models/presence', () => mockPresence)
jest.mock('../utils/pullRequestsState', () => mockPullRequestState)
jest.mock('../views/quickpicks/spaceUserPicker', () => mockSpaceUserPicker)
return require('./pullRequestQuickActions').PullRequestQuickActions
}

const mockAuthorization = {
Authorization: {
currentSession: jest.fn(),
},
}
const mockPullRequestQuickActionsApi = {
PullRequestQuickActionsApi: {
addLabels: jest.fn(),
approve: jest.fn(),
},
}
const mockPresence = {
Presence: {
set: jest.fn(),
},
}
const mockPullRequestState = {
PullRequestState: {
update: jest.fn(),
updateWithDelay: jest.fn(),
},
}
const mockSpaceUserPicker = {
spaceUserPicker: jest.fn(),
}
const mockStatusBar = {
text: 'mock_status_bar',
}
const mockModel = {
id: '1',
}
const mockSession = {
accessToken: 'mock_access_token',
}
38 changes: 18 additions & 20 deletions src/pullRequestQuickActions/pullRequestQuickActions.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import { ExtensionContext, window, StatusBarItem } from 'vscode'
import {
CodeReviewSelectionItem,
PresenceStatus,
StatusBarState,
UserCodeReview,
} from '../utils'
import { CodeReviewSelectionItem, PresenceStatus } from '../utils'
import { Authorization } from '../utils/authorization'
import { PullRequestQuickActionsApi } from '../api/pullRequestQuickActionsApi'
import { spaceUserPicker } from '../views/quickpicks/spaceUserPicker'
import { Presence } from '../models/presence'
import { Store } from '../utils/store'
import { StatusBar } from '../views/statusBar/statusBar'
import { TimeSelectionItem, timePicker } from '../views/quickpicks/timePicker'
import moment = require('moment')
import { PullRequestState } from '../utils/pullRequestsState'
Expand Down Expand Up @@ -59,6 +52,11 @@ export const PullRequestQuickActions = {
context,
statusBar,
})

PullRequestState.updateWithDelay({
context,
statusBar,
})
return true
},

Expand Down Expand Up @@ -103,19 +101,9 @@ export const PullRequestQuickActions = {
statusBar,
})

// removing from pending PRs
const pendingUserCodeReviews = Store.get(
context
)?.pendingUserCodeReviews?.filter((pr) => pr.id !== codeReview.id) as [
UserCodeReview
]
await Store.set(context, {
pendingUserCodeReviews,
})
StatusBar.update({
PullRequestState.updateWithDelay({
context,
statusBar,
state: StatusBarState.SignedIn,
})

return true
Expand Down Expand Up @@ -163,6 +151,11 @@ export const PullRequestQuickActions = {
context,
statusBar,
})

PullRequestState.updateWithDelay({
context,
statusBar,
})
},

requestReview: async ({
Expand Down Expand Up @@ -211,6 +204,11 @@ export const PullRequestQuickActions = {
context,
statusBar,
})

PullRequestState.updateWithDelay({
context,
statusBar,
})
},

refresh: async ({
Expand Down Expand Up @@ -242,7 +240,7 @@ export const PullRequestQuickActions = {
await PullRequestState.update({
context,
statusBar,
isLogin: true,
showLoading: true,
errorCount: { count: 0 },
}) // refetch pull requests

Expand Down
2 changes: 1 addition & 1 deletion src/userPresence/trackUserPresence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Store } from '../utils/store'
import { UserPresence } from './userPresence'
import { log } from '../utils/logger'

const USER_FLOW_INTERVAL = 1000 * 60 * 2 // 2 minutes
const USER_FLOW_INTERVAL = 2 * 60 * 1000 // 2 minutes
const module = 'TrackUserFlow.ts'

export const trackUserPresence = (
Expand Down
31 changes: 24 additions & 7 deletions src/userPresence/userPresence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,56 @@ export const UserPresence = {
if (currentKeyStrokeCount) {
// if the user has typed enough keys and was not in flow before
if (currentKeyStrokeCount >= KEY_STROKE_COUNT) {
await Store.set(context, {
previousPresenceStatus: PresenceStatus.Flow,
keyStrokeCount: 0,
})
await Presence.set({
status: PresenceStatus.Flow,
context,
statusBar,
})
await Store.set(context, {
previousPresenceStatus: PresenceStatus.Flow,
})
return
}
}

const timeSinceLastKeyStroke =
new Date().getTime() - (lastKeyStrokeTime || 0)

// if user has not typed anything in a while and was not active before
// if user has not typed anything in a while
if (timeSinceLastKeyStroke > KEY_STROKE_INTERVAL) {
await Store.set(context, { keyStrokeCount: 0 })
if (isFocused && lastFocusedTime) {
const timeSinceLastFocus = new Date().getTime() - lastFocusedTime
// if user has been in focused mode for a while
if (timeSinceLastFocus > FOCUS_INTERVAL) {
await Store.set(context, {
previousPresenceStatus: PresenceStatus.Active,
})
await Presence.set({
status: PresenceStatus.Active,
context,
statusBar,
})
await Store.set(context, {
previousPresenceStatus: PresenceStatus.Active,
})
return
}
}
}
await Store.set(context, {
previousPresenceStatus: PresenceStatus.Inactive,
})
await Presence.set({
status: PresenceStatus.Inactive,
context,
statusBar,
})
},

resetState: async (context: ExtensionContext) => {
await Store.set(context, {
lastFocusedTime: 0,
keyStrokeCount: 0,
lastKeyStrokeTime: 0,
})
},
}
2 changes: 1 addition & 1 deletion src/utils/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const initialize = async ({
await PullRequestState.update({
context,
statusBar,
isLogin: true,
showLoading: true,
errorCount,
})
await setSpaceUsers({ context, statusBar })
Expand Down
Loading

0 comments on commit b3b3d6b

Please sign in to comment.