Lab: Event - GitHub Discussions
Introduction
In this lab, you will create a GitHub Actions workflow that is triggered whenever a new GitHub Discussion is created, edited, or deleted in your repository. This lab will help you understand how to use the discussion event and interact with its payload using github.event.
Estimated Duration: 20–30 minutes
Instructions
Step 1: Enable Discussions in Your Repository
- Navigate to your GitHub repository.
- Click the Settings tab.
- In the left sidebar, select General.
- Scroll to the Features section.
- Ensure the Discussions checkbox is checked.
If the option is not available, make sure you have admin access to the repository.
Step 2: Create the Workflow File
- Navigate to the Code tab of your repository.
-
In the file explorer, create the following folder structure if it doesn’t exist:
.github/workflows/
- Inside the
workflowsfolder, create a file named:.github/workflows/discussion-event-workflow.yml - Paste the following workflow content into the editor:
name: Handle GitHub Discussion Events
on:
discussion:
types:
[
created,
edited,
deleted,
pinned,
unpinned,
locked,
unlocked,
transferred,
category_changed,
answered,
unanswered,
]
jobs:
handle-discussion:
runs-on: ubuntu-latest
steps:
- name: Print full event payload
run: |
echo "Full event payload:"
echo "$"
- name: Print discussion metadata
run: |
echo "🗣️ Event Type: $"
echo "📌 Title: $"
echo "✍️ Author: $"
echo "📝 Category: $"
echo "💬 Body: $"
- name: On Create
if: github.event.action == 'created'
run: echo "🎉 A new discussion was created!"
- name: On Edit
if: github.event.action == 'edited'
run: echo "✏️ A discussion was edited!"
- name: On Delete
if: github.event.action == 'deleted'
run: echo "🗑️ A discussion was deleted!"
- Scroll down and click Commit new file.
Step 3: Trigger the Workflow
- Go to the Discussions tab of your repository.
- Click New discussion.
- Choose a category (e.g., General).
- Enter a title and body.
- Click Start discussion to trigger the
createdevent.
You can also:
- Edit the discussion (click the
...menu > Edit). - Delete the discussion (click the
...menu > Delete) to trigger other events.
Step 4: View the Workflow Execution
- Navigate to the Actions tab of your repository.
- Select the run with the name Handle GitHub Discussion Events.
- Click the handle-discussion job.
-
Expand the steps to view:
- Event type and discussion details
- Conditional messages depending on the event
Supported types for the discussion Event
GitHub Actions supports the following activity types for the discussion event:
| Type | Description |
|---|---|
created |
When a new discussion is created |
edited |
When the title or body is edited |
deleted |
When a discussion is deleted |
pinned |
When a discussion is pinned |
unpinned |
When a discussion is unpinned |
locked |
When a discussion is locked |
unlocked |
When a discussion is unlocked |
transferred |
When a discussion is moved between repos |
category_changed |
When the category of the discussion changes |
answered |
When a comment is marked as the answer |
unanswered |
When the answer status is removed |
💡 Note: Adding or removing a label to a discussion does not trigger the
discussionevent.
Summary
In this lab, you learned how to:
- Enable Discussions in a GitHub repository
- Create a GitHub Actions workflow triggered by the
discussionevent - Inspect the event payload using
github.event - Use
if:conditionals to branch logic depending on the discussion action
This lays the foundation for building more advanced automation workflows around GitHub Discussions (e.g., moderation, analytics, notifications).