Skip to content

Add handling for unintended header matches #11

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

Merged
merged 1 commit into from
Feb 13, 2025
Merged

Add handling for unintended header matches #11

merged 1 commit into from
Feb 13, 2025

Conversation

ncalteen
Copy link
Collaborator

This PR adds special handling for cases like the one mentioned in issue-ops/parser#102

In some situations, a user's issue form input could include markdown. If the provided value contains a match for the regex used to locate form field responses, it was mistakenly added as a separate field response.

This solution combines any such matches with the previous match, resulting in only the parsed values being those corresponding to fields in the form template. However, it is only applied in cases where a template is included in the parseIssue call.

@ncalteen ncalteen self-assigned this Feb 13, 2025
@Copilot Copilot AI review requested due to automatic review settings February 13, 2025 19:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This pull request enhances the parsing logic for GitHub issue bodies by combining unexpected header matches with the previous field when a form template is provided. In addition, the PR updates test cases and fixtures to reflect the new handling and accommodates various field formats in the template.

  • Moved the regex matching logic and handling of extra headers inside parseIssue.
  • Introduced logic to merge unmatched header sections with the preceding field’s value.
  • Updated fixtures (YAML and Markdown) with revised field IDs and labels.
  • Adjusted tests to cover multiple scenarios including issues with and without a provided template.

Changes

File Description
src/index.ts Refactored parseIssue to incorporate combining of extra header matches when a template is provided.
fixtures/extra/template.yml Updated field definitions and labels to support new parsing behavior.
fixtures/extra/issue.md Adjusted header texts to match updated template definitions.
tests/index.test.ts Rearranged and renamed tests to reflect scenarios with/without templates and with slugified keys.
src/format.ts Made the field parameter optional in formatValue to support changes in parseIssue.

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/index.ts:72

  • Appending the full match (match[0]) may include the header markdown, potentially leading to duplicated header text in the field value. Consider appending only the value portion (e.g., match.groups!.value) or adjust the regex capture so that only the intended content is merged.
parsedMatches[parsedMatches.length - 1].groups!.value = parsedMatches[parsedMatches.length - 1].groups!.value + '\n' + match[0]

fixtures/extra/template.yml:148

  • [nitpick] For consistency with the other checkbox option labels, consider quoting the label 'Sometimes'. This will help avoid potential parsing inconsistencies and improve readability.
- label: Sometimes

Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more

Copy link

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ ACTION actionlint 5 0 0.07s
✅ JSON jsonlint 23 0 0.31s
✅ JSON npm-package-json-lint yes no 0.9s
✅ JSON prettier 23 0 1.09s
✅ JSON v8r 23 0 7.99s
✅ MARKDOWN markdownlint 1 0 0.91s
✅ MARKDOWN markdown-link-check 9 0 3.11s
✅ REPOSITORY checkov yes no 18.08s
✅ REPOSITORY gitleaks yes no 2.33s
✅ REPOSITORY git_diff yes no 0.01s
✅ REPOSITORY grype yes no 17.44s
✅ REPOSITORY secretlint yes no 0.95s
✅ REPOSITORY trivy-sbom yes no 1.18s
✅ REPOSITORY trufflehog yes no 12.3s
✅ TYPESCRIPT prettier 8 0 0.79s
✅ YAML prettier 18 0 0.61s
✅ YAML v8r 18 0 5.6s
✅ YAML yamllint 18 0 0.38s

See detailed report in MegaLinter reports

MegaLinter is graciously provided by OX Security

@ncalteen ncalteen merged commit a34a413 into main Feb 13, 2025
7 checks passed
@ncalteen ncalteen deleted the ncalteen/md branch March 3, 2025 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant