> Markdown version of [/magazine/593-github-actions-auto-comment-on-new-issues](https://www.wearedevelopers.com/magazine/593-github-actions-auto-comment-on-new-issues). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # GitHub Actions: Auto-Comment on New Issues **By:** [Daniel Cranney](https://www.wearedevelopers.com/@daniel-cranney) **Published:** June 5, 2025 GitHub Actions let you automate tasks within your repository. While many developers use them for continuous integration or deployment, they can be used to automate all kinds of tasks and supercharge your repository. In this tutorial, we’ll set up a simple automation that posts a comment whenever someone opens a new issue. It’s an ideal starting point for learning GitHub Actions, and it can help guide users, reinforce contribution standards, or just save you time by automating away repetitive or monotonous tasks. * * * ## What We’re Building This action will listen for new issues being opened in your repository. When that happens, it will run a short JavaScript script that posts a predefined comment in response. There’s no need to install dependencies or build tools. The entire workflow is handled by GitHub’s infrastructure, using just **one workflow file** and **one script block**. GitHub actions can be a lot of work to fun work with, so let’s get started. * * * ## The Workflow File To create the automation, create a `.github` folder, and another `workflow` folder within it. Then, in your new `workflows` folder, create a file called `auto-comment.yml` (the path should now be `.github/workflows/auto-comment.yml`) and include the following: name: Auto Comment on Issues on: issues: types: [opened] jobs: comment: runs-on: ubuntu-latest permissions: issues: write steps: - name: Comment on new issue uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const issueNumber = context.issue.number; const username = context.payload.issue.user.login; const comment = [ `👋 Hey @${username} — thanks for opening an issue!`, ``, `Before we dive in, make sure to check out our [contributing guide](CONTRIBUTING.md) and see if this has already been reported.`, ``, `We appreciate your help! 💖` ].join('\n'); await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issueNumber, body: comment }); Walking through the script, here’s how it works: ### Setup 1. **Name:** The workflow is called “Auto Comment on Issues”. 2. **Trigger:** It runs automatically when a new issue is opened. 3. **Environment:** Executes on the latest Ubuntu runner provided by GitHub. 4. **Permissions:** Grants permission to write comments on issues. ### Main Job: 1. Uses the built-in actions/github-script to run JavaScript directly in the workflow. 2. Retrieves the issue number and the username of the person who opened it (dynamically). 3. Constructs a custom thank-you comment including a link to the contributing guide. 4. Posts the comment to the issue using the built-in GitHub REST API. ## Formatting At this point, it’s worth saying that GitHub actions can be quite fussy when it comes to formatting, and if you see one when you first add your workflow file, it’s likely an issue with identations, so start there. ## Testing Your Action Now we’ll make sure your action is working correctly by creating a test issue (don’t worry, we can delete it later). Then, head to the **‘Actions’** tab on the GitHub repository page and you’ll see logs for each time your workflow runs, making it easier to debug any issues that could popup. ![GitHub Actions Workflow Logs](https://wearedevelopers.imgix.net//magazine/articles/593/images/content/blvn0aSYGrCKzX4IckE9-1749031394.png?w=984&auto=compress,format) Finally, head back to the **Issues** tab and you should see a nicely formatted comment waiting for you! Success! 🎊 ![GitHub Actions Auto-Comment](https://wearedevelopers.imgix.net//magazine/articles/593/images/content/S4gM2amUgRXPfq3H1NjQ-1749031394.png?w=984&auto=compress,format) ## Summary So now you know how to setup a GitHub action to automate parts of your developer workflow! If you wanted to take this tutorial a step further, we recommend experimenting with features like: - Auto-labelling PRs based on file paths - Close stale PRs after X days of inactivity - Check for secrets like API keys in commits We’d love to see what you make, so be sure to [share it with us on Bluesky](https://bsky.app/profile/wearedevelopers.bsky.social)! ## Related Articles - [Liuba Gonta and Yuliya Khadasevic - GitHub Copilot Beyond the Basics - 10 Ways to Elevate Your Coding](https://www.wearedevelopers.com/magazine/490-liuba-gonta-and-yuliya-khadasevic-github-copilot-beyond-the-basics-10-ways-to-elevate-your-coding) - [GitHub’s Hidden Keyboard Shortcuts to Boost Your Productivity](https://www.wearedevelopers.com/magazine/651-github-s-hidden-keyboard-shortcuts-to-boost-your-productivity) - [GitHub Copilot: Beyond the Basics – 10 Ways to Elevate Your Coding](https://www.wearedevelopers.com/magazine/524-github-copilot-beyond-the-basics-10-ways-to-elevate-your-coding) - [5 GitHub Repos That Help You Ship and Show Your Work](https://www.wearedevelopers.com/magazine/694-5-github-repos-that-help-you-ship-and-show-your-work) ## Related Videos - [CI/CD with Github Actions](https://www.wearedevelopers.com/videos/856-ci-cd-with-github-actions) - [The End of Commit-Fail-Commit: Rethinking CI with AI Agents and GitHub Actions](https://www.wearedevelopers.com/videos/100306-the-end-of-commit-fail-commit-rethinking-ci-with-ai-agents-and-github-actions) - [Build a CI/CD pipeline to automate code reviews and ensure code quality](https://www.wearedevelopers.com/videos/349-build-a-ci-cd-pipeline-to-automate-code-reviews-and-ensure-code-quality) - [GitHub Copilot Beyond the Basics - 10 Ways to Elevate Your Coding](https://www.wearedevelopers.com/videos/1011-github-copilot-beyond-the-basics-10-ways-to-elevate-your-coding) ## Related Jobs - [Senior Software Engineer](https://www.wearedevelopers.com/jobs/ext/15942-senior-software-engineer) at **GitHub** - [Staff Software Engineer, Copilot Experiences](https://www.wearedevelopers.com/jobs/ext/164361-staff-software-engineer-copilot-experiences) at **GitHub** - [Staff Developer Advocate, GitHub Security Lab](https://www.wearedevelopers.com/jobs/ext/1921051-staff-developer-advocate-github-security-lab) at **GitHub** - [Principal Product Manager, Agent Platform](https://www.wearedevelopers.com/jobs/ext/277541-principal-product-manager-agent-platform) at **GitHub** - [Staff Software Engineer, Database Infrastructure](https://www.wearedevelopers.com/jobs/ext/1470125-staff-software-engineer-database-infrastructure) at **GitHub** - [Senior Software Engineer](https://www.wearedevelopers.com/jobs/ext/159190-senior-software-engineer) at **GitHub**