iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
👋

Automatically generate GitHub issues from templates with GitHub Actions

に公開
2024/04/04

Introduction

I usually create an issue every day in a private GitHub repository and write things like daily reports and TODO lists there.

Since the overall structure of the issues is always the same, I created a GitHub ISSUE_TEMPLATE and have been manually creating an issue using this template every day until now.

The specific steps for "manually creating an issue from a template" were as follows:

  1. Go to the GitHub issue page
  2. Select "New Issue"
  3. Select "Get started" for the target template
  4. Enter the date in the title
  5. Select "Submit new issue"

Well, it's a task that takes about a minute to complete, but since it feels like a waste of time to spend a minute on the same task every day, I automated it using GitHub Actions. In this article, I will introduce how to do it.

Method

In conclusion, I was able to achieve this easily by using JasonEtco/create-an-issue.

The usage is described in the README, so looking at that might be enough, but I will introduce how to use JasonEtco/create-an-issue for this specific use case.

Creating the Template

Create a markdown file like the following in .github/ISSUE_TEMPLATE/daily_report.md.


---
name: Daily Report
about: Template for daily reports
title: "{{ date | date('YYYY/MM/DD') }}"

---

## TODO

- [ ] hoge

## Reflection

Creating the GitHub Actions Workflow

Create a file like the following in .github/workflows/create_daily_report.yml.

name: Create Daily Report

on:
  workflow_dispatch:

permissions:
  contents: read
  issues: write 

jobs:
  create_issue:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: JasonEtco/create-an-issue@v2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          filename: .github/ISSUE_TEMPLATE/daily_report.md

That's it for the preparation.

How to Run

When you select "Run workflow" for "Create Daily Report" from the GitHub Actions tab, the workflow will be executed, and an issue like the one below will be automatically generated.

image

Additional Notes

If you want to run it periodically, you can achieve this by setting a schedule.

# To run every day at 6:00 AM JST
on:
  schedule:
    - cron:  '0 21 * * *'

Also, it seems you can reference environment variables and variables listed in toolscontext within the template.

# Reference environment variables
{{ env.GITHUB_ACTOR }}

# Reference toolscontext
{{ repo.owner }}
GitHubで編集を提案

Discussion