Skip to content
Open
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
13 changes: 13 additions & 0 deletions __tests__/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,17 @@ c`
})
).toBe(value)
})

it('Handles upload fields', () => {
const value = `https://github.com/user-attachments/assets/example`

expect(
formatValue(value, {
label: 'Upload Test',
type: 'upload',
required: false,
accept: '.png,.txt'
})
).toBe(value)
})
})
21 changes: 21 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ describe('parseIssue()', () => {
expect(result).toEqual(expected)
})

it('Parses an issue with an upload field', () => {
const issue = `### Upload relevant files\nhttps://github.com/user-attachments/assets/example\n`
const template = `name: Bug report\nbody:\n - type: upload\n id: screenshots\n attributes:\n label: Upload relevant files\n description: Drag and drop relevant screenshots or logs.\n validations:\n required: false\n accept: .png,.txt`

expect(parseIssue(issue, template)).toEqual({
screenshots: 'https://github.com/user-attachments/assets/example'
})
})

it('Parses an issue with extra fields without a template (slugified)', () => {
const issue = fs.readFileSync('__fixtures__/extra/issue.md', 'utf8')

Expand Down Expand Up @@ -154,6 +163,18 @@ describe('parseTemplate()', () => {
expect(result).toEqual(expected)
})

it('Parses a template with upload fields', () => {
expect(
parseTemplate(`name: Bug report\nbody:\n - type: upload\n id: screenshots\n attributes:\n label: Upload relevant files\n description: Drag and drop relevant screenshots or logs.\n validations:\n required: false\n accept: .png,.txt`)
).toEqual({
screenshots: {
label: 'Upload relevant files',
type: 'upload',
required: false
}
})
})

it('Throws if the template is not a valid YAML object', () => {
expect(() => {
parseTemplate('invalid')
Expand Down
3 changes: 3 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export enum FieldType {
/** Markdown Field */
MARKDOWN = 'markdown',
/** Textarea Field */
TEXTAREA = 'textarea'
TEXTAREA = 'textarea',
/** Upload Field */
UPLOAD = 'upload'
}

/** Empty Issue Form Responses */
Expand Down
1 change: 1 addition & 0 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function formatValue(
switch (field.type) {
case FieldType.INPUT:
case FieldType.TEXTAREA:
case FieldType.UPLOAD:
// Return empty string if no response was provided. Otherwise, return the
// formatted response.
return isEmptyResponse(value) ? undefined : value
Expand Down
27 changes: 21 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ export type IssueFormTemplate = {
name: string
description: string
body: (
| MarkdownField
| TextareaField
| InputField
| DropdownField
| CheckboxesField
| MarkdownField
| TextareaField
| InputField
| DropdownField
| CheckboxesField
| UploadField
)[]
assignees?: string[]
labels?: string[]
Expand Down Expand Up @@ -88,11 +89,25 @@ export interface CheckboxesField {
}
}

/** GitHub Issue Forms Upload Field */
export interface UploadField {
type: 'upload'
id?: string
attributes: {
label: string
description?: string
}
validations?: {
required?: boolean
accept?: string
}
}

/** Formatted GitHub Issue Forms Field */
export interface FormattedField {
id?: string
label: string
type: 'markdown' | 'textarea' | 'input' | 'dropdown' | 'checkboxes'
type: 'markdown' | 'textarea' | 'input' | 'dropdown' | 'checkboxes' | 'upload'
required: boolean
multiple?: boolean
options?: (
Expand Down