Skip to content

Fix logic to find start index for H3 headers in issue forms#58

Merged
edumserrano merged 1 commit intomainfrom
h3-matching
Jul 17, 2023
Merged

Fix logic to find start index for H3 headers in issue forms#58
edumserrano merged 1 commit intomainfrom
h3-matching

Conversation

@edumserrano
Copy link
Owner

@edumserrano edumserrano commented Jul 17, 2023

The previous logic to find the start index of an H3 header used string.IndexOf to find the first occurrence of the header value. The problem with this is that if the GitHub issue template contains labels that start with the same value then this logic will fail to properly identify all the the H3 headers.

Consider this GitHub issue form template:

name: Release NuGet package
description: Release a NuGet package.
title: Release NuGet package
body:
  - type: dropdown
    id: nuget-id
    attributes:
      label: What NuGet package do you want to release?
      options:
        - dotnet-sdk-extensions
        - dotnet-sdk-extensions-testing
    validations:
      required: true
  - type: dropdown
    id: nuget-id-2
    attributes:
      label: What
      options:
        - dotnet-sdk-extensions
        - dotnet-sdk-extensions-testing
    validations:
      required: true

When a GitHub issue is created using the above template then the app would fail to parse the value for the label with id nuget-id-2 because it would do <github issue body>.indexOf("### What") and it would return the index for the label with id nuget-id because it also starts with ### What.

To fix this we still use string.IndexOf but we match on an entire line, meaning it has to have the header value followed by a new line character.

@codecov
Copy link

codecov bot commented Jul 17, 2023

Codecov Report

Merging #58 (3fdeedb) into main (927ad66) will increase coverage by 0.26%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #58      +/-   ##
==========================================
+ Coverage   91.22%   91.48%   +0.26%     
==========================================
  Files          27       27              
  Lines         262      270       +8     
  Branches       23       24       +1     
==========================================
+ Hits          239      247       +8     
  Misses         17       17              
  Partials        6        6              
Impacted Files Coverage Δ
...erCli/IssueFormBody/Parsing/IssueFormBodyParser.cs 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@edumserrano edumserrano merged commit ed7b4c5 into main Jul 17, 2023
@edumserrano edumserrano deleted the h3-matching branch July 17, 2023 23:30
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