Issue Form Interaction

Issue form templates let developers create specific structures for issue openers. You can set different input types, validations, default assignees, and default labels for the issue forms.

In PyAction, you can parse issues created with these forms and use the data they contain.

Read more about GitHub issue forms here.

Creating an Issue Form

Consider an action repository with the following issue form template. It’s located in .github/ISSUE_TEMPLATE/text_summarize.yml.

name: Text Summarization
description: Summarize tens of paragraphs into a smaller amount of sections
title: "AI: Text Summarization"
labels: ["summarization", "ai"]
body:
  - type: textarea
    attributes:
      label: Text
      description: Write or paste your text here
      render: markdown
    validations:
      required: true
  - type: dropdown
    id: sentences
    attributes:
      label: Sentences
      description: Select the amount of sentence(s) you want your text get summarized to
      options:
        - 2
        - 4
        - 6
        - 8
      default: 0
    validations:
      required: true

This template creates an issue form with the following two fields.

  • Text (textarea)

  • Sentences (dropdown)

Issue form

Note that the action should trigger on the issue opening event.

Create the Action

Three major changes need to happen.

1

Add the issue_number input to the action.yml.

inputs:
  ...
  issue_number:
    description: The id of the issue
    required: true
2

Make the action get triggered when an issue opens. Also, send the issue number to the action.

on:
  issues:
    types: [opened]

...

steps:
  - name: Running the action
    uses: you/your-action
    with:
      issue_number: ${{ github.event.issue.number }}
3

Read the issue content in the action function in the main.py.

from pyaction.issues import IssueForm
...

@workflow.action
def my_action(repository: str, issue_number: int, github_token: str) -> None:
    user_input = IssueForm(
        repository=repository, number=issue_number, token=github_token
    ).render()

The user_input is a dictionary that holds the values from the created issue.

{
    "Text": "While many quantum experiments examine very small..",
    "Sentences": "2"
}

Local Running

To test an action that uses issue forms, the following input parameters need to be included in the .env file before running pyaction run.

INPUT_REPOSITORY=
INPUT_ISSUE_NUMBER=
INPUT_GITHUB_TOKEN=
...
  • INPUT_REPOSITORY: The repository from which the action will retrieve the issue. Its value should be in the format username/repo.

  • INPUT_ISSUE_NUMBER: The issue id.

  • INPUT_GITHUB_TOKEN: A GitHub personal access token that has read access to the repository's issue.

Read more about GitHub personal access tokens here.

Updated on