Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
onmax committed Jan 22, 2023
1 parent 4296c1a commit d2a49de
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 71 deletions.
129 changes: 58 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,105 +1,92 @@
<p align="center">
<a href="/~https://github.com/actions/typescript-action/actions"><img alt="typescript-action status" src="/~https://github.com/actions/typescript-action/workflows/build-test/badge.svg"></a>
<a href="/~https://github.com/onmax/issue-form-parser/actions"><img alt="issue-form-parser status" src="/~https://github.com/onmax/issue-form-parser/actions/workflows/test.yml/badge.svg"></a>
</p>

# Create a JavaScript Action using TypeScript
# Issue Form Parser - GitHub Action

Use this template to bootstrap the creation of a TypeScript action.:rocket:
Convert GitHub Form Issues into JSON objects with this simple Action.

This template includes compilation support, tests, a validation workflow, publishing, and versioning guidance.
![Issue Form Parser](./issue-form-parser.png)

If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](/~https://github.com/actions/hello-world-javascript-action)
---

## Create an action from this template
## Description

Click the `Use this Template` and provide the new repo details for your action
This GitHub Action allows you to easily convert GitHub issues into JSON objects, making it simple to work with and manipulate issue data in your workflow. With just a few simple steps, you can use this action to automatically convert an issue into a JSON object, which can then be used for a variety of purposes, such as data analysis, reporting, or integration with other systems. This action is designed to be flexible and easy to use, so you can quickly and easily convert issues into JSON format without any hassle.

## Code in Main
## Parameters

> First, you'll need to have a reasonably modern version of `node` handy. This won't work with versions older than 9, for instance.
<!-- table with input name, required, description -->

Install the dependencies
```bash
$ npm install
```
| Name | Required | Description |
| ------------- | ------------- | ------------- |
| `issue_number` | `true` | The issue number to parse. |
| `github_token` | `false` | The GitHub token to use for authentication and fetching the issue. Defaults to the `GITHUB_TOKEN` secret. |

Build the typescript and package it for distribution
```bash
$ npm run build && npm run package
```
## Usage

Run the tests :heavy_check_mark:
```bash
$ npm test
First, you need to create a GitHub Issue Form. You can read more about it [here](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms).

PASS ./index.test.js
✓ throws invalid number (3ms)
wait 500 ms (504ms)
test runs (95ms)
Then, you need to create a workflow file and include the following step:

...
```yaml
steps:
- name: Parse issue
id: parse
uses: onmax/issue-form-parser@v1.0.0
with:
issue_number: ${{ github.event.issue.number }}

# Examples on how to use the output
- name: Show parsed payload
run: |
echo "${{ toJson(steps.parse.outputs.payload) }}"
- name: Show 'Name' field
run: |
echo "${{ steps.parse.outputs.payload['Name'] }}"
```
## Change action.yml
## ⚠️ Limitations
The action.yml defines the inputs and output for your action.
- The action only works with issues, not pull requests.
- **The `issue_number` input is required.** If the event that trigger the workflow is not an issue, you need to specify the issue number manually.
- **The returned `payload` is a string.** You need to use `toJson` to convert it to a JSON object. Read more about [GitHub Actions expressions](https://docs.github.com/en/actions/learn-github-actions/expressions#tojson).
- Checkboxes are not supported. If you need to use checkboxes, you can create a PR or use the [`peter-murray/issue-forms-body-parser@v3.0.0`](/~https://github.com/peter-murray/issue-forms-body-parser)

Update the action.yml with your name, description, inputs and outputs for your action.
## Example

See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
This issue:

## Change the Code
```md
### Country
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
Spain
```javascript
import * as core from '@actions/core';
...
### Age
async function run() {
try {
...
}
catch (error) {
core.setFailed(error.message);
}
}
The age of the candidate is 17 years old
run()
```

See the [toolkit documentation](/~https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
### Languages
## Publish to a distribution branch
Python, TypeScript, and others...
Actions are run from GitHub repos so we will checkin the packed dist folder.
### How many years of experience do you have?
Then run [ncc](/~https://github.com/zeit/ncc) and push the results:
```bash
$ npm run package
$ git add dist
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1
I have 2 years of experience
```

Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.

Your action is now published! :rocket:
Will be converted to:

See the [versioning documentation](/~https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)

## Validate

You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml))

```yaml
uses: ./
with:
milliseconds: 1000
```json
{
"Country": "Spain",
"Age": "The age of the candidate is 17 years old",
"Languages": "Python, TypeScript, and others...",
"How many years of experience do you have?": "I have 2 years of experience"
}
```

See the [actions tab](/~https://github.com/actions/typescript-action/actions) for runs of this action! :rocket:
## Usage:
## Acknowledgements

After testing you can [create a v1 tag](/~https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action
- Based on the previous work of [Peter Murray](/~https://github.com/peter-murray/issue-forms-body-parser)
- This template was created using the [TypeScript Action Template](/~https://github.com/actions/typescript-action)
Binary file added issue-form-parser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d2a49de

Please sign in to comment.