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.

PRにマイルストーンを自動設定

Last updated at Posted at 2021-01-22

概要

定期的にリリースするサービス向けにマイルストーンでPRをまとめている。
GithubのマイルストーンをGithub Actionsを利用して自動設定する方法の備忘。

スクリプト

prreview.yml
name: PullRequest assign the latest milestone automatically

on:
  pull_request:
    branches:
      - develop
      - 'feature/**'
    types: [opened, ready_for_review]

jobs:
  add-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
            }
            // PRのnumberを取得
            const prNumber = context.payload.pull_request.number
            const result = await github.issues.update({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: prNumber,
              milestone: milestone.number,
            })
            console.log(result.status)

補足

マイルストーンの自動生成は下記を見る
https://qiita.com/stnamco/items/6778adcaa47569409825

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?