diff --git a/__tests__/format.test.ts b/__tests__/format.test.ts index 70ae7c5..4606864 100644 --- a/__tests__/format.test.ts +++ b/__tests__/format.test.ts @@ -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) + }) }) diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index 6d6daf5..85e9be3 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -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') @@ -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') diff --git a/dist/index.js b/dist/index.js index 145de4b..4f8262a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7452,6 +7452,8 @@ var FieldType; FieldType["MARKDOWN"] = "markdown"; /** Textarea Field */ FieldType["TEXTAREA"] = "textarea"; + /** Upload Field */ + FieldType["UPLOAD"] = "upload"; })(FieldType || (FieldType = {})); /** Empty Issue Form Responses */ var EmptyResponse; @@ -7503,6 +7505,7 @@ function formatValue(input, field) { 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; diff --git a/src/enums.ts b/src/enums.ts index a64a867..d2642f9 100644 --- a/src/enums.ts +++ b/src/enums.ts @@ -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 */ diff --git a/src/format.ts b/src/format.ts index c7d45cb..c50a16c 100644 --- a/src/format.ts +++ b/src/format.ts @@ -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 diff --git a/src/types.ts b/src/types.ts index e7f43b9..e06661a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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[] @@ -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?: (