quickCreateHelpers.tsā¢5.59 kB
import type { CreateStoryParams } from './shortcut-types'
import { CUSTOM_FIELDS, COMMON_LABELS, STORY_TEMPLATES, COMMON_EPICS } from './shortcutHelpers'
export interface QuickBugParams {
title: string
description?: string
priority?: 'Highest' | 'Medium' | 'Low'
dashboardLinks?: string[]
orgIds?: string[]
loomUrl?: string
currentBehavior?: string
expectedBehavior?: string
stepsToReproduce?: string[]
project_id: number
owner_ids?: string[]
requested_by_id?: string
}
export interface QuickFeatureParams {
title: string
description?: string
project_id: number
epic_id?: number
owner_ids?: string[]
requested_by_id?: string
estimate?: number
}
/**
* Create a bug story with all the standard fields and formatting
*/
export function createBugStoryParams(params: QuickBugParams): CreateStoryParams {
// Build the bug description from template
let description = ''
if (params.description || params.dashboardLinks || params.orgIds || params.loomUrl ||
params.currentBehavior || params.expectedBehavior || params.stepsToReproduce) {
description = `# REPORTER:
### Please give a detailed description of the issue, and supply all user/membership/class IDs where necessary:
`
if (params.dashboardLinks && params.dashboardLinks.length > 0) {
description += `**Dashboard Link(s):** ${params.dashboardLinks.join(', ')}\n`
}
if (params.orgIds && params.orgIds.length > 0) {
description += `**Org ID(s):** ${params.orgIds.join(', ')}\n`
}
description += `
**Current behavior:** What is currently happening?
${params.currentBehavior || params.description || '[Describe the issue here]'}
**Expected behavior:** What is expected?
${params.expectedBehavior || '[Describe expected behavior]'}
**Steps to reproduce:** How can the team reproduce this issue? Share exact steps and device to use
`
if (params.stepsToReproduce && params.stepsToReproduce.length > 0) {
params.stepsToReproduce.forEach((step, index) => {
description += `${index + 1}. ${step}\n`
})
} else {
description += `1. [Step 1]
2. [Step 2]
3. [Step 3]
`
}
if (params.loomUrl) {
description += `\n**Loom:** ${params.loomUrl}\n`
}
description += `
.
.
.
# ON CALL DEV:
**Code Area:**
**Complexity:** High / Medium / Low
**Fix LOE:** High = Multiple Days / Medium = 1 Day / Low = Less than 1 Day
**Investigation Result:** What did you learn?
**Implementation Plan:** If you know how to fix it, what should we do?`
}
// Determine priority value
let priorityValue = CUSTOM_FIELDS.PRIORITY.VALUES.MEDIUM
if (params.priority === 'Highest') {
priorityValue = CUSTOM_FIELDS.PRIORITY.VALUES.HIGHEST
} else if (params.priority === 'Low') {
priorityValue = CUSTOM_FIELDS.PRIORITY.VALUES.LOW
}
// Calculate deadline (next business day)
const deadline = new Date()
deadline.setDate(deadline.getDate() + 1)
if (deadline.getDay() === 0) deadline.setDate(deadline.getDate() + 1) // Sunday -> Monday
if (deadline.getDay() === 6) deadline.setDate(deadline.getDate() + 2) // Saturday -> Monday
// Build the story params
const storyParams: CreateStoryParams = {
name: `š ${params.title}`,
story_type: 'bug',
project_id: params.project_id,
description: description || params.description,
epic_id: COMMON_EPICS.BUGS,
story_template_id: STORY_TEMPLATES.BUG_REPORT,
labels: [{ name: COMMON_LABELS.BUG_INVESTIGATE }],
custom_fields: [{
field_id: CUSTOM_FIELDS.PRIORITY.FIELD_ID,
value_id: priorityValue,
}],
deadline: deadline.toISOString().split('T')[0] + 'T07:00:00Z',
}
// Add optional fields
if (params.owner_ids) storyParams.owner_ids = params.owner_ids
if (params.requested_by_id) storyParams.requested_by_id = params.requested_by_id
// Add additional labels based on content
const content = `${params.title} ${description}`.toLowerCase()
if (content.includes('kiosk')) {
storyParams.labels!.push({ name: COMMON_LABELS.KIOSK })
}
if (content.includes('audience')) {
storyParams.labels!.push({ name: COMMON_LABELS.AUDIENCE })
}
if (content.includes('tag')) {
storyParams.labels!.push({ name: COMMON_LABELS.TAG })
}
if (content.includes('intercom') || content.includes('customer') || content.includes('partner')) {
storyParams.labels!.push({ name: COMMON_LABELS.INTERCOM })
}
// Add external links if we have loom URL
if (params.loomUrl) {
storyParams.external_links = [params.loomUrl]
}
return storyParams
}
/**
* Create a feature story with standard fields
*/
export function createFeatureStoryParams(params: QuickFeatureParams): CreateStoryParams {
const storyParams: CreateStoryParams = {
name: params.title,
story_type: 'feature',
project_id: params.project_id,
description: params.description,
}
// Add optional fields
if (params.epic_id) storyParams.epic_id = params.epic_id
if (params.owner_ids) storyParams.owner_ids = params.owner_ids
if (params.requested_by_id) storyParams.requested_by_id = params.requested_by_id
if (params.estimate) storyParams.estimate = params.estimate
return storyParams
}