Skip to content

Commit 3ee2b7d

Browse files
committed
Make step fail if parsing fails and fix usage of "form" vs "forms"
1 parent 00be6fd commit 3ee2b7d

File tree

11 files changed

+52
-46
lines changed

11 files changed

+52
-46
lines changed

GitHubIssueFormsParser/src/GitHubIssuesParserCli/CliCommands/ParseGitHubIssueFormCommandException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace GitHubIssuesParserCli.CliCommands;
22

33
public class ParseGitHubIssueFormCommandException : Exception
44
{
5-
private const string _errorMessage = "An error occurred trying to execute the command to parse a GitHub issue forms. See inner exception for more details.";
5+
private const string _errorMessage = "An error occurred trying to execute the command to parse a GitHub issue form. See inner exception for more details.";
66

77
public ParseGitHubIssueFormCommandException(Exception innerException)
88
: base(_errorMessage, innerException)

GitHubIssueFormsParser/src/GitHubIssuesParserCli/CliCommands/ParseIssueFormCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ namespace GitHubIssuesParserCli.CliCommands;
33
[Command("parse-issue-form")]
44
public class ParseIssueFormCommand : ICommand
55
{
6-
[CommandOption("issue-body", 'i', Description = "The body of the GitHub issue forms.")]
6+
[CommandOption("issue-body", 'i', Description = "The body of the GitHub issue form.")]
77
public string? IssueFormBody { get; init; }
88

9-
[CommandOption("template-filepath", 't', Description = "The filepath for the GitHub issue forms YAML template.")]
9+
[CommandOption("template-filepath", 't', Description = "The filepath for the GitHub issue form YAML template.")]
1010
public string? TemplateFilepath { get; init; }
1111

1212
public async ValueTask ExecuteAsync(IConsole console)

GitHubIssueFormsParser/src/GitHubIssuesParserCli/IssueFormBody/Parsing/IssueFormBodyParserException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private IssueFormBodyParserException(string message)
99

1010
internal static IssueFormBodyParserException H3HeaderNotFound(string h3Header)
1111
{
12-
var message = $"H3 header value '{h3Header}' not found in issue forms body.";
12+
var message = $"H3 header value '{h3Header}' not found in issue form body.";
1313
return new IssueFormBodyParserException(message);
1414
}
1515

GitHubIssueFormsParser/src/GitHubIssuesParserCli/IssueFormTemplates/Parsing/IssueFormYamlTemplateParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public static IssueFormYamlTemplate Parse(IssueFormYamlTemplateText yamlTemplate
1414
throw IssueFormYamlTemplateParserException.InvalidYmlTemplate();
1515
}
1616

17-
// markdown template item types do NOT show in the issue forms body, they are only used
17+
// markdown template item types do NOT show in the issue form body, they are only used
1818
// to show some markdown text when creating the issue. Excluding them here so that we
19-
// only get the issue forms template items that will be rendered on the issue forms body
19+
// only get the issue form template items that will be rendered on the issue form body
2020
var items = templateDto.Body
2121
.Where(x => x.Type is not IssueFormYamlTemplateItemDtoTypes.Markdown)
2222
.Select(x =>

GitHubIssueFormsParser/src/GitHubIssuesParserCli/IssueFormTemplates/Parsing/IssueFormYamlTemplateParserException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private IssueFormYamlTemplateParserException(string message)
99

1010
internal static IssueFormYamlTemplateParserException InvalidYmlTemplate()
1111
{
12-
const string message = "Failed to deserialize the issue forms template. The template must contain at least an YAML member named 'body' at the first indentation level.";
12+
const string message = "Failed to deserialize the issue form template. The template must contain at least an YAML member named 'body' at the first indentation level.";
1313
return new IssueFormYamlTemplateParserException(message);
1414
}
1515

GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliCommands/ParseIssueFormCommandValidationTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public async Task ValidateIssueFormBodyParam(string? issueFormBody)
1818
TemplateFilepath = "./some/file/path.txt",
1919
};
2020
var exception = await Should.ThrowAsync<ParseGitHubIssueFormCommandException>(() => command.ExecuteAsync(console).AsTask());
21-
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue forms. See inner exception for more details.");
21+
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue form. See inner exception for more details.");
2222
exception.InnerException.ShouldNotBeNull();
2323
exception.InnerException.ShouldBeAssignableTo<ArgumentException>();
2424
exception.InnerException.Message.ShouldBe("IssueFormBody cannot be null or whitespace.");
@@ -35,11 +35,11 @@ public async Task ValidateTemplateFilepathParam(string? templateFilepath)
3535
using var console = new FakeInMemoryConsole();
3636
var command = new ParseIssueFormCommand
3737
{
38-
IssueFormBody = "some issue forms body",
38+
IssueFormBody = "some issue form body",
3939
TemplateFilepath = templateFilepath,
4040
};
4141
var exception = await Should.ThrowAsync<ParseGitHubIssueFormCommandException>(() => command.ExecuteAsync(console).AsTask());
42-
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue forms. See inner exception for more details.");
42+
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue form. See inner exception for more details.");
4343
exception.InnerException.ShouldNotBeNull();
4444
exception.InnerException.ShouldBeAssignableTo<ArgumentException>();
4545
exception.InnerException.Message.ShouldBe("TemplateFilepath cannot be null or whitespace.");
@@ -55,11 +55,11 @@ public async Task TemplateFilepathNotFound()
5555
using var console = new FakeInMemoryConsole();
5656
var command = new ParseIssueFormCommand
5757
{
58-
IssueFormBody = "some issue forms body",
58+
IssueFormBody = "some issue form body",
5959
TemplateFilepath = "./this/path/does/not/exist.yml",
6060
};
6161
var exception = await Should.ThrowAsync<ParseGitHubIssueFormCommandException>(() => command.ExecuteAsync(console).AsTask());
62-
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue forms. See inner exception for more details.");
62+
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue form. See inner exception for more details.");
6363
exception.InnerException.ShouldNotBeNull();
6464
exception.InnerException.ShouldBeAssignableTo<DirectoryNotFoundException>();
6565
exception.InnerException.Message.ShouldStartWith("Could not find a part of the path");
@@ -75,14 +75,14 @@ public async Task InvalidTemplate()
7575
using var console = new FakeInMemoryConsole();
7676
var command = new ParseIssueFormCommand
7777
{
78-
IssueFormBody = "some issue forms body",
78+
IssueFormBody = "some issue form body",
7979
TemplateFilepath = "./TestFiles/InvalidTemplate.yml",
8080
};
8181
var exception = await Should.ThrowAsync<ParseGitHubIssueFormCommandException>(() => command.ExecuteAsync(console).AsTask());
82-
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue forms. See inner exception for more details.");
82+
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue form. See inner exception for more details.");
8383
exception.InnerException.ShouldNotBeNull();
8484
exception.InnerException.ShouldBeAssignableTo<IssueFormYamlTemplateParserException>();
85-
exception.InnerException.Message.ShouldStartWith("Failed to deserialize the issue forms template. The template must contain at least an YAML member named 'body' at the first indentation level.");
85+
exception.InnerException.Message.ShouldStartWith("Failed to deserialize the issue form template. The template must contain at least an YAML member named 'body' at the first indentation level.");
8686
}
8787

8888
/// <summary>
@@ -99,10 +99,10 @@ public async Task InvalidIssueFormBody()
9999
TemplateFilepath = "./TestFiles/Template.yml",
100100
};
101101
var exception = await Should.ThrowAsync<ParseGitHubIssueFormCommandException>(() => command.ExecuteAsync(console).AsTask());
102-
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue forms. See inner exception for more details.");
102+
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue form. See inner exception for more details.");
103103
exception.InnerException.ShouldNotBeNull();
104104
exception.InnerException.ShouldBeAssignableTo<IssueFormBodyParserException>();
105-
exception.InnerException.Message.ShouldStartWith("H3 header value '### What NuGet package do you want to release?' not found in issue forms body.");
105+
exception.InnerException.Message.ShouldStartWith("H3 header value '### What NuGet package do you want to release?' not found in issue form body.");
106106
}
107107

