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

Feature: Set reminders on Pull requests #10

Merged
merged 5 commits into from
Nov 14, 2023
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.0.1",
"version": "1.1.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.0.1",
"version": "1.1.0",
"preview": true,
"license": "MIT",
"engines": {
Expand Down
35 changes: 35 additions & 0 deletions src/api/pullRequestQuickActionsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ const REQUEST_REVIEW = `
}
`

const SET_REMINDER = `
mutation setCodeReviewReminder($codeReviewId: String!, $duration: Int!) {
setCodeReviewReminder(codeReviewId: $codeReviewId, duration: $duration) {
success
message
}
}
`

export const PullRequestQuickActionsApi = {
addLabels: async ({
authToken,
Expand Down Expand Up @@ -149,4 +158,30 @@ export const PullRequestQuickActionsApi = {
return { error }
}
},

setReminder: async ({
duration,
codeReviewId,
authToken,
context,
}: {
duration: number
codeReviewId: string
authToken: string
context: ExtensionContext
}) => {
log.info(`setting reminder: ${{ duration, codeReviewId }}}`, module)

const pullflowApi = new PullflowApi(context, authToken)
try {
const data = await pullflowApi.fetch(SET_REMINDER, {
codeReviewId,
duration,
})
return data.setCodeReviewReminder
} catch (error) {
log.error(`error in requesting review, ${error}`, module)
return { error }
}
},
}
35 changes: 35 additions & 0 deletions src/pullRequestQuickActions/pullRequestQuickActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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')

export const PullRequestQuickActions = {
applyLabel: async ({
Expand Down Expand Up @@ -209,4 +211,37 @@ export const PullRequestQuickActions = {
statusBar,
})
},
setReminder: ({
codeReview,
context,
}: {
codeReview: CodeReviewSelectionItem
context: ExtensionContext
}) => {
const onDidChangeSelection = async (item: readonly TimeSelectionItem[]) => {
if (!item[0]?.label) return false
const selectedTime = item[0]
const session = await Authorization.currentSession(context)
const duration = computeTime(selectedTime.value)
const response = await PullRequestQuickActionsApi.setReminder({
codeReviewId: codeReview.id,
duration,
authToken: session?.accessToken ?? '',
context,
})
if (response.message || response.error || !response.success) {
window.showInformationMessage(
'Something went wrong, failed to set reminder'
)
return false
}
window.showInformationMessage(`Pullflow: Successfully set reminder.`)
return true
}

timePicker({ title: 'Remind me in', onDidChangeSelection })
},
}

const computeTime = (minutes: number) =>
Math.floor(moment().add(minutes, 'minutes').valueOf() / 1000)
10 changes: 10 additions & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export interface ReviewerSelectionItem extends QuickPickItem {
hasUser: boolean
xid: string
}
export interface SpaceUserSelectionItem extends QuickPickItem {
label: string
description: string
}
export enum CodeReviewType {
Pending,
Authored,
Expand All @@ -89,6 +93,7 @@ export enum ActivePullRequestActions {
ApplyLabel = 'Add label',
AddAssignee = 'Add assignee',
RequestReview = 'Add reviewer',
SetReminder = 'Set a reminder',
}
export type SpaceUser = {
id: string
Expand All @@ -112,6 +117,7 @@ export type ApiVariables =
| AddAssigneeVariables
| RequestReviewVariables
| CodeReviewApproveVariables
| CodeReviewRemindersVariables
export type ThreadMessageVariables = {
body: string
parentMessageXid: string
Expand Down Expand Up @@ -149,6 +155,10 @@ export type CodeReviewApproveVariables = {
codeReviewId: string
body?: string
}
export type CodeReviewRemindersVariables = {
codeReviewId: string
duration: number
}
export type RepoInfo = {
repoName?: string
branch?: string
Expand Down
1 change: 1 addition & 0 deletions src/views/quickpicks/pullRequestActionPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const getActionItems = (type: CodeReviewType) => [
{
label: ActivePullRequestActions.RequestReview,
},
{ label: ActivePullRequestActions.SetReminder },
]

export const pullRequestActionPicker = ({
Expand Down
8 changes: 4 additions & 4 deletions src/views/quickpicks/quickPick.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { QuickPickItem, window } from 'vscode'

export const QuickPick = {
create: ({
create: <Type extends QuickPickItem>({
items,
title,
placeholder,
onDidChangeSelection,
}: {
items: QuickPickItem[]
items: Type[]
title: string
placeholder: string
onDidChangeSelection: (selection: readonly QuickPickItem[]) => void
onDidChangeSelection: (selection: readonly Type[]) => void
}) => {
const quickPick = window.createQuickPick()
const quickPick = window.createQuickPick<Type>()
quickPick.items = items
quickPick.title = title
quickPick.placeholder = placeholder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ export const pullRequestActionHandler = async ({
statusBar,
})
}
if (selectedItem?.label === ActivePullRequestActions.SetReminder) {
await PullRequestQuickActions.setReminder({
codeReview: codeReviewItem,
context,
})
}
}

const openLink = (link: string) => env.openExternal(Uri.parse(link))
6 changes: 4 additions & 2 deletions src/views/quickpicks/spaceUserPicker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExtensionContext, window } from 'vscode'
import { Store } from '../../utils/store'
import { SpaceUser } from '../../utils'
import { SpaceUser, SpaceUserSelectionItem } from '../../utils'
import { QuickPick } from './quickPick'

export const spaceUserPicker = ({
Expand All @@ -12,7 +12,9 @@ export const spaceUserPicker = ({
context: ExtensionContext
placeholder: string
title: string
onDidChangeSelection: (item: any) => Promise<boolean>
onDidChangeSelection: (
item: readonly SpaceUserSelectionItem[]
) => Promise<boolean>
}) => {
const spaceUsers = Store.get(context)?.spaceUsers
if (!spaceUsers) {
Expand Down
41 changes: 41 additions & 0 deletions src/views/quickpicks/timePicker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { QuickPickItem } from 'vscode'
import { QuickPick } from './quickPick'

export interface TimeSelectionItem extends QuickPickItem {
value: number
}
export const TimeIntervals: TimeSelectionItem[] = [
{
label: '30 minutes',
value: 30,
},
{
label: '45 minutes',
value: 45,
},
{
label: '1 hour',
value: 60,
},
{
label: '2 hours',
value: 120,
},
]

export const timePicker = ({
title,
onDidChangeSelection,
}: {
title: string
onDidChangeSelection: (
selection: readonly TimeSelectionItem[]
) => Promise<Boolean>
}) => {
QuickPick.create({
items: TimeIntervals,
title,
placeholder: 'Choose time interval',
onDidChangeSelection,
})
}
Loading