@zentered/issue-forms-body-parser
v2.2.0
Published
Parser for GitHub Issue Form body, also available as GitHub Action
Downloads
295
Maintainers
Readme
GitHub Issue Forms Body Parser
Issue Forms is a great way to structure GitHub Issues to an expected format, and to make it easier to capture information from the user. Unfortunately, the schema only defined the input of the data, not the output. So the markdown body needs to be parsed to extract the information in a structured way and to make further processing easier.
We use this Action at the
Cyprus Developer Community to
create issues with event data
for upcoming meetups etc. The parser extracts the information from the issues
and provides structured data to create calendar entries (ie .ics
files for
calendar subscriptions with GitEvents),
calling 3rd party APIs, etc.
Inspired by: Peter Murray's Issue Forms Body Parser with valuable feedback from Steffen
Features
- :white_check_mark: npm version available
npm i @zentered/issue-forms-body-parser
- :white_check_mark: parse question/answer format into title/text as JSON
- :white_check_mark: parse line items and "tasks" with separate
checked
attributes - :white_check_mark: slugify title to id to find data
- :white_check_mark: parse dates and times into separate
date
andtime
fields - :negative_squared_cross_mark: no tokens/input required
- :negative_squared_cross_mark: zero configuration
Transforms markdown from GitHub Issue Forms:
### Event Description
Let's meet for coffee and chat about tech, coding, Cyprus and the newly formed
CDC (Cyprus Developer Community).
### Location
Cafe Nero Finikoudes, Larnaka
### Date
11.03.2022
### Time
16:00
to structured, usable data:
{
"event-description": {
"order": 0,
"title": "Event Description",
"text": "Let's meet for coffee and chat about tech, coding, Cyprus and the newly formed\nCDC (Cyprus Developer Community)."
},
"location": {
"order": 1,
"title": "Location",
"text": "Cafe Nero Finikoudes, Larnaka"
},
"date": {
"order": 2,
"title": "Date",
"text": "11.03.2022",
"date": "2022-03-11"
},
"time": {
"order": 3,
"title": "Time",
"text": "16:00",
"time": "16:00"
}
}
See more examples in md test cases and test results.
Parsers
date
: checks if the value matches a common date format and returns a formatteddate
field (in UTC).time
: checks if the value matches a common time format and returns a formattedtime
field.lists
: automatically returns lists as arraysduration
: currently only the formatXXhYYm
is supported as duration, ie.1h30m
returns aduration
object withhours
andminutes
.
Installation & Usage
GitHub Actions
name: Issue Forms Body Parser
on: issues
jobs:
process:
runs-on: ubuntu-latest
steps:
- name: Issue Forms Body Parser
id: parse
uses: zentered/[email protected]
- run: echo ${{ toJSON(steps.parse.outputs.data) }}
You can also provide a custom body
input:
name: Issue Forms Body Parser
on:
workflow_dispatch:
inputs:
issue_number:
type: string
required: true
env:
GH_TOKEN: ${{ github.token }}
jobs:
process:
runs-on: ubuntu-latest
steps:
- name: Fetch the issue
id: read_issue_body
run:
echo "body=$(gh issue view ${{ inputs.issue_number }} --repo ${{
github.repo }} --json body --jq '.body')" >> $GITHUB_OUTPUT
- name: Issue Forms Body Parser
id: parse
uses: zentered/[email protected]
with:
body: ${{ steps.read_issue_body.output.body }}
- run: echo ${{ toJSON(steps.parse.outputs.data) }}
NPM
The parser is available as a standalone library:
npm i @zentered/issue-forms-body-parser
# OR yarn add @zentered/issue-forms-body-parser
Usage:
import bodyParser from '@zentered/issue-forms-body-parser'
const issueData = await bodyParser(issue.body)
Development & Testing
You can use act to test this Action locally.
npm run build && act issues -e test/issue.json
or run:
npm test
to test the parser.
Links
License
Licensed under MIT.
Here is a list of all the licenses of our production dependencies