2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

マイルストーンを自動生成

Last updated at Posted at 2021-01-22

概要

定期的にリリースするサービス向けにマイルストーンでPRをまとめている。
GithubのマイルストーンをGithub Actionsの定期実行で自動生成する処理の備忘。

スクリプト

milestone.yml
name: Create Milestone

on:
  schedule:
    - cron: "0 17 * * *"

jobs:
  create-milestone:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/github-script@v3
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            // https://octokit.github.io/rest.js/v18#issues-list-milestones
            const milestones = await github.issues.listMilestones({
              owner: context.repo.owner,
              repo: context.repo.repo,
              sort: "due_on",
              direction: "desc",
              state: "open",
            })
            // サービスのルールに依存: マイルストーンのタイトルが日付のもので最新のものを取得してくる
            const milestone = milestones.data.find(({ title }) => title.match(/^\d{4}-\d{2}-\d{2}$/)) || null
            if (!milestone) {
              console.log("マイルストーンが取得できませんでした")
              return
            }
            const date = new Date(milestone.due_on)
            // サービスのルールに依存: 最新のマイルストーンのリリース日の4日前に次sprintのマイルストーンを作成
            const baseDate = new Date()
            baseDate.setDate(baseDate.getDate() + 4)
            if (date.getTime() > baseDate.getTime()) {
              return
            }
            date.setDate(date.getDate() + 14)
            date.setHours(9)
            const dueOn = date.toISOString()
            const month = ("00" + (date.getMonth() + 1)).slice(-2)
            const day = ("00" + date.getDate()).slice(-2)
            const releaseDate = date.getFullYear() + "-" + month + "-" + day
            // https://octokit.github.io/rest.js/v18#issues-create-milestone
            github.issues.createMilestone({
              owner: context.repo.owner,
              repo: context.repo.repo,
              title: releaseDate,
              due_on: dueOn,
              description: "定期リリース"
            })

補足

PRにマイルストーンを自動アサインする方法
https://qiita.com/stnamco/items/06d2147c93a1cca97371

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?