108108
/// <summary>
@@ -119,7 +119,7 @@ public async Task InvalidIssueFormBody2()
119119
TemplateFilepath = "./TestFiles/Template.yml",
120120
};
121121
var exception = await Should.ThrowAsync<ParseGitHubIssueFormCommandException>(() => command.ExecuteAsync(console).AsTask());
122-
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue forms. See inner exception for more details.");
122+
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue form. See inner exception for more details.");
123123
exception.InnerException.ShouldNotBeNull();
124124
exception.InnerException.ShouldBeAssignableTo<IssueFormBodyParserException>();
125125
exception.InnerException.Message.ShouldStartWith("Failed to obtain the value for H3 header: '### What NuGet package do you want to release?'. Couldn't find any text between that H3 header and the next H3 header: '### What is the new version for the NuGet package?'.");
@@ -139,7 +139,7 @@ public async Task InvalidIssueFormBody3()
139139
TemplateFilepath = "./TestFiles/Template.yml",
140140
};
141141
var exception = await Should.ThrowAsync<ParseGitHubIssueFormCommandException>(() => command.ExecuteAsync(console).AsTask());
142-
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue forms. See inner exception for more details.");
142+
exception.Message.ShouldBe("An error occurred trying to execute the command to parse a GitHub issue form. See inner exception for more details.");
143143
exception.InnerException.ShouldNotBeNull();
144144
exception.InnerException.ShouldBeAssignableTo<IssueFormBodyParserException>();
145145
exception.InnerException.Message.ShouldStartWith("Invalid checkbox option text: '- macOS'.");

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,25 @@ A Docker container [GitHub action](https://docs.github.com/en/actions/learn-gith
3838
3939
| Name | Description
4040
| --- | --- |
41-
| `template-filepath` | The filepath to the [issue forms template](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository#creating-issue-forms). |
41+
| `template-filepath` | The filepath to the [issue form template](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository#creating-issue-forms). |
4242
| `issue-form-body` | The body of the issue to parse. |
4343

4444
### Action outputs
4545

4646
| Name | Description
4747
| --- | --- |
48-
| `parsed-issue` | The issue forms parsed as a JSON string. |
48+
| `parsed-issue` | The issue form parsed as a JSON string. |
4949

5050
**Notes about the JSON output:**
5151

5252
- The keys on the JSON object are id field of the template form element.
5353
- Checkboxes form elements are outputed as an object whose keys are the [slugified]((https://blog.tersmitten.nl/slugify/)) value of the label of the option.
54-
- When the form element is optional and no input is provided for the form element then the issue forms body will contain a `_No response_` but the parsed output for that key in the JSON string will just be an empty value.
54+
- When the form element is optional and no input is provided for the form element then the issue form body will contain a `_No response_` but the parsed output for that key in the JSON string will just be an empty value.
5555
- **For a better understanding of the output rules see example below.**
5656

57-
## Example output for a given issue forms template and body
57+
## Example output for a given issue form template and body
5858

59-
Given the following issue forms template:
59+
Given the following issue form template:
6060

6161
```yml
6262
name: Release NuGet package
@@ -120,7 +120,7 @@ body:
120120
- label: Linux
121121
```
122122

123-
And given the following issue forms body:
123+
And given the following issue form body:
124124

125125
```md
126126
### What NuGet package do you want to release?
@@ -180,7 +180,7 @@ The output would be:
180180

181181
You can check the structure of the action's output on the log produced by the action.
182182

183-
In the log for the action, expand the groups for `dotnet GitHub issue forms parser output` and `dotnet GitHub issue forms parser output indented` as shown in the image below.
183+
In the log for the action, expand the groups for `dotnet GitHub issue form parser output` and `dotnet GitHub issue form parser output indented` as shown in the image below.
184184

185185
![debug-output](docs/readme-images/debug-output.png "Debug output")
186186

action.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
name: 'GitHub issue forms parser'
2-
description: 'Parses a GitHub issue forms body and outputs a JSON representation.'
2+
description: 'Parses a GitHub issue form body and outputs a JSON representation.'
33
branding:
44
icon: align-justify
55
color: blue
66
inputs:
77
template-filepath:
8-
description: 'The filepath for the GitHub issue forms template.'
8+
description: 'The filepath for the GitHub issue form template.'
99
required: true
1010
issue-form-body:
11-
description: 'The issue forms body.'
11+
description: 'The issue form body.'
1212
required: true
1313
outputs:
1414
parsed-issue:
15-
description: 'The parsed issue forms as a JSON string.'
15+
description: 'The parsed issue form as a JSON string.'
1616
runs:
1717
using: 'docker'
1818
image: 'Dockerfile'

docs/dev-notes/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ The steps below show how to run the Docker container action against a set of tes
3232

3333
1) Clone the repo and browse to the repo's directory.
3434
2) Run `docker build -t github-issue-parser .`
35-
3) Read the test issue forms body into the variable `$issueBody` by doing: `$issueBody = Get-Content GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/IssueBody.md -Raw`
35+
3) Read the test issue form body into the variable `$issueBody` by doing: `$issueBody = Get-Content GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/IssueBody.md -Raw`
3636
4) Run the docker container by executing `docker run --rm -v ${pwd}:/workspace --workdir /workspace github-issue-parser GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/Template.yml $issueBody`.
3737

3838
**Notes:**
3939

4040
- The docker container entrypoint expects two arguments:
41-
1) First, the filepath to the issue forms template.
42-
2) Second, the issue forms body.
43-
- When running the docker container the current directory is mounted to the docker container so that we can read the issue forms template.
44-
- When reading the issue forms body into the `$issueBody` variable we have to use the `-Raw` parameter to avoid problems with line endings.
41+
1) First, the filepath to the issue form template.
42+
2) Second, the issue form body.
43+
- When running the docker container the current directory is mounted to the docker container so that we can read the issue form template.
44+
- When reading the issue form body into the `$issueBody` variable we have to use the `-Raw` parameter to avoid problems with line endings.
4545

4646
## Projects wide configuration
4747

@@ -73,7 +73,9 @@ This action is published to the [GitHub marketplace](https://github.com/marketpl
7373

7474
## Note about the Docker container action
7575

76-
This repo provides a [Docker container action](https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action). See here for more information about the [syntax for a Docker container action](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-docker-container-actions). To understand better how the action builds and executes the Docker container look at the log for the steps that build and run the action.
76+
This repo provides a [Docker container action](https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action). If parsing the GitHub issue form fails then the action [will fail](https://docs.github.com/en/enterprise-cloud@latest/actions/creating-actions/setting-exit-codes-for-actions#setting-a-failure-exit-code-in-a-docker-container-action). See here for more information about the [syntax for a Docker container action](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-docker-container-actions).
77+
78+
To understand better how the action builds and executes the Docker container look at the log for the steps that build and run the action.
7779

7880
### As of writing this, the log for building the docker action looks as follows
7981

@@ -130,19 +132,19 @@ This allows the GitHub action to access the files checked out by the workflow an
130132

131133
**Example:**
132134

133-
- Repository `hello-world` has an issue forms template file at `.github\ISSUE_TEMPLATE\my-template.yml`.
135+
- Repository `hello-world` has an issue form template file at `.github\ISSUE_TEMPLATE\my-template.yml`.
134136
- We create a workflow in the `hello-world` repository that checks out the `hello-world` repo and makes use of the `GitHub issue forms parser` action.
135137
- We set the `template-filepath` input parameter of the `GitHub issue forms parser` action to `.github\ISSUE_TEMPLATE\my-template.yml`.
136138
- When the workflow is executing the Docker container is able to get to `.github\ISSUE_TEMPLATE\my-template.yml` because the contents of the checked out `hello-world` repo are mounted into the Docker container at `/github/workspace`. Furthermore the `template-filepath` input parameter doesn't need to start with `/github/workspace` because the `workdir` parameter is set to `/github/workspace` when executing the Docker container.
137139

138140
## Other notes
139141

140-
When creatng the [Test GitHub action workflow](/.github/workflows/test-action.yml) I had difficulty figuring out how to properly read the issue forms body from a file and pass it into the GitHub action as an input parameter.
142+
When creatng the [Test GitHub action workflow](/.github/workflows/test-action.yml) I had difficulty figuring out how to properly read the issue form body from a file and pass it into the GitHub action as an input parameter.
141143

142-
What was happening initially was that the newlines were not being preserved and the action would fail to parse the issue forms body. To help me debug this issue and see exactly what text, including newline characters, were being passed into the action I added the following debug step:
144+
What was happening initially was that the newlines were not being preserved and the action would fail to parse the issue form body. To help me debug this issue and see exactly what text, including newline characters, were being passed into the action I added the following debug step:
143145

144146
```yml
145-
- name: Debug reading issue forms body file using -Raw
147+
- name: Debug reading issue form body file using -Raw
146148
run: |
147149
$issueBody = Get-Content ./GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/IssueBody.md -Raw
148150
$issue = @{

docs/dev-notes/workflows/test-action-workflow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[This workflow](/.github/workflows/test-action.yml):
66

77
- Contains a step that executes the GitHub action provided by this repo.
8-
- Runs the action against a test template and a test issue forms body.
8+
- Runs the action against a test template and a test issue form body.
99
- Checks that the output produced by the action is as expected.
1010

1111
Since this workflow executes the [Docker container action](https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action) it will build and execute the docker container so if there are any issues with the action's [Dockerfile](/Dockerfile) this workflow will detect it.

0 commit comments

Comments
 (0)