@zentered/issue-forms-body-parser

2.2.0 • Public • Published

GitHub Issue Forms Body Parser

Test Release Conventional Commits zentered.co

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

  • ✅ npm version available npm i @zentered/issue-forms-body-parser
  • ✅ parse question/answer format into title/text as JSON
  • ✅ parse line items and "tasks" with separate checked attributes
  • ✅ slugify title to id to find data
  • ✅ parse dates and times into separate date and time fields
  • ❎ no tokens/input required
  • ❎ 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 formatted date field (in UTC).
  • time: checks if the value matches a common time format and returns a formatted time field.
  • lists: automatically returns lists as arrays
  • duration: currently only the format XXhYYm is supported as duration, ie. 1h30m returns a duration object with hours and minutes.

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/issue-forms-body-parser@v2.0.0
      - 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/issue-forms-body-parser@v2.0.0
        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.

License

Licensed under MIT.

Here is a list of all the licenses of our production dependencies

Package Sidebar

Install

npm i @zentered/issue-forms-body-parser

Homepage

zentered.co/

Weekly Downloads

125

Version

2.2.0

License

MIT

Unpacked Size

86.8 kB

Total Files

35

Last publish

Collaborators

  • patrickheneise