Create a new GitHub Discussion with GitHub Actions
This action allows you to create a new GitHub Discussion with GitHub Actions.
In your workflow, to create a new discussion, include a step like this:
- name: Create a new GitHub Discussion
id: create-discussion
uses: abirismyname/create-discussion@main
with:
title: Feelings
body: |
Let's talk!
category-name: Your Category #optional, defaults to "General"
repository-name: owner/repo #optional, defaults to the current repository
github-token: ${{ secrets.GITHUB_TOKEN }}
If you know the repository-id
and category-id
, you can use them directly to create a discussion, which will speed things up slightly:
- name: Create a new GitHub Discussion
id: create-discussion
uses: abirismyname/create-discussion@main
with:
title: Feelings
body: |
Let's talk!
repository-id: R_asdf1234
category-id: DIC_asdf1234
github-token: ${{ secrets.GITHUB_TOKEN }}
The Action returns the discussion-id
and discussion-url
as outputs, which you can use in subsequent steps. For example, to print the discussion URL and ID:
- name: Create a new GitHub Discussion
id: create-discussion
uses: abirismyname/create-discussion@main
with:
title: Feelings
body: |
Let's talk!
repository-id: R_asdf1234
category-id: DAC_asdf1234
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Print discussion url and id
run: |
echo discussion-id: ${{steps.create-discussion.outputs.discussion-id}}
echo discussion-url: ${{steps.create-discussion.outputs.discussion-url}}
The Action accepts the following inputs:
title
: The title of the discussion (Required)body
: The body of the discussion (Required, ifbody-filepath
is not provided)body-filepath
: The path to a file containing the body of the new discussion (Required, ifbody
is not provided. Takes precedence overbody
).repository-id
: The ID of the repository for the new discussioncategory-id
: The ID of the category for the new discussion.repository-name
: The name of the repository (owner/repo) for the new discussion (Optional, defaults to the current repository)category-name
: The name of the category for the new discussion (Optional, defaults to "General" if the category-id is not provided)github-token
: The GitHub token to use for authentication (Required, unlessGH_TOKEN
is passed as anenv
variable).
Note: If you are using body-filepath
be sure to add a actions/checkout
action before this action in the workflow to make sure the file exists in the action workspace.
You can find repository-id
and category-id
using GitHub's GraphQL Explorer. Replace <REPO_NAME>
and <REPO_OWNER>
with the repo you want to update.
query MyQuery {
repository(name: "<REPO_NAME>", owner: "<REPO_OWNER>") {
id
discussionCategories(first: 10) {
edges {
node {
id
name
}
cursor
}
}
}
}
This action provides the following outputs:
discussion-id
: ID of created discussiondiscussion-url
: URL of created discussion
This repo contains an example workflow that contains this action.
- 🙇 Based on swinton/commit.
- 🙇 @imjohnbo for the inspiration.
- 🙇 @benbalter for modernizing and adding much needed new features