@@ -33557,80 +33557,16 @@ var EmptyResponse;
3355733557 /** None */
3355833558 EmptyResponse["NONE"] = "None";
3355933559})(EmptyResponse || (EmptyResponse = {}));
33560-
33561- /**
33562- * Checks if a response is empty (it is either empty or contains one of the
33563- * "empty" strings used in issue form responses).
33564- *
33565- * @param value Value to Check
33566- */
33567- function isEmptyResponse(value) {
33568- return (value.toLowerCase() === EmptyResponse.NONE.toLowerCase() ||
33569- value.toLowerCase() === EmptyResponse.NO_RESPONSE.toLowerCase() ||
33570- value === '');
33571- }
33572- /**
33573- * Formats an input name to a slugified string.
33574- *
33575- * @param name Name to Format
33576- */
33577- function formatKey(name) {
33578- return name
33579- .trim()
33580- .toLowerCase()
33581- .replace(/[^a-z0-9]/g, '_')
33582- .replace(/^_+|_+$/g, '')
33583- .replace(/_+/g, '_');
33584- }
3358533560/**
3358633561 * Formats an input value to an appropriate type
3358733562 */
3358833563function formatValue(input, field) {
33589- // Regex to check if a checkbox is checked.
33590- const checkedExp = /^-\s\[x\]\s/im;
3359133564 // Remove any whitespace, carriage returns, and leading/trailing newlines.
3359233565 const value = input
3359333566 .trim()
3359433567 .replace(/\r/g, '')
3359533568 .replace(/^[\n]+|[\n]+$/g, '');
33596- if (field === undefined)
33597- return value;
33598- // Parse input field types.
33599- switch (field.type) {
33600- case FieldType.INPUT:
33601- case FieldType.TEXTAREA:
33602- // Return empty string if no response was provided. Otherwise, return the
33603- // formatted response.
33604- return isEmptyResponse(value) ? undefined : value;
33605- case FieldType.DROPDOWN:
33606- // Return empty list if no response was provided. Otherwise, split by
33607- // commas and return the list.
33608- return isEmptyResponse(value) ? [] : value.split(/, */);
33609- case FieldType.CHECKBOXES: {
33610- // Return empty object if no response was provided. Otherwise, verify
33611- // which checkboxes are checked and return the object.
33612- const checkboxes = {
33613- selected: [],
33614- unselected: []
33615- };
33616- // Return empty object if no response was provided
33617- if (isEmptyResponse(value))
33618- return checkboxes;
33619- // Split response by newlines.
33620- for (let line of value.split('\n')) {
33621- line = line.trim();
33622- // Add checked items to selected.
33623- if (checkedExp.test(line))
33624- checkboxes.selected.push(line.replace(/-\s\[x\]\s/i, ''));
33625- // Add unchecked items to unselected.
33626- else
33627- checkboxes.unselected.push(line.replace(/-\s\[\s\]\s/i, ''));
33628- }
33629- return checkboxes;
33630- }
33631- default:
33632- throw new Error(`Unknown field type: ${field.type}`);
33633- }
33569+ return value;
3363433570}
3363533571
3363633572/**
@@ -33645,46 +33581,29 @@ function formatValue(input, field) {
3364533581 * @returns Parsed Issue Body
3364633582 */
3364733583function parseIssue(issue, template, options) {
33648- const parsedTemplate = parseTemplate();
33649- const parsedIssue = {};
3365033584 // Match the sections of the issue body
3365133585 const regexp = /### *(?<key>.*?)\s*[\r\n]+(?<value>[\s\S]*?)(?=\n?###|\n?$)/g;
3365233586 const matches = issue.matchAll(regexp);
33653- for (const match of matches) {
33654- let value = match.groups?.value || undefined;
33655- let key = match.groups?.key || '';
33656- // Skip malformed sections
33657- if (key === undefined || key === '' || value === undefined || value === '')
33658- continue;
33659- // If the form template was provided, use the key from there instead of the
33660- // heading in the issue body.
33661- for (const [k, v] of Object.entries(parsedTemplate)) {
33662- if (formatKey(v.label) === key || v.label === key) {
33663- key = k;
33664- break;
33665- }
33587+ // Create an empty dictionary to store the parsed issue body.
33588+ const parsedIssue = {};
33589+ {
33590+ // No template was provided. Use the field header text as the key.
33591+ for (const match of matches) {
33592+ /* istanbul ignore if */
33593+ if (match.groups?.key === undefined ||
33594+ match.groups?.value === undefined ||
33595+ match.groups?.key === '' ||
33596+ match.groups?.value === '')
33597+ continue;
33598+ let key = match.groups.key;
33599+ const value = match.groups.value;
33600+ // Add to the parsed issue body
33601+ parsedIssue[key] = formatValue(value);
3366633602 }
33667- // Format the value (returns null if the value couldn't be parsed)
33668- value = formatValue(value, parsedTemplate[key]);
33669- // Add to the parsed issue body
33670- parsedIssue[key] = value;
3367133603 }
3367233604 // Return the dictionary
3367333605 return parsedIssue;
3367433606}
33675- /**
33676- * Parses an issue form template and returns a dictionary of fields. The
33677- * dictionary is used to match the field types and labels in the issue body. If
33678- * no template is provided, an empty dictionary is returned.
33679- *
33680- * @param template Issue Form Template (YAML String)
33681- * @returns Parsed Issue Form Template
33682- * @throws Error if the template is not valid YAML
33683- */
33684- function parseTemplate(template) {
33685- // If the template was not provided, return an empty object.
33686- return {};
33687- }
3368833607
3368933608var Action;
3369033609(function (Action) {
0 commit comments