GitHub Actions Workshop

Master GitHub Actions with hands-on labs and exercises. Learn how to automate workflows, run tests, deploy applications, and more using GitHub's powerful automation platform. This repository has everything you need to get started with continuous integration and continuous deployment.


Project maintained by prasadhonrao Hosted on GitHub Pages — Theme by mattgraham

Solution: Automatically Comment and Label Issues

name: Misc - Auto Comment on New Issues

on:
  issues:
    types: opened
  workflow_dispatch:

jobs:
  thanks:
    runs-on: ubuntu-latest
    permissions:
      issues: write # required to create comments
    steps:
      - uses: actions/github-script@v7
        id: issue_script
        with:
          github-token: $
          script: |
            const issue_number = context.issue.number;
            console.log(`issue_number: ${issue_number}`);

            const owner = context.repo.owner;
            const repo = context.repo.repo;

            // lookup issue info
            const issue = await github.rest.issues.get({
              repo, owner, issue_number
            });
            console.log(`issue: ${issue}`);

            // create comment thanking contributor
            const comment = await github.rest.issues.createComment({
              repo, owner, issue_number,
              body: "Thanks for your contribution!"
            });
            console.log(`comment id: ${comment.data.id}`);
            console.log(comment.data);

            // auto label
            github.rest.issues.addLabels({
              repo, owner, issue_number,
              labels: ['todo-review']
            })

            // make comment id available to subsequent steps
            return comment.data.id;

      - run: echo 'comment id=$'